mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Make GetConfigOption/GetConfigOptionResetString return "" for NULL.
As per the preceding commit, GUC APIs generally expose NULL-valued string variables as empty strings. Extend that policy to GetConfigOption() and GetConfigOptionResetString(), eliminating a crash hazard for unwary callers, as well as a fundamental ambiguity in GetConfigOption()'s API. No back-patch, since this is an API change and conceivably somebody somewhere is depending on this corner case. Xing Guo, Aleksander Alekseev, Tom Lane Discussion: https://postgr.es/m/CACpMh+AyDx5YUpPaAgzVwC1d8zfOL4JoD-uyFDnNSa1z0EsDQQ@mail.gmail.com
This commit is contained in:
@ -4215,8 +4215,7 @@ SetConfigOption(const char *name, const char *value,
|
|||||||
/*
|
/*
|
||||||
* Fetch the current value of the option `name', as a string.
|
* Fetch the current value of the option `name', as a string.
|
||||||
*
|
*
|
||||||
* If the option doesn't exist, return NULL if missing_ok is true (NOTE that
|
* If the option doesn't exist, return NULL if missing_ok is true,
|
||||||
* this cannot be distinguished from a string variable with a NULL value!),
|
|
||||||
* otherwise throw an ereport and don't return.
|
* otherwise throw an ereport and don't return.
|
||||||
*
|
*
|
||||||
* If restrict_privileged is true, we also enforce that only superusers and
|
* If restrict_privileged is true, we also enforce that only superusers and
|
||||||
@ -4259,7 +4258,8 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
|
|||||||
return buffer;
|
return buffer;
|
||||||
|
|
||||||
case PGC_STRING:
|
case PGC_STRING:
|
||||||
return *((struct config_string *) record)->variable;
|
return *((struct config_string *) record)->variable ?
|
||||||
|
*((struct config_string *) record)->variable : "";
|
||||||
|
|
||||||
case PGC_ENUM:
|
case PGC_ENUM:
|
||||||
return config_enum_lookup_by_value((struct config_enum *) record,
|
return config_enum_lookup_by_value((struct config_enum *) record,
|
||||||
@ -4306,7 +4306,8 @@ GetConfigOptionResetString(const char *name)
|
|||||||
return buffer;
|
return buffer;
|
||||||
|
|
||||||
case PGC_STRING:
|
case PGC_STRING:
|
||||||
return ((struct config_string *) record)->reset_val;
|
return ((struct config_string *) record)->reset_val ?
|
||||||
|
((struct config_string *) record)->reset_val : "";
|
||||||
|
|
||||||
case PGC_ENUM:
|
case PGC_ENUM:
|
||||||
return config_enum_lookup_by_value((struct config_enum *) record,
|
return config_enum_lookup_by_value((struct config_enum *) record,
|
||||||
|
Reference in New Issue
Block a user