This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]