Index: common/ioz.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/ioz.c,v retrieving revision 1.3 diff -u -r1.3 ioz.c --- ioz.c 2000/08/14 12:42:04 1.3 +++ ioz.c 2000/09/02 16:07:56 @@ -211,9 +211,10 @@ char buffer[4096]; int num; num = my_vsnprintf(buffer, sizeof(buffer), format, ap); - if (num >= sizeof(buffer)) { - freelog(LOG_ERROR, "Too much data: truncated in fz_fprintf (%d/%d)", - num, (int)sizeof(buffer)); + /* Do not assume C99 vsnprintf(). */ + if (num >= sizeof(buffer) || num == -1) { + freelog(LOG_ERROR, "Too much data: truncated in fz_fprintf (%d)", + (int)sizeof(buffer)); } retval = gzwrite(fp->u.zlib, buffer, (unsigned int)strlen(buffer)); } Index: common/support.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/support.c,v retrieving revision 1.9 diff -u -r1.9 support.c --- support.c 2000/08/12 04:15:00 1.9 +++ support.c 2000/09/02 16:07:58 @@ -119,7 +119,6 @@ #endif } - /*************************************************************** Return a string which describes a given error (errno-style.) ***************************************************************/ @@ -255,6 +254,7 @@ va_list ap; va_start(ap, format); + ret = vsnprintf(str, n, format, ap); va_end(ap); return ret; @@ -265,8 +265,8 @@ our requirements; specifically: - Should actually obey the parameter n, rather than, eg, just calling sprintf and ignoring n. - - On truncation, should return the number of chars (not counting - trailing null) which would have been printed, rather than, eg, -1. + - On truncation, should return either -1 or the number of chars (not + counting the trailing NUL) which would have been printed. Returns 1 if both ok. Also checks whether null-terminates on truncation, but we don't base return value on this since it is easy to force this behaviour. @@ -297,7 +297,8 @@ } #endif - return (buf[ntrunc]==one_past && ret==test_len); + return (buf[ntrunc] == one_past + && (ret == test_len || ret == -1); } #endif @@ -373,8 +374,8 @@ if (native_is_ok) { int ret = vsnprintf(str, n, format, ap); - /* Guarantee null-terminated: (native_is_ok means can use ret like this) */ - if (ret >= n) { + /* Guarantee NUL-terminated: */ + if (ret >= n || ret == -1) { str[n-1] = '\0'; } return ret; @@ -393,9 +394,8 @@ } #ifdef HAVE_VSNPRINTF - /* This occurs if have native, but didn't pass check: - * may just be that native doesn't give the right return, - * in which case may be slightly safer to use it here: + /* This occurs if have native, but didn't pass check, + * in which case it might be slightly safer to use it here: */ vsnprintf(buf, VSNP_BUF_SIZE, format, ap); #else Index: server/report.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/report.c,v retrieving revision 1.4 diff -u -r1.4 report.c --- report.c 2000/08/31 13:32:49 1.4 +++ report.c 2000/09/02 16:08:02 @@ -1374,6 +1374,7 @@ int len; struct packet_generic_message genmsg; + /* C99 */ len = my_snprintf(genmsg.message, sizeof(genmsg.message), "%s\n%s\n%s", caption, headline, lines); if (len >= sizeof(genmsg.message)) { Index: server/stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.160 diff -u -r1.160 stdinhand.c --- stdinhand.c 2000/09/01 13:34:38 1.160 +++ stdinhand.c 2000/09/02 16:08:12 @@ -2379,6 +2379,10 @@ cmd_reply_show(horiz_line); len1 = my_snprintf(buf, sizeof(buf), _("%-*s value (min,max) "), OPTION_NAME_SPACE, _("Option")); + if (len1 >= sizeof(buf) || len1 == -1) { + /* Don't assume C99 vsnprintf(). */ + len1 = sizeof(buf) - 1; + } sz_strlcat(buf, _("description")); cmd_reply_show(buf); cmd_reply_show(horiz_line); @@ -2406,6 +2410,10 @@ ((strcmp(op->svalue, op->default_svalue)==0) ? '=' : ' '), op->svalue); } + if (len >= sizeof(buf) || len == -1) { + /* Don't assume C99 vsnprintf(). */ + len = sizeof(buf) - 1; + } /* Line up the descriptions: */ if(len < len1) { cat_snprintf(buf, sizeof(buf), "%*s", (len1-len), " "); @@ -2413,6 +2421,9 @@ sz_strlcat(buf, " "); } sz_strlcat(buf, _(op->short_help)); +#if 0 /* I don't think this is necessary. --GS */ + buf[sizeof(buf) - 1] = 0; +#endif cmd_reply_show(buf); } }