diff options
author | schnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-10-08 01:07:46 +0000 |
---|---|---|
committer | schnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-10-08 01:07:46 +0000 |
commit | d1332f3f8a5101d2c81f30e98e08fc34dbe036d1 (patch) | |
tree | 425d9d6bf69d93c151056e5cfa75828cbf22c852 /lib/sbin | |
parent | 36865d9cfefb819adaa0fab41f4340b5b35a2c59 (diff) |
The perl cpp does not handle empty macro arguments correctly. When
the last macro argument is empty, it thinks there is one argument too
few. That is, the following code
#define M2(a,b)
M2(x,)
leads to an error message stating that M2 was used with only a single
argument. This is wrong, as it is called with two arguments, where
the second argument is the empty string. After reading the GNU cpp
manual, I think that the ANSI standard requires that empty arguments
must be handled.
The problem is that the routine SplitArgs that decodes the macro
arguments cannot distinguish between an empty last argument and no
argument, as both are represented by an empty string. I change the
routine so that an empty string always means "empty argument". This
means that SplitArgs cannot be called any more if there are no
arguments -- but this does not matter. I place a corresponding if
statement around the call.
Empty macro arguments may cause problems on some system. A later
patch will produce warnings or errors for them.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4179 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/sbin')
-rwxr-xr-x | lib/sbin/cpp.pl | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/sbin/cpp.pl b/lib/sbin/cpp.pl index 4cfccb65..375abad0 100755 --- a/lib/sbin/cpp.pl +++ b/lib/sbin/cpp.pl @@ -806,6 +806,13 @@ sub ExpandMacro my $retcode = 0; my @arguments = &SplitArgs($args); + # SplitArgs returns one (empty) argument for macros without arguments, + # because it cannot distinguish between no arguments and one empty argument. + if (@{$defines{$macro}{"ARGS"}} == 0) + { + @arguments = (); + } + my $outstring = $defines{$macro}{"BODY"}; if($macro eq "__FILE__") @@ -949,11 +956,8 @@ sub SplitArgs push(@thistoken, $splitargs[$pos]); } - # Push any remaining token - if(@thistoken > 0) - { - push(@outargs, join("",@thistoken)); - } + # Push the remaining token + push(@outargs, join("",@thistoken)); return @outargs; } |