From aca71566249cd13f506b70f88457eaa8efc5b795 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Mon, 6 Apr 2015 11:38:35 +0200 Subject: Detect (and reject with an error) preprocessing numbers that are not valid integer or floating constants. --- cparser/Lexer.mll | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'cparser') diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll index 13c1248b..82e6589c 100644 --- a/cparser/Lexer.mll +++ b/cparser/Lexer.mll @@ -233,6 +233,11 @@ let hexadecimal_floating_constant = | hexadecimal_prefix (hexadecimal_digit_sequence as intpart) binary_exponent_part floating_suffix? +(* Preprocessing numbers *) +let preprocessing_number = + '.'? ['0'-'9'] + (['0'-'9' 'A'-'Z' 'a'-'z' '_' '.'] | ['e' 'E' 'p' 'P']['+' '-'])* + (* Character and string constants *) let simple_escape_sequence = '\\' ( ['\'' '\"' '?' '\\' 'a' 'b' 'e' 'f' 'n' 'r' 't' 'v'] as c) @@ -273,6 +278,8 @@ rule initial = parse | None -> None | Some c -> Some (String.make 1 c) }, currentLoc lexbuf)} + | preprocessing_number as s { error lexbuf "invalid numerical constant '%s'@ These characters form a preprocessor number, but not a constant" s; + CONSTANT (Cabs.CONST_INT "0", currentLoc lexbuf) } | "'" { let l = char_literal [] lexbuf in CONSTANT (Cabs.CONST_CHAR(false, l), currentLoc lexbuf) } -- cgit