* large message), we will elog(ERROR), but we want to discard the
* message body so as not to lose communication sync.
*/
- PG_TRY();
+ if (!isStringInfoLargeEnough(s, len))
{
- enlargeStringInfo(s, len);
- }
- PG_CATCH();
- {
- if (pq_discardbytes(len) == EOF)
- ereport(COMMERROR,
- (errcode(ERRCODE_PROTOCOL_VIOLATION),
- errmsg("incomplete message from client")));
- PG_RE_THROW();
+ PG_TRY();
+ {
+ enlargeStringInfo(s, len);
+ }
+ PG_CATCH();
+ {
+ if (pq_discardbytes(len) == EOF)
+ ereport(COMMERROR,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("incomplete message from client")));
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
}
- PG_END_TRY();
/* And grab the message */
if (pq_getbytes(s->data, len) == EOF)
*/
extern void enlargeStringInfo(StringInfo str, int needed);
+/*------------------------
+ * isStringInfoLargeEnough
+ * Test whether a StringInfo's buffer can hold at least 'needed' more bytes.
+ */
+#define isStringInfoLargeEnough(str,needed) \
+ ((needed) < (str)->maxlen - ((str)->len + 1))
+
#endif /* STRINGINFO_H */