Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!ut-sally!utah-cs!utah-gr!uplherc!jr From: jr@uplherc.UUCP (J.R. Westmoreland) Newsgroups: comp.lang.c++ Subject: form() bug and fix Message-ID: <121@uplherc.UUCP> Date: Fri, 17-Jul-87 12:58:22 EDT Article-I.D.: uplherc.121 Posted: Fri Jul 17 12:58:22 1987 Date-Received: Sat, 18-Jul-87 17:13:53 EDT Organization: Utah Power & Light, Salt Lake City Lines: 89 The form function can not handle a very large or complex format. The reason is that the call to sprintf in the file out.c onlly copies 10*sizeof(int) bytes of the argument list. The following small test program will exhibit the bug. #includemain() { float x1 = 1.5, x2 = 2.5, x3 = 3.5, x4 = 4.5, x5 = 5.5, x6 = 6.5, x7 = 7.5, x8 = 8.5, x9 = 9.5, x10 = 10.5; cout << form("float\t%g %g %g %g %g %g %g %g %g %g\n", x1, x2, x3, x4, x5, x6, x7, x8, x9, x10); } Here is the patch that overcomes the problem. I have tested the patch for BSD but do not have a easy way to test the sysv patch. I believe that this patch will also work on v1.2 but since we do not have that version yet I am not positive. *** /usr/c++/incl/stdio.h.orig Fri Jul 17 08:59:43 1987 --- /usr/c++/incl/stdio.h Fri Jul 17 09:08:23 1987 *************** *** 30,37 **** --- 30,43 ---- #define _IOMYBUF 0010 #define _IOEOF 0020 #define _IOERR 0040 + #ifdef BSD + #define _IOSTRG 0100 + #define _IOLBF 0200 + #define _IORW 0400 + #else #define _IOLBF 0100 #define _IORW 0200 + #endif #define NULL 0 #define FILE struct _iobuf #define EOF (-1) *** /usr/c++/lib/stream/out.c.orig Fri Dec 19 11:01:05 1986 --- /usr/c++/lib/stream/out.c Fri Jul 17 09:24:45 1987 *************** *** 8,13 **** --- 8,19 ---- strlen(const char*); #include "stream.h" #include + # ifdef BSD + #include + _doprnt(const char*, int*, FILE*); + #else + vsprintf(char*, char*, int*); + #endif #define MAXOSTREAMS 20 *************** *** 70,76 **** register char* buf = bfree; if (max < buf+fld_size) buf = formbuf; ! register ll = sprintf(buf,format,ap[0],ap[1],ap[2],ap[3],ap[4],ap[5],ap[6],ap[7],ap[8],ap[9]); // too few words copied if (0