tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: [PATCH] Fix printf(1) for integer larger than INTMAX_MAX
On 2020/10/26 3:14, Robert Elz wrote:
Date: Sun, 25 Oct 2020 19:01:18 +0900
From: Rin Okuyama <rokuyama.rk%gmail.com@localhost>
Message-ID: <09f349b6-f483-e582-d5b4-71f6b747db56%gmail.com@localhost>
| I forgot to mention in the previous message: %[oux] also fail for numbers
| larger than 1<<63:
Yes, so they do - that's a (relatively) recent regression (which
probably means I caused it) and should certainly be fixed.
| This is because we convert unsigned integers by strtoimax(3). So, I've
| updated the patch:
|
| http://www.netbsd.org/~rin/printf_20201025.patch
Apart from the change to getwidth() (from ulong to uintmax_t) which isn't
really needed, this is for handling field width values, and we arbitrarily
silently truncate those (to a megabyte) already - an unsigned long can
easily cope with any value we're actually going to use, the rest of that
looks fine to me.
Ah, I didn't know ulong is intentionally. Thanks, I withdraw this part.
There are probably (ugly) ways to deal with the commented out tests (because
we have no simple way to know what range of values printf supports, so can't
tell at what point errors, and value truncation, will start happening). For
the purposes of ATF tests (rather than generic sh programming) there are
probably a sequence of operations that can be performed, where the results
are not used for pass/fail of the test, but for deciding what later tests to
run, perhaps using something like the method used in the sh arithmetic test
which has the same needs (but which has the advantage of being able to use
arithmetic to assist finding the range of values it supports). That is,
the details would vary, but the general method should be able to be made to
work.
Hmm, it seems like tautology if printf(1) itself is used for this test.
How about this autoconf like method?
----
cat > test.c << EOF
#include <sys/types.h>
int main(void) { __CTASSERT(sizeof(intmax_t) == 8); return 0; }
EOF
if cc -c test.c 2> /dev/null; then
echo "64 bit"
else
echo "probably 128 bit or larger"
fi
rm -f test.o
----
This is straightforward, but, yes, ugly too ;).
Thanks,
rin
Home |
Main Index |
Thread Index |
Old Index