Bug 58249 - sscanf() does not convert correctly.
sscanf() does not convert correctly.
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
7.1
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-01-11 17:51 EST by Jules Colding
Modified: 2007-04-18 12:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-01-11 17:51:24 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jules Colding 2002-01-11 17:51:19 EST
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:

#include <stdio.h>

main ()
{
	long s;
	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):


How reproducible:
Always

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.

Additional info:

I am using glibc-2.2.4-19.3
Comment 1 Jakub Jelinek 2002-01-14 06:48:32 EST
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).

Note You need to log in before you can comment on or make changes to this bug.