From 4a95dbc597e3583ef32b0c2c7f7b10c0d208afcc Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 3 Feb 2021 21:06:58 -0600 Subject: [PATCH] Give an error if you try to define a macro to + or - on the command line. This affects command lines like: cmpl myprog.c cc=(-da=+) ... Previously, this would be accepted, but a was actually defined to 0 rather than +. Now, this gives an error, consistent with other tokens that are not supported in such definitions on the command line. (Perhaps we should support definitions using any tokens, but that would require bigger code changes.) This also cleans up some related code to avoid possible null-pointer dereferences. --- Scanner.pas | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index 691d34a..8316f83 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -3853,6 +3853,10 @@ repeat bp := pointer(ord4(macros) + hash(mp^.name)); mp^.next := bp^; bp^ := mp; + token.kind := intconst; {create the default value} + token.numString := nil; + token.class := intConstant; + token.ival := 1; if lch = '=' then begin NextCh; {record the value} token.numString := nil; @@ -3876,12 +3880,8 @@ repeat otherwise: ; end; {case} end {if} - else begin - token.kind := intconst; - token.numString := nil; - token.class := intConstant; - token.ival := 0; - end; {else} + else + Error(108); end {else if} else if lch in ['.','0'..'9'] then begin token.name := GetWord; @@ -3891,17 +3891,11 @@ repeat GetString else Error(108); - end {if} - else begin - token.kind := intconst; {create the default value} - token.numString := nil; - token.class := intConstant; - token.ival := 1; - end; {else} + end; {if} new(mp^.tokens); {add the value to the definition} with mp^.tokens^ do begin next := nil; - tokenString := nil; + tokenString := @''; expandEnabled := true; tokenStart := nil; tokenEnd := nil;