From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.5) Gecko/20011013
Description of problem:
The following program does not work:
unsigned long us;
sscanf("0xF0F0F0F0", "%lu", &us);
if (us != 0xf0f0f0f0)
printf("fail unsigned: expect 0xf0f0f0f0 got 0x%lx\n", us);
sscanf("0xF0F0F0F0", "%li", &s);
if (s != 0xf0f0f0f0)
printf("fail signed: expect 0xf0f0f0f0 got 0x%lx\n", s);
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Compile the sample code and run it.
Actual Results: The output from the sample code is:
fail unsigned: expect 0xf0f0f0f0 got 0x0
fail signed: expect 0xf0f0f0f0 got 0x7fffffff
Expected Results: The conversion should have worked.
I am using glibc-2.2.4-19.3
glibc is right, please reread info libc on formated input.
%u conversion matches unsigned integer in DECIMAL radix (so it matches 0 but
not the rest) - this is strtoul (, , 10) does.
%i conversion matches optionally signed integer in decimal/octal/hex radix,
is what strtol (, , 0) does. But in this second case the problem is that you're
trying to put an value which doesn't fit into 32-bit signed integer
(errno is set to ERANGE after second sscanf).