Skip to content

Commit 7666e73

Browse files
committed
Throw an error if a DATA() line contains wrong # of attributes.
David Christensen, reviewed by Dagfinn Ilmari Mannsåker Discussion: http://postgr.es/m/20170215154018.fs5vwtqhp5d2sifs@veeddeux.attlocal.net
1 parent ccce90b commit 7666e73

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/backend/catalog/Catalog.pm

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ sub Catalogs
4646

4747
open(INPUT_FILE, '<', $input_file) || die "$input_file: $!";
4848

49+
my ($filename) = ($input_file =~ m/(\w+)\.h$/);
50+
my $natts_pat = "Natts_$filename";
51+
4952
# Scan the input file.
5053
while (<INPUT_FILE>)
5154
{
@@ -70,8 +73,15 @@ sub Catalogs
7073
s/\s+/ /g;
7174

7275
# Push the data into the appropriate data structure.
73-
if (/^DATA\(insert(\s+OID\s+=\s+(\d+))?\s+\(\s*(.*)\s*\)\s*\)$/)
76+
if (/$natts_pat\s+(\d+)/)
77+
{
78+
$catalog{natts} = $1;
79+
}
80+
elsif (/^DATA\(insert(\s+OID\s+=\s+(\d+))?\s+\(\s*(.*)\s*\)\s*\)$/)
7481
{
82+
check_natts($filename, $catalog{natts}, $3,
83+
$input_file, INPUT_FILE->input_line_number);
84+
7585
push @{ $catalog{data} }, { oid => $2, bki_values => $3 };
7686
}
7787
elsif (/^DESCR\(\"(.*)\"\)$/)
@@ -216,4 +226,20 @@ sub RenameTempFile
216226
rename($temp_name, $final_name) || die "rename: $temp_name: $!";
217227
}
218228

229+
# verify the number of fields in the passed-in bki structure
230+
sub check_natts
231+
{
232+
my ($catname, $natts, $bki_val, $file, $line) = @_;
233+
die "Could not find definition for Natts_${catname} before start of DATA() in $file\n"
234+
unless defined $natts;
235+
236+
# we're working with a copy and need to count the fields only, so collapse
237+
$bki_val =~ s/"[^"]*?"/xxx/g;
238+
my @atts = split /\s+/, $bki_val;
239+
240+
die sprintf
241+
"Wrong number of attributes in DATA() entry at %s:%d (expected %d but got %d)\n",
242+
$file, $line, $natts, scalar @atts
243+
unless $natts == @atts;
244+
}
219245
1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy