From bc13a79e197e191d2c6cb0ec76217e27e0932575 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Tue, 8 Dec 2020 09:50:47 +0000 Subject: perly.y: avoid <0 test on unsigned value Coverity CID 313707 Moving to a newer version of Bison has changed how the YYTRANSLATE() macro is defined: in particular it now has a <0 test, which Coverity is complaining about, since the arg is an unsigned value. This commit just casts the arg back to a signed value. In more detail: we formerly had: yytoken = YYTRANSLATE(NATIVE_TO_UNI(parser->yychar)); yychar is of type int, but NATIVE_TO_UNI returns a UV. So just cast the result back to an int: yytoken = YYTRANSLATE((int)NATIVE_TO_UNI(parser->yychar)); --- perly.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'perly.c') diff --git a/perly.c b/perly.c index 091371937d..ad79c49c49 100644 --- a/perly.c +++ b/perly.c @@ -297,7 +297,7 @@ Perl_yyparse (pTHX_ int gramtype) /* initialise state for this parse */ parser->yychar = gramtype; - yytoken = YYTRANSLATE(NATIVE_TO_UNI(parser->yychar)); + yytoken = YYTRANSLATE((int)NATIVE_TO_UNI(parser->yychar)); parser->yyerrstatus = 0; parser->yylen = 0; @@ -369,11 +369,11 @@ Perl_yyparse (pTHX_ int gramtype) * characters in that range, but all tokens it returns are * either 0, or above 255. There could be a problem if NULs * weren't 0, or were ever returned as raw chars by yylex() */ - yytoken = YYTRANSLATE(NATIVE_TO_UNI(parser->yychar)); + yytoken = YYTRANSLATE((int)NATIVE_TO_UNI(parser->yychar)); } /* make sure no-one's changed yychar since the last call to yylex */ - assert(yytoken == YYTRANSLATE(NATIVE_TO_UNI(parser->yychar))); + assert(yytoken == YYTRANSLATE((int)NATIVE_TO_UNI(parser->yychar))); YYDSYMPRINTF("lookahead token is", yytoken, &parser->yylval); -- cgit v1.2.1