Skip to content

Commit 641401c

Browse files
committed
regen/embed.pl: Improve error checking
This commit verifies that only one of the mutually exclusive argument modifiers, like NN, is present, and that NZ isn't used for a pointer argument.
1 parent ae0f6cd commit 641401c

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

regen/embed.pl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,30 @@ sub generate_proto_h {
247247
unless $has_mflag;
248248
}
249249
else {
250-
if ( $args_assert_line
251-
&& $arg =~ /\*/
252-
&& $arg !~ /\b(NN|NULLOK)\b/ )
253-
{
254-
warn "$func: $arg needs NN or NULLOK\n";
255-
++$unflagged_pointers;
256-
}
257-
258250
my $nn = ( $arg =~ s/\s*\bNN\b\s+// );
259251
my $nz = ( $arg =~ s/\s*\bNZ\b\s+// );
260252
my $nullok = ( $arg =~ s/\s*\bNULLOK\b\s+// );
261253
my $nocheck = ( $arg =~ s/\s*\bNOCHECK\b\s+// );
262254

255+
die_at_end ":$func: $arg Use only one of NN, NULLOK, and NZ"
256+
if 0 + $nn + $nz + $nullok > 1;
257+
258+
push( @nonnull, $n ) if $nn;
259+
260+
# A non-pointer shouldn't have a pointer-related modifier.
261+
# But typedefs may be pointers without our knowing it, so
262+
# we can't check for non-pointer issues. We can only
263+
# check for the case where the argument is definitely a
264+
# pointer.
265+
if ($args_assert_line && $arg =~ /\*/) {
266+
if ($nn + $nullok == 0) {
267+
warn "$func: $arg needs NN or NULLOK\n";
268+
++$unflagged_pointers;
269+
}
270+
271+
warn "$func: $arg should not have NZ\n" if $nz;
272+
}
273+
263274
push( @nonnull, $n ) if $nn;
264275

265276
# Make sure each arg has at least a type and a var name.

0 commit comments

Comments
 (0)