44 *
55 * StringInfo provides an indefinitely-extensible string data type.
66 * It can be used to buffer either ordinary C strings (null-terminated text)
7- * or arbitrary binary data. All storage is allocated with palloc() and
8- * friends.
7+ * or arbitrary binary data. All storage is allocated with palloc().
98 *
109 * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
1110 * Portions Copyright (c) 1994, Regents of the University of California
@@ -37,29 +36,11 @@ makeStringInfo(void)
3736 return res ;
3837}
3938
40- /*
41- * makeLongStringInfo
42- *
43- * Same as makeStringInfo, for larger strings.
44- */
45- StringInfo
46- makeLongStringInfo (void )
47- {
48- StringInfo res ;
49-
50- res = (StringInfo ) palloc (sizeof (StringInfoData ));
51-
52- initLongStringInfo (res );
53-
54- return res ;
55- }
56-
57-
5839/*
5940 * initStringInfo
6041 *
6142 * Initialize a StringInfoData struct (with previously undefined contents)
62- * to describe an empty string; don't enable long strings yet .
43+ * to describe an empty string.
6344 */
6445void
6546initStringInfo (StringInfo str )
@@ -68,22 +49,9 @@ initStringInfo(StringInfo str)
6849
6950 str -> data = (char * ) palloc (size );
7051 str -> maxlen = size ;
71- str -> long_ok = false;
7252 resetStringInfo (str );
7353}
7454
75- /*
76- * initLongStringInfo
77- *
78- * Same as initStringInfo, plus enable long strings.
79- */
80- void
81- initLongStringInfo (StringInfo str )
82- {
83- initStringInfo (str );
84- str -> long_ok = true;
85- }
86-
8755/*
8856 * resetStringInfo
8957 *
@@ -174,7 +142,7 @@ appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
174142 /*
175143 * Return pvsnprintf's estimate of the space needed. (Although this is
176144 * given as a size_t, we know it will fit in int because it's not more
177- * than either MaxAllocSize or half an int's width .)
145+ * than MaxAllocSize.)
178146 */
179147 return (int ) nprinted ;
180148}
@@ -276,25 +244,15 @@ appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
276244void
277245enlargeStringInfo (StringInfo str , int needed )
278246{
279- Size newlen ;
280- Size limit ;
281-
282- /*
283- * Determine the upper size limit. Because of overflow concerns outside
284- * of this module, we limit ourselves to 4-byte signed integer range,
285- * even for "long_ok" strings.
286- */
287- limit = str -> long_ok ?
288- (((Size ) 1 ) << (sizeof (int32 ) * 8 - 1 )) - 1 :
289- MaxAllocSize ;
247+ int newlen ;
290248
291249 /*
292250 * Guard against out-of-range "needed" values. Without this, we can get
293251 * an overflow or infinite loop in the following.
294252 */
295253 if (needed < 0 ) /* should not happen */
296254 elog (ERROR , "invalid string enlargement request size: %d" , needed );
297- if (((Size ) needed ) >= (limit - (Size ) str -> len ))
255+ if (((Size ) needed ) >= (MaxAllocSize - (Size ) str -> len ))
298256 ereport (ERROR ,
299257 (errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
300258 errmsg ("out of memory" ),
@@ -303,7 +261,7 @@ enlargeStringInfo(StringInfo str, int needed)
303261
304262 needed += str -> len + 1 ; /* total space required now */
305263
306- /* Because of the above test, we now have needed <= limit */
264+ /* Because of the above test, we now have needed <= MaxAllocSize */
307265
308266 if (needed <= str -> maxlen )
309267 return ; /* got enough space already */
@@ -318,14 +276,14 @@ enlargeStringInfo(StringInfo str, int needed)
318276 newlen = 2 * newlen ;
319277
320278 /*
321- * Clamp to the limit in case we went past it. Note we are assuming here
322- * that limit <= INT_MAX/2, else the above loop could overflow. We will
323- * still have newlen >= needed.
279+ * Clamp to MaxAllocSize in case we went past it. Note we are assuming
280+ * here that MaxAllocSize <= INT_MAX/2, else the above loop could
281+ * overflow. We will still have newlen >= needed.
324282 */
325- if (newlen > limit )
326- newlen = limit ;
283+ if (newlen > ( int ) MaxAllocSize )
284+ newlen = ( int ) MaxAllocSize ;
327285
328- str -> data = (char * ) repalloc_huge (str -> data , ( Size ) newlen );
286+ str -> data = (char * ) repalloc (str -> data , newlen );
329287
330288 str -> maxlen = newlen ;
331289}
0 commit comments