This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib 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]

[wjoye@cfa.harvard.edu: 1.3.6: sscanf bug (error with %n)]


I haven't verified if this is actually a problem or not.

cgf

----- Forwarded message from William Joye <wjoye@cfa.harvard.edu> -----

From: William Joye <wjoye@cfa.harvard.edu>
To: cygwin@cygwin.com
Subject: 1.3.6: sscanf bug (error with %n)
Date: Fri, 11 Jan 2002 14:04:22 -0500

There seems to be a bug with trailing spaces and %n with sscanf strings.
In particular, %n fails if it is the last item in the format string and
it is preceeded with a space.

Here is some sample code:

#include <stdio.h>

main()
{
  char foo[] = " name 1111.1 ";

  char bar[8];
  float ff;
  int nc;
  int r;

  nc = 0;
  r = sscanf(foo, " %s %f %n", bar, &ff, &nc);
  printf ("  space got:%d count:%d\n", r, nc);

  nc = 0;
  r = sscanf(foo, " %s %f%n", bar, &ff, &nc);
  printf ("nospace got:%d count:%d\n", r, nc);
}

cygwin 1.3.6 outputs:

  space got:2 count:0
nospace got:2 count:12

The correct output should be:

  space got:2 count:13
nospace got:2 count:12

----- End forwarded message -----


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