* sscanf(3) return value doesn't count %100c assignments
@ 2013-11-15 20:23 David Wuertele
2013-11-15 20:47 ` Rich Felker
0 siblings, 1 reply; 3+ messages in thread
From: David Wuertele @ 2013-11-15 20:23 UTC (permalink / raw)
To: musl
Comparing musl-0.9.14 with glibc-2.13, I find sscanf(3) behaves
differently. In Glibc, sscanf() returns the same assignment counts when
using %Nc compared with using %s, but in Mulsl, sscanf returns different
assignment counts.
For example, take the following two instructions:
sscanf (string, "%d %s", &number, remainder);
sscanf (string, "%d %100c", &number, remainder);
If each of these makes two assignments, they should both return 2.
Glibc works this way. But even though with Musl they both make two
assignments, Musl sscanf() returns 2 for the %s and it returns 1 for
the %100c version.
Here is a test program:
#include <stdio.h>
#include <strings.h>
int main ()
{
int number = 0;
char *string = "1234 five six seven";
char remainder[100];
bzero (remainder, sizeof(remainder));
int args = sscanf (string, "%d %s", &number, remainder);
fprintf (stderr,
"format=%%s string=\"%s\" args=%d number=%d remainder=%s\n",
string, args, number, remainder);
args = sscanf (string, "%d %100c", &number, remainder);
fprintf (stderr,
"format=%%100c string=\"%s\" args=%d number=%d remainder=%s\n",
string, args, number, remainder);
return 0;
}
Here is how I compile them:
arm-tegra452-linux-gnueabi-gcc --static test.c -o test-glibc
arm-linux-musleabishf-gcc -static test.c -o test-musl
Here is what I see when I execute them:
# ./test-musl
format=%s string="1234 five six" args=2 number=1234 remainder=five
format=%100c string="1234 five six" args=1 number=1234 remainder=five six
# ./test-glibc
format=%s string="1234 five six" args=2 number=1234 remainder=five
format=%100c string="1234 five six" args=2 number=1234 remainder=five six
This seems like a bug to me. I tried to read through
musl-0.9.14/src/stdio/vfscanf.c to troubleshoot this, but I couldn't find the
source of the difference. Can anyone give me pointers to build a musl-libc
that has a sscanf() that is compatible with glibc's sscanf()?
Thanks,
Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: sscanf(3) return value doesn't count %100c assignments
2013-11-15 20:23 sscanf(3) return value doesn't count %100c assignments David Wuertele
@ 2013-11-15 20:47 ` Rich Felker
2013-11-15 21:17 ` David Wuertele
0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2013-11-15 20:47 UTC (permalink / raw)
To: musl
On Fri, Nov 15, 2013 at 08:23:42PM +0000, David Wuertele wrote:
> Comparing musl-0.9.14 with glibc-2.13, I find sscanf(3) behaves
> differently. In Glibc, sscanf() returns the same assignment counts when
> using %Nc compared with using %s, but in Mulsl, sscanf returns different
> assignment counts.
>
> For example, take the following two instructions:
>
> sscanf (string, "%d %s", &number, remainder);
> sscanf (string, "%d %100c", &number, remainder);
>
> If each of these makes two assignments, they should both return 2.
> Glibc works this way. But even though with Musl they both make two
> assignments, Musl sscanf() returns 2 for the %s and it returns 1 for
> the %100c version.
musl's sscanf returns 1 because only the %d was matched. %100c
requires _exactly_ 100 characters; anything shorter is a matching
failure. See C99 7.19.6.2 The fscanf function, paragraph 12:
12 The conversion specifiers and their meanings are:
....
c
Matches a sequence of characters of exactly the number specified
by the field width (1 if no field width is present in the
directive).
What you're seeing is a known bug in glibc:
https://sourceware.org/bugzilla/show_bug.cgi?id=12701
It's an old WONTFIX from the days when Ulrich Drepper was maintainer.
Rich
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-11-15 21:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-15 20:23 sscanf(3) return value doesn't count %100c assignments David Wuertele
2013-11-15 20:47 ` Rich Felker
2013-11-15 21:17 ` David Wuertele
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).