This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: ["Vadim Zhukovsky" <zva@ukrpost.net>] scanf bug
- To: libc-alpha at sources dot redhat dot com
- Subject: Re: ["Vadim Zhukovsky" <zva@ukrpost.net>] scanf bug
- From: Ulrich Drepper <drepper at redhat dot com>
- Date: 17 Jul 2001 12:42:47 -0700
- Cc: "Vadim Zhukovsky" <zva at ukrpost dot net>
- References: <hog0bvsk8t.fsf@gee.suse.de>
- Reply-To: drepper at cygnus dot com (Ulrich Drepper)
Andreas Jaeger <aj@suse.de> writes:
> #include <stdio.h>
> #include <stdlib.h>
>
> const char *oct_long_long = "01000000000000000000000";
>
> void main()
> {
> long long ll1, ll2;
> sscanf(oct_long_long, "%Lo", &ll1);
> sscanf(oct_long_long, "%Li", &ll2);
> printf("%%Lo: %Ld, %%Li: %Ld\n", ll1, ll2);
> }
> ----------------------------------------------------------------
> %Lo: -9223372036854775808, %Li: 9223372036854775807
This is the correct result. The octal number is 8000000000000000 is
hex. I.e., bit 63 is set. I.e., this number is not positive. Which
in turn means that strtoll() detects an overflow since it's positive
number > LONG_LONG_MAX. This means strtoll() returns LONG_LONG_MAX
and sets errno.
%o is an unsigned format and uses strtoull() which does not have this
problem.
I know that other implementations don't produce this result but they
are wrong, not glibc.
--
---------------. ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Red Hat `--' drepper at redhat.com `------------------------