Skip to content

Fix runtime error: left shift of negative value #4957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2022

Conversation

batizdaniel
Copy link
Contributor

This patch fixes #4701

JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz [email protected]

This patch fixes jerryscript-project#4701

JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz [email protected]
@rerobika rerobika requested a review from dbatyai January 14, 2022 10:05
Copy link
Contributor

@ossy-szeged ossy-szeged left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://262.ecma-international.org/12.0/#sec-numeric-types-number-leftShift
The latest spec defines this operation: "Return the result of left shifting lnum by shiftCount bits. The mathematical value of the result is exactly representable as a 32-bit two's complement bit string."

With two's complement, the signed and unsigned left shift is exactly the same operation. To avoid the undefined behavior I think it is the right fix is doing unsigned left shift here and then interpreting the results as signed int. The PR exactly does it, so LGTM.

@dbatyai dbatyai merged commit 0ef5094 into jerryscript-project:master Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ubsan: jerryscript/jerry-core/vm/opcodes-ecma-bitwise.c:96:70: runtime error: left shift of negative value -1
3 participants