@@ -875,7 +875,8 @@ PQconndefaults(void)
875875 connOptions = conninfo_init (& errorBuf );
876876 if (connOptions != NULL )
877877 {
878- if (!conninfo_add_defaults (connOptions , & errorBuf ))
878+ /* pass NULL errorBuf to ignore errors */
879+ if (!conninfo_add_defaults (connOptions , NULL ))
879880 {
880881 PQconninfoFree (connOptions );
881882 connOptions = NULL ;
@@ -4412,9 +4413,10 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
44124413 *
44134414 * Defaults are obtained from a service file, environment variables, etc.
44144415 *
4415- * Returns TRUE if successful, otherwise FALSE; errorMessage is filled in
4416- * upon failure. Note that failure to locate a default value is not an
4417- * error condition here --- we just leave the option's value as NULL.
4416+ * Returns TRUE if successful, otherwise FALSE; errorMessage, if supplied,
4417+ * is filled in upon failure. Note that failure to locate a default value
4418+ * is not an error condition here --- we just leave the option's value as
4419+ * NULL.
44184420 */
44194421static bool
44204422conninfo_add_defaults (PQconninfoOption * options , PQExpBuffer errorMessage )
@@ -4424,9 +4426,10 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
44244426
44254427 /*
44264428 * If there's a service spec, use it to obtain any not-explicitly-given
4427- * parameters.
4429+ * parameters. Ignore error if no error message buffer is passed
4430+ * because there is no way to pass back the failure message.
44284431 */
4429- if (parseServiceInfo (options , errorMessage ) != 0 )
4432+ if (parseServiceInfo (options , errorMessage ) != 0 && errorMessage )
44304433 return false;
44314434
44324435 /*
@@ -4448,8 +4451,9 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
44484451 option -> val = strdup (tmp );
44494452 if (!option -> val )
44504453 {
4451- printfPQExpBuffer (errorMessage ,
4452- libpq_gettext ("out of memory\n" ));
4454+ if (errorMessage )
4455+ printfPQExpBuffer (errorMessage ,
4456+ libpq_gettext ("out of memory\n" ));
44534457 return false;
44544458 }
44554459 continue ;
@@ -4465,8 +4469,9 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
44654469 option -> val = strdup (option -> compiled );
44664470 if (!option -> val )
44674471 {
4468- printfPQExpBuffer (errorMessage ,
4469- libpq_gettext ("out of memory\n" ));
4472+ if (errorMessage )
4473+ printfPQExpBuffer (errorMessage ,
4474+ libpq_gettext ("out of memory\n" ));
44704475 return false;
44714476 }
44724477 continue ;
@@ -4477,7 +4482,7 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
44774482 */
44784483 if (strcmp (option -> keyword , "user" ) == 0 )
44794484 {
4480- option -> val = pg_fe_getauthname (errorMessage );
4485+ option -> val = pg_fe_getauthname ();
44814486 continue ;
44824487 }
44834488 }
0 commit comments