From b83ed7b17bfdfe06ff083817f5e79a09cd8220ad Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 12 Oct 2016 20:36:03 -0500 Subject: [PATCH] Do not erroneously treat integer constant expressions of type unsigned int as signed in certain contexts. Unsigned constants in the range 0x8000-0xFFFF were erroneously being treated like negative signed values in some contexts, including in array declarators and in the case labels of switch statements where the expression switched over has type long or unsigned long. This could lead to bogus compile errors for array declarations and typedefs such as the following: typedef char foo[0x8000]; It could also lead to cases in switch statements not being properly matched, as in the following program: #include int main(void) { long i = 0xFF00; switch (i) { case 0xFF00: puts("good"); break; default: puts("bad"); } } --- Expression.pas | 1 + 1 file changed, 1 insertion(+) diff --git a/Expression.pas b/Expression.pas index 055ebed..845e16c 100644 --- a/Expression.pas +++ b/Expression.pas @@ -3682,6 +3682,7 @@ else begin {record the expression for an initialize end {else if} else if tree^.token.kind = uintconst then begin expressionValue := tree^.token.ival; + expressionValue := expressionValue & $0000FFFF; expressionType := uwordPtr; isConstant := true; end {else if}