[ben -AT- 666 -PERIOD- com: Scanf bug]

Christopher Faylor me@cgf.cx
Sun Oct 3 22:12:00 GMT 2004

Just reported in the cygwin list...


----- Forwarded message from Ben Wing <ben -AT- 666 -PERIOD- com> -----

Somehow or other, sscanf() has gotten messed up in recent Cygwin

Test program, with output:

/xemacs/test 2391% cat testscanf.c
main (int argc, char **argv)
  int ret, cp1, cp2, endcount;
  char *p = "0x7d   0x000E  ";
  ret = sscanf (p, "%i %i%n", &cp1, &cp2, &endcount);
  printf ("ret: %d cp1: %d cp2: %d endcount: %d\n", ret, cp1, cp2,
  printf ("%d\n", endcount + strspn (p + endcount, " \t\n\r\f"));
  return 0;
/xemacs/test 2392% gcc --verbose testscanf.c
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/specs
Configured with: /gcc/gcc-3.3.3-3/configure --verbose --prefix=/usr
x=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib
hare/man --infodir=/usr/share/info
pascal --enable-nls --without-included-gettext --enable-libgcj
b --enable-interpreter --enable-threads=posix --enable-java-gc=boehm
lj-exceptions --disable-version-specific-runtime-libs
Thread model: posix
gcc version 3.3.3 (cygwin special)
 /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/cc1.exe -quiet -v -D__GNUC__=3
-D__unix__ -
D__unix -idirafter
api -idirafter
lib/../../include/w32api testscanf.c -quiet -dumpbase testscanf.c -auxbase
canf -version -o /DOCUME~1/BENWIN~1/LOCALS~1/Temp/cco65aDq.s
GNU C version 3.3.3 (cygwin special) (i686-pc-cygwin)
        compiled by GNU C version 3.3.3 (cygwin special).
GGC heuristics: --param ggc-min-expand=82 --param ggc-min-heapsize=98244
ignoring nonexistent directory "/usr/i686-pc-cygwin/include"
ignoring duplicate directory "/usr/i686-pc-cygwin/lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
raditional-format -o /DOCUME~1/BENWIN~1/LOCALS~1/Temp/ccSaWKvo.o
 /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/collect2.exe -Bdynamic
x=cyg /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/../../../crt0.o
6-pc-cygwin/3.3.3/crtbegin.o -L/usr/lib/gcc-lib/i686-pc-cygwin/3.3.3
o -lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc
/xemacs/test 2393% a
ret: 2 cp1: 125 cp2: 14 endcount: 11

The value of endcount should be 13, not 11.  The problem is with hex numbers
with more than one leading 0.  Change 0x000E to 0x0FFE or 0xFFFE and you get
13.  Change it to 0x00EE and you get 12.  In all cases cp2 is correct.

This used to work.  I know because the above code is part of XEmacs and we
are getting lots of warnings as a result of this bug, which didn't used to
be there, and the code hasn't changed.

Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

More information about the Newlib mailing list