Skip to content

Commit b1134e3

Browse files
committed
Cope with versions of vsnprintf() written by people who
don't read man pages...
1 parent bee7cd2 commit b1134e3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/backend/lib/stringinfo.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: stringinfo.c,v 1.21 1999/08/31 01:28:25 tgl Exp $
11+
* $Id: stringinfo.c,v 1.22 1999/09/08 16:31:38 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -121,7 +121,12 @@ appendStringInfo(StringInfo str, const char *fmt,...)
121121
nprinted = vsnprintf(str->data + str->len, avail,
122122
fmt, args);
123123
va_end(args);
124-
if (nprinted < avail-1)
124+
/*
125+
* Note: some versions of vsnprintf return the number of chars
126+
* actually stored, but at least one returns -1 on failure.
127+
* Be conservative about believing whether the print worked.
128+
*/
129+
if (nprinted >= 0 && nprinted < avail-1)
125130
{
126131
/* Success. Note nprinted does not include trailing null. */
127132
str->len += nprinted;

0 commit comments

Comments
 (0)