This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
GLibc sscanf bug
- From: wasik <wasik at broumovska dot lbcfree dot net>
- To: libc-alpha at sources dot redhat dot com
- Date: Sat, 19 Jun 2004 17:51:17 +0200
- Subject: GLibc sscanf bug
Hello,
while configuring Nagios a nice network monitoring software I found that
glibc sscanf returns incorrect results.
I have following test program:
#include <stdio.h>
int main(int argc, char * argv[])
{
int pl =-1;
char input_buffer[]="10 packets transmitted, 0 received, +2
errors, 100% packet loss, time 9000ms\n";
sscanf (input_buffer, "%*d packets transmitted, %*d packets received,
+%*d errors, %d%% packet loss", &pl);
printf("pl: %d\n",pl);
sscanf (input_buffer, "%*d packets transmitted, %*d received,
%d%% loss, time", &pl);
printf("pl: %d\n",pl);
sscanf (input_buffer, "%*d packets transmitted, %*d received,
+%*d errors, %d%% packet loss, time", &pl);
printf("pl: %d\n",pl);
}
Its output is:
pl: -1
pl: 2
pl: 100
I think the second line should be -1 as the line does not match defined
format of sscanf.
Thanks for help,
Jan Wasserbauer