snprintf return value

Alex Waugh Alex.Waugh at arm.com
Fri Oct 18 01:40:04 PDT 2002


snprintf sometimes returns EOF when the buffer is not large enough; it
should return the number of characters that would be written had the
buffer been big enough. The following patch fixes this.

Alex

Index: unixlib/source/stdio/printf.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/stdio/printf.c,v
retrieving revision 1.2.2.4
diff -u -r1.2.2.4 printf.c
--- unixlib/source/stdio/printf.c	18 Apr 2002 07:40:02 -0000	1.2.2.4
+++ unixlib/source/stdio/printf.c	18 Oct 2002 08:31:28 -0000
@@ -905,11 +905,6 @@
  		/* finally, adjust ret */
  		ret += width > realsz ? width : realsz;

-                if (max < 1 || (flags & STOP))
-                {
-                    ret = EOF;
-                    break;
-                }
  	}
  done:
  	if (ferror(fp))




More information about the gcc mailing list