You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
1. Code example:
unsigned long dwMask = 0xFFFFFFFF;
dwMask >>= 1;
printf("Result: 0x%08X\n", dwMask);
2. The displayed result will be:
Result: 0xFFFFFFFF
3. The expected result is:
Result: 0x7FFFFFFF
It looks that the "unsigned long" variable is treated as a "signed long" type.
In the file "expression.c", the problem can be fixed by casting all shift
operators with "(unsigned long)":
/* evaluate an infix operator */
void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack
**StackTop, enum LexToken Op, struct Value *BottomValue, struct Value *TopValue)
{
// [...]
case TokenShiftLeftAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, (unsigned long) BottomInt << TopInt, FALSE); break;
case TokenShiftRightAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, (unsigned long) BottomInt >> TopInt, FALSE); break;
// [...]
case TokenShiftLeft: ResultInt = (unsigned long) BottomInt << TopInt; break;
case TokenShiftRight: ResultInt = (unsigned long) BottomInt >> TopInt; break;
// [...]
}
The above workaround works, but I agree that's not the best way to fix the
problem. It would be better to check the TopValue and BottomValue variable
types (signed/unsigned) and branch for the mathematical operation with the
appropriate type (signed/unsigned). I suspect that all the other mathematical
expressions are affected by this problem.
Original issue reported on code.google.com by [email protected] on 15 Dec 2014 at 7:29
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
[email protected]
on 15 Dec 2014 at 7:29The text was updated successfully, but these errors were encountered: