|
9 | 9 | * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group |
10 | 10 | * Portions Copyright (c) 1994, Regents of the University of California |
11 | 11 | * |
12 | | - * $Id: stringinfo.c,v 1.29 2001/10/25 05:49:29 momjian Exp $ |
| 12 | + * $Id: stringinfo.c,v 1.30 2002/03/04 18:34:02 tgl Exp $ |
13 | 13 | * |
14 | 14 | *------------------------------------------------------------------------- |
15 | 15 | */ |
@@ -114,11 +114,22 @@ appendStringInfo(StringInfo str, const char *fmt,...) |
114 | 114 | avail=str->maxlen-str->len-1; |
115 | 115 | if (avail>16) |
116 | 116 | { |
| 117 | +/* |
| 118 | + * Assert check here is to catch buggy vsnprintf that overruns |
| 119 | + * the specified buffer length. Solaris 7 in 64-bit mode is |
| 120 | + * an example of a platform with such a bug. |
| 121 | + */ |
| 122 | +#ifdefUSE_ASSERT_CHECKING |
| 123 | +str->data[str->maxlen-1]='\0'; |
| 124 | +#endif |
| 125 | + |
117 | 126 | va_start(args,fmt); |
118 | 127 | nprinted=vsnprintf(str->data+str->len,avail, |
119 | 128 | fmt,args); |
120 | 129 | va_end(args); |
121 | 130 |
|
| 131 | +Assert(str->data[str->maxlen-1]=='\0'); |
| 132 | + |
122 | 133 | /* |
123 | 134 | * Note: some versions of vsnprintf return the number of chars |
124 | 135 | * actually stored, but at least one returns -1 on failure. Be |
|