PostgreSQL Source Code git master
pqexpbuffer.c File Reference
#include "postgres_fe.h"
#include <limits.h>
#include "pqexpbuffer.h"
Include dependency graph for pqexpbuffer.c:

Go to the source code of this file.

Functions

static void markPQExpBufferBroken (PQExpBuffer str)
 
PQExpBuffer createPQExpBuffer (void)
 
void initPQExpBuffer (PQExpBuffer str)
 
void destroyPQExpBuffer (PQExpBuffer str)
 
void termPQExpBuffer (PQExpBuffer str)
 
void resetPQExpBuffer (PQExpBuffer str)
 
int enlargePQExpBuffer (PQExpBuffer str, size_t needed)
 
void printfPQExpBuffer (PQExpBuffer str, const char *fmt,...)
 
void appendPQExpBuffer (PQExpBuffer str, const char *fmt,...)
 
bool appendPQExpBufferVA (PQExpBuffer str, const char *fmt, va_list args)
 
void appendPQExpBufferStr (PQExpBuffer str, const char *data)
 
void appendPQExpBufferChar (PQExpBuffer str, char ch)
 
void appendBinaryPQExpBuffer (PQExpBuffer str, const char *data, size_t datalen)
 

Variables

static const char oom_buffer [1] = ""
 
static const char *const oom_buffer_ptr = oom_buffer
 

Function Documentation

◆ appendBinaryPQExpBuffer()

void appendBinaryPQExpBuffer ( PQExpBuffer  str,
const char *  data,
size_t  datalen 
)

Definition at line 397 of file pqexpbuffer.c.

398{
399 /* Make more room if needed */
400 if (!enlargePQExpBuffer(str, datalen))
401 return;
402
403 /* OK, append the data */
404 memcpy(str->data + str->len, data, datalen);
405 str->len += datalen;
406
407 /*
408 * Keep a trailing null in place, even though it's probably useless for
409 * binary data...
410 */
411 str->data[str->len] = '\0';
412}
const char * str
const void * data
int enlargePQExpBuffer(PQExpBuffer str, size_t needed)
Definition: pqexpbuffer.c:172

References data, enlargePQExpBuffer(), and str.

Referenced by appendPQExpBufferStr(), createViewAsClause(), dumpTableSchema(), evaluate_backtick(), pg_GSS_error_int(), pqGets_internal(), and psqlscan_emit().

◆ appendPQExpBuffer()

void appendPQExpBuffer ( PQExpBuffer  str,
const char *  fmt,
  ... 
)

Definition at line 265 of file pqexpbuffer.c.

266{
267 int save_errno = errno;
268 va_list args;
269 bool done;
270
272 return; /* already failed */
273
274 /* Loop in case we have to retry after enlarging the buffer. */
275 do
276 {
277 errno = save_errno;
278 va_start(args, fmt);
280 va_end(args);
281 } while (!done);
282}
static void const char * fmt
va_end(args)
va_start(args, fmt)
bool appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args)
Definition: pqexpbuffer.c:294
#define PQExpBufferBroken(str)
Definition: pqexpbuffer.h:59

References appendPQExpBufferVA(), generate_unaccent_rules::args, fmt, PQExpBufferBroken, str, va_end(), and va_start().

Referenced by _getObjectDescription(), _printTableAccessMethodNoStorage(), _selectOutputSchema(), _selectTableAccessMethod(), _selectTablespace(), add_tablespace_footer(), AddAcl(), addFooterToPublicationDesc(), append_db_pattern_cte(), append_depends_on_extension(), append_rel_pattern_filtered_cte(), append_rel_pattern_raw_cte(), AppendIntegerCommandOption(), AppendPlainCommandOption(), appendReloptionsArray(), AppendStringCommandOption(), binary_upgrade_extension_member(), binary_upgrade_set_pg_class_oids(), binary_upgrade_set_type_oids_by_type_oid(), bootstrap_template1(), build_client_final_message(), build_client_first_message(), buildACLCommands(), buildDefaultACLCommands(), buildShSecLabelQuery(), check_and_drop_existing_subscriptions(), cluster_conn_opts(), compile_relation_list_one_db(), connectFailureMessage(), constructConnStr(), create_logical_replication_slot(), create_logical_replication_slots(), create_publication(), create_subscription(), createDummyViewAsClause(), createPartitions(), CreateReplicationSlot(), createViewAsClause(), describeAccessMethods(), describeAggregates(), describeConfigurationParameters(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOperators(), describePublications(), DescribeQuery(), describeRoleGrants(), describeRoles(), describeSubscriptions(), describeTablespaces(), describeTypes(), drop_existing_subscriptions(), drop_publication(), drop_replication_slot(), DropReplicationSlot(), dumpAccessMethod(), dumpACL(), dumpAgg(), dumpAttrDef(), dumpBaseType(), dumpCast(), dumpCollation(), dumpCommentExtended(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpDatabase(), dumpDefaultACL(), dumpDomain(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpIndex(), dumpIndexAttach(), dumpLO(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpPolicy(), dumpProcLang(), dumpPublication(), dumpPublicationNamespace(), dumpPublicationTable(), dumpRangeType(), dumpRoleMembership(), dumpRoles(), dumpRule(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpShellType(), dumpStatisticsExt(), dumpStdStrings(), dumpSubscription(), dumpSubscriptionTable(), dumpTableAttach(), dumpTableComment(), dumpTableConstraintComment(), dumpTableData(), dumpTableData_copy(), dumpTableData_insert(), dumpTableSchema(), dumpTableSecLabel(), dumpTablespaces(), dumpTransform(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), dumpUndefinedType(), dumpUserMappings(), emitHostIdentityInfo(), emitShSecLabels(), enable_subscription(), executeMetaCommand(), expand_table_name_patterns(), fmtQualifiedId(), format_aggregate_signature(), format_function_arguments(), format_function_signature(), GenerateRecoveryConfig(), get_create_object_cmd(), get_db_conn(), get_language_name(), get_rel_infos_query(), getAggregates(), getAnotherTuple(), getCasts(), getConstraints(), getFormattedTypeName(), getFuncs(), getIndexes(), getParamDescriptions(), getPolicies(), getRowDescriptions(), GetSlotInformation(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), initCreatePKeys(), initCreateTables(), is_load_via_partition_root(), libpqrcv_get_conninfo(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDomains(), listEventTriggers(), listExtendedStats(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listLargeObjects(), listOperatorClasses(), listOperatorFamilies(), listOpFamilyFunctions(), listOpFamilyOperators(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSDictionaries(), listUserMappings(), lockTableForWorker(), lookup_object_oid(), main(), makeAlterConfigCommand(), objectDescription(), parseAclItem(), permissionsList(), pg_GSS_error(), pq_verify_peer_name_matches_certificate(), pqBuildErrorMessage3(), pqGetNegotiateProtocolVersion3(), pqsecure_open_gss(), prepare_btree_command(), prepare_heap_command(), prepare_vacuum_command(), printACLColumn(), printVerboseErrorMessages(), process_data_type_check(), processSQLNamePattern(), ReceiveArchiveStreamChunk(), ReceiveBackupManifestInMemoryChunk(), refreshMatViewData(), replace_guc_value(), reportErrorPosition(), RestoreArchive(), run_reindex_command(), runInitSteps(), runPgDump(), set_replication_progress(), set_restrict_relation_kind(), setup_connection(), setup_recovery(), start_conn(), start_standby_server(), StreamLogicalLog(), syntax_error(), test_specific_config_settings(), upgrade_task_add_step(), and vacuum_one_database().

◆ appendPQExpBufferChar()

void appendPQExpBufferChar ( PQExpBuffer  str,
char  ch 
)

Definition at line 378 of file pqexpbuffer.c.

379{
380 /* Make more room if needed */
381 if (!enlargePQExpBuffer(str, 1))
382 return;
383
384 /* OK, append the character */
385 str->data[str->len] = ch;
386 str->len++;
387 str->data[str->len] = '\0';
388}

References enlargePQExpBuffer(), and str.

Referenced by _doSetSessionAuth(), AddAcl(), append_db_pattern_cte(), append_rel_pattern_raw_cte(), appendConnStrItem(), appendConnStrVal(), appendPGArray(), AppendPlainCommandOption(), appendPsqlMetaConnect(), appendShellStringNoError(), appendStringLiteralConn(), appendStringLiteralDQ(), binary_upgrade_set_pg_class_oids(), build_client_first_message(), cluster_conn_opts(), cluster_one_database(), conninfo_uri_parse_options(), constructConnStr(), createDummyViewAsClause(), createPartitions(), CreateReplicationSlot(), dequoteAclUserName(), describeOneTableDetails(), describeRoles(), do_edit(), dumpCompositeType(), dumpConstraint(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpPublication(), dumpRule(), dumpTableData_insert(), dumpTableSchema(), dumpUserConfig(), ExecuteSimpleCommands(), fmtCopyColumnList(), fmtId(), format_aggregate_signature(), format_function_signature(), gather_boolean_expression(), GenerateRecoveryConfig(), get_create_object_cmd(), getAggregates(), getConstraints(), getFuncs(), getIndexes(), getNamespaces(), getPolicies(), getTableAttrs(), getTriggers(), indent_lines(), libpq_append_conn_error(), libpq_append_error(), main(), MainLoop(), minimal_error_message(), output_completion_banner(), patternToSQLRegex(), pg_append_history(), pg_GSS_error(), pg_GSS_error_int(), pq_verify_peer_name_matches_certificate(), pqBuildErrorMessage3(), PQconnectPoll(), pqGetNegotiateProtocolVersion3(), prepare_vacuum_command(), processSQLNamePattern(), psqlscan_emit(), quoteAclUserName(), read_pattern(), read_quoted_string(), replace_guc_value(), reportErrorPosition(), run_reindex_command(), start_standby_server(), and StreamLogicalLog().

◆ appendPQExpBufferStr()

void appendPQExpBufferStr ( PQExpBuffer  str,
const char *  data 
)

Definition at line 367 of file pqexpbuffer.c.

368{
370}
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:397

References appendBinaryPQExpBuffer(), data, and str.

Referenced by _doSetSessionAuth(), _getObjectDescription(), _printTableAccessMethodNoStorage(), _selectOutputSchema(), _selectTablespace(), add_role_attribute(), AddAcl(), append_db_pattern_cte(), append_rel_pattern_filtered_cte(), append_rel_pattern_raw_cte(), appendConnStrItem(), appendConnStrVal(), appendPGArray(), AppendPlainCommandOption(), appendPsqlMetaConnect(), appendQualifiedRelation(), appendReloptionsArray(), appendShellStringNoError(), appendStringLiteralDQ(), binary_upgrade_extension_member(), binary_upgrade_set_pg_class_oids(), binary_upgrade_set_type_oids_by_type_oid(), build_client_final_message(), build_client_first_message(), buildACLCommands(), buildMatViewRefreshDependencies(), check_for_incompatible_polymorphics(), cluster_conn_opts(), cluster_one_database(), collectComments(), collectSecLabels(), compile_database_list(), compile_relation_list_one_db(), concat_conninfo_dbname(), conninfo_uri_parse_options(), copy_previous_query(), create_sql_command(), createDummyViewAsClause(), createPartitions(), CreateReplicationSlot(), describeAccessMethods(), describeAggregates(), describeConfigurationParameters(), describeFunctions(), describeOneTableDetails(), describeOperators(), describePublications(), DescribeQuery(), describeRoleGrants(), describeRoles(), describeSubscriptions(), describeTableDetails(), describeTablespaces(), describeTypes(), do_copy(), do_edit(), dumpAccessMethod(), dumpACL(), dumpAgg(), dumpBaseType(), dumpCast(), dumpCollation(), dumpCommentExtended(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpDatabase(), dumpDomain(), dumpEncoding(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpPolicy(), dumpProcLang(), dumpPublication(), dumpPublicationTable(), dumpRangeType(), dumpRoleMembership(), dumpRoles(), dumpRule(), dumpSearchPath(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpSubscription(), dumpSubscriptionTable(), dumpTable(), dumpTableAttach(), dumpTableComment(), dumpTableData_copy(), dumpTableData_insert(), dumpTableSchema(), dumpTableSecLabel(), dumpTablespaces(), dumpTransform(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpUserMappings(), emitShSecLabels(), ensureCleanShutdown(), exec_command_ef_ev(), expand_dbname_patterns(), expand_extension_name_patterns(), expand_foreign_server_name_patterns(), expand_schema_name_patterns(), fmtCopyColumnList(), fmtId(), fmtQualifiedId(), format_aggregate_signature(), format_function_arguments(), format_function_signature(), gather_boolean_expression(), generate_old_dump(), GenerateRecoveryConfig(), get_create_object_cmd(), get_db_conn(), get_parallel_object_list(), get_rel_infos_query(), getAccessMethods(), getAdditionalACLs(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDependencies(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getInherits(), getLOs(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPartitioningInfo(), getPolicies(), getProcLangs(), getPublicationNamespaces(), getPublications(), getPublicationTables(), getRestoreCommand(), getRules(), gets_fromFile(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), indent_lines(), initCreatePKeys(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtendedStats(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listLargeObjects(), listOperatorClasses(), listOperatorFamilies(), listOpFamilyFunctions(), listOpFamilyOperators(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), lookup_object_oid(), main(), makeAlterConfigCommand(), minimal_error_message(), objectDescription(), output_completion_banner(), patternToSQLRegex(), permissionsList(), pg_append_history(), pg_fe_sendauth(), pg_GSS_write(), pg_SASL_init(), pgtls_read(), pgtls_write(), pqBuildErrorMessage3(), pqCheckInBufferSpace(), pqCheckOutBufferSpace(), pqConnectDBStart(), pqGetErrorNotice3(), pqGetNegotiateProtocolVersion3(), pqPipelineSyncInternal(), pqSaveWriteError(), prepare_vacuum_command(), printVerboseErrorMessages(), processSQLNamePattern(), psqlscan_escape_variable(), read_pattern(), replace_guc_value(), reportErrorPosition(), RestoreArchive(), run_reindex_command(), runInitSteps(), runPgDump(), setup_connection(), start_conn(), start_postmaster(), start_standby_server(), StreamLogicalLog(), and vacuum_one_database().

◆ appendPQExpBufferVA()

bool appendPQExpBufferVA ( PQExpBuffer  str,
const char *  fmt,
va_list  args 
)

Definition at line 294 of file pqexpbuffer.c.

295{
296 size_t avail;
297 size_t needed;
298 int nprinted;
299
300 /*
301 * Try to format the given string into the available space; but if there's
302 * hardly any space, don't bother trying, just enlarge the buffer first.
303 */
304 if (str->maxlen > str->len + 16)
305 {
306 avail = str->maxlen - str->len;
307
308 nprinted = vsnprintf(str->data + str->len, avail, fmt, args);
309
310 /*
311 * If vsnprintf reports an error, fail (we assume this means there's
312 * something wrong with the format string).
313 */
314 if (unlikely(nprinted < 0))
315 {
317 return true;
318 }
319
320 if ((size_t) nprinted < avail)
321 {
322 /* Success. Note nprinted does not include trailing null. */
323 str->len += nprinted;
324 return true;
325 }
326
327 /*
328 * We assume a C99-compliant vsnprintf, so believe its estimate of the
329 * required space, and add one for the trailing null. (If it's wrong,
330 * the logic will still work, but we may loop multiple times.)
331 *
332 * Choke if the required space would exceed INT_MAX, since str->maxlen
333 * can't represent more than that.
334 */
335 if (unlikely(nprinted > INT_MAX - 1))
336 {
338 return true;
339 }
340 needed = nprinted + 1;
341 }
342 else
343 {
344 /*
345 * We have to guess at how much to enlarge, since we're skipping the
346 * formatting work. Fortunately, because of enlargePQExpBuffer's
347 * preference for power-of-2 sizes, this number isn't very sensitive;
348 * the net effect is that we'll double the buffer size before trying
349 * to run vsnprintf, which seems sensible.
350 */
351 needed = 32;
352 }
353
354 /* Increase the buffer size and try again. */
355 if (!enlargePQExpBuffer(str, needed))
356 return true; /* oops, out of memory */
357
358 return false;
359}
#define unlikely(x)
Definition: c.h:333
#define vsnprintf
Definition: port.h:237
static void markPQExpBufferBroken(PQExpBuffer str)
Definition: pqexpbuffer.c:50

References generate_unaccent_rules::args, enlargePQExpBuffer(), fmt, markPQExpBufferBroken(), str, unlikely, and vsnprintf.

Referenced by appendPQExpBuffer(), libpq_append_conn_error(), libpq_append_error(), and printfPQExpBuffer().

◆ createPQExpBuffer()

PQExpBuffer createPQExpBuffer ( void  )

Definition at line 72 of file pqexpbuffer.c.

73{
75
77 if (res != NULL)
79
80 return res;
81}
#define malloc(a)
Definition: header.h:50
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
PQExpBufferData * PQExpBuffer
Definition: pqexpbuffer.h:51

References initPQExpBuffer(), malloc, and res.

Referenced by _doSetSessionAuth(), _printTableAccessMethodNoStorage(), _selectOutputSchema(), _selectTableAccessMethod(), _selectTablespace(), _WriteLOData(), append_depends_on_extension(), appendStringLiteralDQ(), binary_upgrade_set_type_oids_by_type_oid(), buildACLCommands(), buildDefaultACLCommands(), buildMatViewRefreshDependencies(), buildShSecLabels(), check_and_drop_existing_subscriptions(), cluster_conn_opts(), collectComments(), collectSecLabels(), concat_conninfo_dbname(), constructConnStr(), create_logical_replication_slot(), create_logical_replication_slots(), create_publication(), create_subscription(), createDummyViewAsClause(), CreateReplicationSlot(), createViewAsClause(), drop_existing_subscriptions(), drop_publication(), drop_replication_slot(), DropReplicationSlot(), dropRoles(), dump_lo_buf(), dumpAccessMethod(), dumpACL(), dumpAgg(), dumpAttrDef(), dumpBaseType(), dumpCast(), dumpCollation(), dumpCommentExtended(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpDatabase(), dumpDatabaseConfig(), dumpDefaultACL(), dumpDomain(), dumpEncoding(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpIndex(), dumpIndexAttach(), dumpLO(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpPolicy(), dumpProcLang(), dumpPublication(), dumpPublicationNamespace(), dumpPublicationTable(), dumpRangeType(), dumpRoleGUCPrivs(), dumpRoleMembership(), dumpRoles(), dumpRule(), dumpSearchPath(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpShellType(), dumpStatisticsExt(), dumpStdStrings(), dumpSubscription(), dumpSubscriptionTable(), dumpTable(), dumpTableAttach(), dumpTableComment(), dumpTableConstraintComment(), dumpTableData(), dumpTableData_copy(), dumpTableData_insert(), dumpTableSchema(), dumpTableSecLabel(), dumpTablespaces(), dumpTransform(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), dumpUndefinedType(), dumpUserConfig(), dumpUserMappings(), enable_subscription(), ensureCleanShutdown(), exec_command_sf_sv(), ExecuteSimpleCommands(), expand_dbname_patterns(), expand_extension_name_patterns(), expand_foreign_server_name_patterns(), expand_schema_name_patterns(), expand_table_name_patterns(), fmtQualifiedId(), gather_boolean_expression(), GenerateRecoveryConfig(), get_base_conninfo(), get_create_object_cmd(), get_language_name(), get_sub_conninfo(), getAccessMethods(), getAdditionalACLs(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDependencies(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFormattedTypeName(), getFuncs(), getIndexes(), getInherits(), getLOs(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPartitioningInfo(), getPolicies(), getProcLangs(), getPublicationNamespaces(), getPublications(), getPublicationTables(), getRestoreCommand(), getRules(), gets_fromFile(), GetSlotInformation(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), is_load_via_partition_root(), lockTableForWorker(), lookup_object_oid(), main(), MainLoop(), minimal_error_message(), printVerboseErrorMessages(), process_data_type_check(), processExtensionTables(), ReceiveArchiveStreamChunk(), refreshMatViewData(), replace_guc_value(), RestoreArchive(), set_replication_progress(), set_restrict_relation_kind(), setup_connection(), start_standby_server(), StreamLogicalLog(), and upgrade_task_create().

◆ destroyPQExpBuffer()

void destroyPQExpBuffer ( PQExpBuffer  str)

Definition at line 114 of file pqexpbuffer.c.

115{
116 if (str)
117 {
119 free(str);
120 }
121}
#define free(a)
Definition: header.h:65
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129

References free, str, and termPQExpBuffer().

Referenced by _doSetSessionAuth(), _printTableAccessMethodNoStorage(), _selectOutputSchema(), _selectTableAccessMethod(), _selectTablespace(), _WriteLOData(), append_depends_on_extension(), appendStringLiteralDQ(), BaseBackup(), binary_upgrade_set_type_oids_by_type_oid(), buildACLCommands(), buildDefaultACLCommands(), buildMatViewRefreshDependencies(), buildShSecLabels(), check_and_drop_existing_subscriptions(), check_for_data_types_usage(), collectComments(), collectSecLabels(), concat_conninfo_dbname(), constructConnStr(), create_logical_replication_slot(), create_logical_replication_slots(), create_publication(), create_subscription(), CreateReplicationSlot(), createViewAsClause(), DeCloneArchive(), drop_existing_subscriptions(), drop_publication(), drop_replication_slot(), DropReplicationSlot(), dropRoles(), dump_lo_buf(), dumpAccessMethod(), dumpACL(), dumpAgg(), dumpAttrDef(), dumpBaseType(), dumpCast(), dumpCollation(), dumpCommentExtended(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpDatabase(), dumpDatabaseConfig(), dumpDefaultACL(), dumpDomain(), dumpEncoding(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpIndex(), dumpIndexAttach(), dumpLO(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpPolicy(), dumpProcLang(), dumpPublication(), dumpPublicationNamespace(), dumpPublicationTable(), dumpRangeType(), dumpRoleGUCPrivs(), dumpRoleMembership(), dumpRoles(), dumpRule(), dumpSearchPath(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpShellType(), dumpStatisticsExt(), dumpStdStrings(), dumpSubscription(), dumpSubscriptionTable(), dumpTable(), dumpTableAttach(), dumpTableComment(), dumpTableConstraintComment(), dumpTableData(), dumpTableData_copy(), dumpTableData_insert(), dumpTableSchema(), dumpTableSecLabel(), dumpTablespaces(), dumpTransform(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), dumpUndefinedType(), dumpUserConfig(), dumpUserMappings(), enable_subscription(), ensureCleanShutdown(), exec_command_sf_sv(), expand_dbname_patterns(), expand_extension_name_patterns(), expand_foreign_server_name_patterns(), expand_schema_name_patterns(), expand_table_name_patterns(), fmtQualifiedId(), get_base_conninfo(), get_create_object_cmd(), get_language_name(), get_sub_conninfo(), getAccessMethods(), getAdditionalACLs(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDependencies(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFormattedTypeName(), getFuncs(), getIndexes(), getInherits(), getLOs(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPartitioningInfo(), getPolicies(), getProcLangs(), getPublicationNamespaces(), getPublications(), getPublicationTables(), getRestoreCommand(), getRules(), GetSlotInformation(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), ignore_boolean_expression(), is_load_via_partition_root(), is_true_boolean_expression(), lockTableForWorker(), lookup_object_oid(), main(), MainLoop(), minimal_error_message(), processExtensionTables(), ReceiveArchiveStream(), refreshMatViewData(), RestoreArchive(), set_replication_progress(), set_restrict_relation_kind(), setup_connection(), start_standby_server(), StreamLogicalLog(), and upgrade_task_free().

◆ enlargePQExpBuffer()

int enlargePQExpBuffer ( PQExpBuffer  str,
size_t  needed 
)

Definition at line 172 of file pqexpbuffer.c.

173{
174 size_t newlen;
175 char *newdata;
176
178 return 0; /* already failed */
179
180 /*
181 * Guard against ridiculous "needed" values, which can occur if we're fed
182 * bogus data. Without this, we can get an overflow or infinite loop in
183 * the following.
184 */
185 if (needed >= ((size_t) INT_MAX - str->len))
186 {
188 return 0;
189 }
190
191 needed += str->len + 1; /* total space required now */
192
193 /* Because of the above test, we now have needed <= INT_MAX */
194
195 if (needed <= str->maxlen)
196 return 1; /* got enough space already */
197
198 /*
199 * We don't want to allocate just a little more space with each append;
200 * for efficiency, double the buffer size each time it overflows.
201 * Actually, we might need to more than double it if 'needed' is big...
202 */
203 newlen = (str->maxlen > 0) ? (2 * str->maxlen) : 64;
204 while (needed > newlen)
205 newlen = 2 * newlen;
206
207 /*
208 * Clamp to INT_MAX in case we went past it. Note we are assuming here
209 * that INT_MAX <= UINT_MAX/2, else the above loop could overflow. We
210 * will still have newlen >= needed.
211 */
212 if (newlen > (size_t) INT_MAX)
213 newlen = (size_t) INT_MAX;
214
215 newdata = (char *) realloc(str->data, newlen);
216 if (newdata != NULL)
217 {
218 str->data = newdata;
219 str->maxlen = newlen;
220 return 1;
221 }
222
224 return 0;
225}
#define realloc(a, b)
Definition: header.h:60

References markPQExpBufferBroken(), PQExpBufferBroken, realloc, and str.

Referenced by appendBinaryPQExpBuffer(), appendByteaLiteral(), appendPQExpBufferChar(), appendPQExpBufferVA(), appendStringLiteral(), appendStringLiteralConn(), build_client_final_message(), and passwordFromFile().

◆ initPQExpBuffer()

void initPQExpBuffer ( PQExpBuffer  str)

Definition at line 90 of file pqexpbuffer.c.

91{
92 str->data = (char *) malloc(INITIAL_EXPBUFFER_SIZE);
93 if (str->data == NULL)
94 {
95 str->data = unconstify(char *, oom_buffer_ptr); /* see comment above */
96 str->maxlen = 0;
97 str->len = 0;
98 }
99 else
100 {
101 str->maxlen = INITIAL_EXPBUFFER_SIZE;
102 str->len = 0;
103 str->data[0] = '\0';
104 }
105}
#define unconstify(underlying_type, expr)
Definition: c.h:1202
static const char *const oom_buffer_ptr
Definition: pqexpbuffer.c:41
#define INITIAL_EXPBUFFER_SIZE
Definition: pqexpbuffer.h:76

References INITIAL_EXPBUFFER_SIZE, malloc, oom_buffer_ptr, str, and unconstify.

Referenced by _printTocEntry(), _reconnectToDB(), add_tablespace_footer(), append_database_pattern(), append_relation_pattern_helper(), append_schema_pattern(), appendPsqlMetaConnect(), appendQualifiedRelation(), BaseBackup(), bootstrap_template1(), build_client_final_message(), build_client_first_message(), check_for_incompatible_polymorphics(), cluster_one_database(), compile_database_list(), compile_relation_list_one_db(), conninfo_uri_parse_options(), create_sql_command(), createPartitions(), createPQExpBuffer(), describeAccessMethods(), describeAggregates(), describeConfigurationParameters(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describePublications(), DescribeQuery(), describeRoleGrants(), describeRoles(), describeSubscriptions(), describeTableDetails(), describeTablespaces(), describeTypes(), do_copy(), evaluate_backtick(), exec_command_password(), executeMetaCommand(), expand_schema_name_patterns(), expand_table_name_patterns(), filter_read_item(), format_aggregate_signature(), format_function_arguments(), format_function_signature(), generate_old_dump(), GenerateRecoveryConfig(), get_db_conn(), get_parallel_object_list(), get_rel_infos_query(), getCasts(), getParameterStatus(), getTransforms(), helpSQL(), helpVariables(), indent_lines(), initCreatePKeys(), initCreateTables(), initGenerateDataServerSide(), initialize_data_directory(), initPopulateTable(), libpqrcv_get_conninfo(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtendedStats(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listLargeObjects(), listOneExtensionContents(), listOperatorClasses(), listOperatorFamilies(), listOpFamilyFunctions(), listOpFamilyOperators(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), main(), objectDescription(), old_9_6_invalidate_hash_indexes(), output_completion_banner(), ParseScript(), passwordFromFile(), patternToSQLRegex(), permissionsList(), pg_SASL_init(), PQchangePassword(), PQconndefaults(), PQconninfo(), PQconninfoParse(), pqGetErrorNotice3(), pqGetNegotiateProtocolVersion3(), pqMakeEmptyPGconn(), PQresultVerboseErrorMessage(), process_backslash_command(), process_extension_updates(), processSQLNamePattern(), psql_get_variable(), psql_scan_slash_command(), psql_scan_slash_option(), ReceiveTarFile(), resetPQExpBuffer(), run_reindex_command(), runInitSteps(), runPgDump(), slashUsage(), start_conn(), start_postmaster(), syntax_error(), test_specific_config_settings(), usage(), vacuum_one_database(), and validateSQLNamePattern().

◆ markPQExpBufferBroken()

static void markPQExpBufferBroken ( PQExpBuffer  str)
static

Definition at line 50 of file pqexpbuffer.c.

51{
52 if (str->data != oom_buffer)
53 free(str->data);
54
55 /*
56 * Casting away const here is a bit ugly, but it seems preferable to not
57 * marking oom_buffer const. We want to do that to encourage the compiler
58 * to put oom_buffer in read-only storage, so that anyone who tries to
59 * scribble on a broken PQExpBuffer will get a failure.
60 */
61 str->data = unconstify(char *, oom_buffer_ptr);
62 str->len = 0;
63 str->maxlen = 0;
64}
static const char oom_buffer[1]
Definition: pqexpbuffer.c:38

References free, oom_buffer, oom_buffer_ptr, str, and unconstify.

Referenced by appendPQExpBufferVA(), and enlargePQExpBuffer().

◆ printfPQExpBuffer()

void printfPQExpBuffer ( PQExpBuffer  str,
const char *  fmt,
  ... 
)

Definition at line 235 of file pqexpbuffer.c.

236{
237 int save_errno = errno;
238 va_list args;
239 bool done;
240
242
244 return; /* already failed */
245
246 /* Loop in case we have to retry after enlarging the buffer. */
247 do
248 {
249 errno = save_errno;
250 va_start(args, fmt);
252 va_end(args);
253 } while (!done);
254}
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146

References appendPQExpBufferVA(), generate_unaccent_rules::args, fmt, PQExpBufferBroken, resetPQExpBuffer(), str, va_end(), and va_start().

Referenced by add_tablespace_footer(), addFooterToPublicationDesc(), binary_upgrade_set_type_oids_by_type_oid(), bootstrap_template1(), buildACLCommands(), createPartitions(), describeAccessMethods(), describeAggregates(), describeConfigurationParameters(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describePublications(), DescribeQuery(), describeRoleGrants(), describeRoles(), describeSubscriptions(), describeTableDetails(), describeTablespaces(), describeTypes(), do_copy(), dropRoles(), dumpAgg(), dumpBaseType(), dumpCompositeType(), dumpDatabaseConfig(), dumpDomain(), dumpEnumType(), dumpFunc(), dumpOpr(), dumpRangeType(), dumpRoleMembership(), dumpRoles(), dumpRule(), dumpTable(), dumpTableAttach(), dumpTableData(), dumpUserConfig(), exec_command_password(), executeMetaCommand(), get_create_object_cmd(), get_next_possible_free_pg_type_oid(), getAdditionalACLs(), getDomainConstraints(), getPolicies(), getTableAttrs(), initAccount(), initBranch(), initCreateTables(), initGenerateDataServerSide(), initialize_data_directory(), initTeller(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtendedStats(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listLargeObjects(), listOneExtensionContents(), listOperatorClasses(), listOperatorFamilies(), listOpFamilyFunctions(), listOpFamilyOperators(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), main(), minimal_error_message(), parseAclItem(), permissionsList(), PQchangePassword(), printVerboseErrorMessages(), processExtensionTables(), runPgDump(), syntax_error(), and test_specific_config_settings().

◆ resetPQExpBuffer()

void resetPQExpBuffer ( PQExpBuffer  str)

Definition at line 146 of file pqexpbuffer.c.

147{
148 if (str)
149 {
150 if (str->data != oom_buffer)
151 {
152 str->len = 0;
153 str->data[0] = '\0';
154 }
155 else
156 {
157 /* try to reinitialize to valid state */
159 }
160 }
161}

References initPQExpBuffer(), oom_buffer, and str.

Referenced by cluster_conn_opts(), create_logical_replication_slots(), create_publication(), dequoteAclUserName(), describeOneTableDetails(), describeRoles(), do_edit(), dumpCompositeTypeColComments(), dumpDatabase(), dumpOpclass(), dumpOpfamily(), dumpRoleMembership(), dumpRoles(), dumpSequence(), dumpSequenceData(), dumpTableComment(), dumpTableData_insert(), dumpTableSchema(), dumpTableSecLabel(), dumpTrigger(), dumpTSConfig(), dumpUserConfig(), dumpUserMappings(), exec_command_edit(), exec_command_ef_ev(), exec_command_reset(), exec_command_watch(), ExecuteSimpleCommands(), expand_dbname_patterns(), expand_extension_name_patterns(), expand_foreign_server_name_patterns(), expand_schema_name_patterns(), expand_table_name_patterns(), expr_lex_one_word(), get_create_object_cmd(), get_parallel_object_list(), getNamespaces(), gets_fromFile(), getTableAttrs(), getTables(), initCreatePKeys(), MainLoop(), parseAclItem(), ParseScript(), pg_send_history(), PQcancelPoll(), pqGetErrorNotice3(), pqGets_internal(), prepare_btree_command(), prepare_heap_command(), prepare_vacuum_command(), printfPQExpBuffer(), printVerboseErrorMessages(), set_replication_progress(), StreamLogicalLog(), and vacuum_one_database().

◆ termPQExpBuffer()

void termPQExpBuffer ( PQExpBuffer  str)

Definition at line 129 of file pqexpbuffer.c.

130{
131 if (str->data != oom_buffer)
132 free(str->data);
133 /* just for luck, make the buffer validly empty. */
134 str->data = unconstify(char *, oom_buffer_ptr); /* see comment above */
135 str->maxlen = 0;
136 str->len = 0;
137}

References free, oom_buffer, oom_buffer_ptr, str, and unconstify.

Referenced by _printTocEntry(), _reconnectToDB(), add_tablespace_footer(), append_database_pattern(), append_relation_pattern_helper(), append_schema_pattern(), appendPsqlMetaConnect(), appendQualifiedRelation(), bootstrap_template1(), build_client_final_message(), build_client_first_message(), check_for_incompatible_polymorphics(), cluster_one_database(), compile_database_list(), compile_relation_list_one_db(), conninfo_uri_parse_options(), createPartitions(), describeAccessMethods(), describeAggregates(), describeConfigurationParameters(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describePublications(), DescribeQuery(), describeRoleGrants(), describeRoles(), describeSubscriptions(), describeTableDetails(), describeTablespaces(), describeTypes(), destroyPQExpBuffer(), do_copy(), evaluate_backtick(), exec_command_password(), executeMetaCommand(), expand_schema_name_patterns(), expand_table_name_patterns(), free_command(), freePGconn(), generate_old_dump(), GenerateRecoveryConfig(), get_db_conn(), get_parallel_object_list(), getParameterStatus(), helpSQL(), helpVariables(), indent_lines(), initCreatePKeys(), initCreateTables(), initGenerateDataServerSide(), initialize_data_directory(), initPopulateTable(), libpqrcv_get_conninfo(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtendedStats(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listLargeObjects(), listOneExtensionContents(), listOperatorClasses(), listOperatorFamilies(), listOpFamilyFunctions(), listOpFamilyOperators(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), main(), objectDescription(), old_9_6_invalidate_hash_indexes(), output_completion_banner(), ParseScript(), passwordFromFile(), patternToSQLRegex(), permissionsList(), pg_SASL_init(), PQchangePassword(), PQconndefaults(), PQconninfo(), PQconninfoParse(), pqGetErrorNotice3(), pqGetNegotiateProtocolVersion3(), PQresultVerboseErrorMessage(), process_backslash_command(), process_extension_updates(), processSQLNamePattern(), psql_scan_slash_option(), ReceiveTarFile(), run_reindex_command(), runInitSteps(), runPgDump(), slashUsage(), start_conn(), start_postmaster(), syntax_error(), test_specific_config_settings(), usage(), vacuum_one_database(), and validateSQLNamePattern().

Variable Documentation

◆ oom_buffer

const char oom_buffer[1] = ""
static

Definition at line 38 of file pqexpbuffer.c.

Referenced by markPQExpBufferBroken(), resetPQExpBuffer(), and termPQExpBuffer().

◆ oom_buffer_ptr

const char* const oom_buffer_ptr = oom_buffer
static

Definition at line 41 of file pqexpbuffer.c.

Referenced by initPQExpBuffer(), markPQExpBufferBroken(), and termPQExpBuffer().