1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-28 11:44:57 +03:00

gen_guc_tables.pl: Validate required GUC fields before code generation

Previously, gen_guc_tables.pl would emit "Use of uninitialized value"
warnings if required fields were missing in guc_parameters.dat (for
example, when an integer or real GUC omitted the 'max' value).  The
resulting error messages were unclear and did not identify which GUC
entry was problematic.

Add explicit validation of required fields depending on the parameter
type, and fail with a clear and specific message such as:

    guc_parameters.dat:1909: error: entry "max_index_keys" of type "int" is missing required field "max"

No changes to generated guc_tables.c.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://www.postgresql.org/message-id/flat/CAEoWx2%3DoP4LgHi771_OKhPPUS7B-CTqCs%3D%3DuQcNXWrwBoAm5Vg%40mail.gmail.com
This commit is contained in:
Peter Eisentraut
2025-11-25 16:50:34 +01:00
parent 2256af4ba2
commit 7169c0b96b

View File

@@ -38,6 +38,52 @@ sub dquote
return q{"} . $s =~ s/"/\\"/gr . q{"};
}
sub validate_guc_entry
{
my ($entry) = @_;
my @required_common =
qw(name type context group short_desc variable boot_val);
my %required_by_type = (
int => [qw(min max)],
real => [qw(min max)],
enum => [qw(options)],
bool => [], # no extra required fields
string => [], # no extra required fields
);
for my $f (@required_common)
{
unless (defined $entry->{$f})
{
die sprintf(
qq{%s:%d: error: entry "%s" is missing required field "%s"\n},
$input_fname, $entry->{line_number},
$entry->{name} // '<unknown>', $f);
}
}
unless (exists $required_by_type{ $entry->{type} })
{
die sprintf(
qq{%s:%d: error: entry "%s" has unrecognized GUC type "%s"\n},
$input_fname, $entry->{line_number},
$entry->{name}, $entry->{type} // '<unknown>');
}
for my $f (@{ $required_by_type{ $entry->{type} } })
{
unless (defined $entry->{$f})
{
die sprintf(
qq{%s:%d: error: entry "%s" of type "%s" is missing required field "%s"\n},
$input_fname, $entry->{line_number}, $entry->{name},
$entry->{type}, $f);
}
}
}
# Print GUC table.
sub print_table
{
@@ -50,6 +96,8 @@ sub print_table
foreach my $entry (@{$parse})
{
validate_guc_entry($entry);
if (defined($prev_name) && lc($prev_name) ge lc($entry->{name}))
{
die sprintf(