Skip to content

bugfix: fix "attempt to shift left with overflow" exception - #5

Open
mwicat wants to merge 1 commit into
monomadic:masterfrom
mwicat:bugfix/fix-overflow-on-left-bitshift
Open

bugfix: fix "attempt to shift left with overflow" exception#5
mwicat wants to merge 1 commit into
monomadic:masterfrom
mwicat:bugfix/fix-overflow-on-left-bitshift

Conversation

@mwicat

@mwicat mwicat commented Aug 19, 2024

Copy link
Copy Markdown

I spotted this because it causes a few tests to fail.

The expression inside decode_truncated_block_i32 function that is used to get a bitmask for given bit_size will fail in case bit_size == 32. Expression 1<<32 will be evaluated first which will cause "attempt to shift left with overflow" exception since 1<<32 value does not fit in i32 type. Let's compute the bitmask incrementally from zero instead of backward arithmetic to avoid the type overflow.

…2 expression results in overflow for i32 type
@mwicat mwicat changed the title bugfix: fix "attempt to shift left with overflow" exception when 1<<32 expression results in overflow for i32 type bugfix: fix "attempt to shift left with overflow" exception Aug 19, 2024
@isolin

isolin commented Sep 10, 2024

Copy link
Copy Markdown

The same should be then used in read_packed_values_i32 as well. In fact, it would be the best to have a small function just doing (in pseudocode):

x == 32 ? -1 : (x == 31 ? 2147483647 : (1 << x) - 1)

If I counted well, it will be called 2x (incl. your previous patch).

Then, there is another call on the next line, which also needs handling for bit_size = 32:

x == 32 ? -2147483648 : 1 << (x - 1))

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.

2 participants