Skip to content

Fix undefined behaviour in bitops unit test#1786

Merged
zuiderkwast merged 1 commit into
valkey-io:unstablefrom
zuiderkwast:ubsan-bitops-unit-test
Feb 26, 2025
Merged

Fix undefined behaviour in bitops unit test#1786
zuiderkwast merged 1 commit into
valkey-io:unstablefrom
zuiderkwast:ubsan-bitops-unit-test

Conversation

@zuiderkwast

Copy link
Copy Markdown
Contributor

The unit test was added in #1741. It fails when compiled with UBSAN. Using a local array like char buf[size] is undefined behaviour when size == 0. This fix just makes it size 1 in this case.

The failure I get locally:

unit/test_bitops.c:28:13: runtime error: variable length array bound evaluates to non-positive value 0

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>

@rjd15372 rjd15372 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@zuiderkwast zuiderkwast merged commit 7db01d8 into valkey-io:unstable Feb 26, 2025
@zuiderkwast zuiderkwast deleted the ubsan-bitops-unit-test branch February 26, 2025 18:01
@codecov

codecov Bot commented Feb 26, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.02%. Comparing base (79d5047) to head (81ffec6).
Report is 2 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1786      +/-   ##
============================================
- Coverage     71.17%   71.02%   -0.15%     
============================================
  Files           123      123              
  Lines         65641    65641              
============================================
- Hits          46720    46622      -98     
- Misses        18921    19019      +98     

see 8 files with indirect coverage changes

zuiderkwast added a commit that referenced this pull request Mar 18, 2025
The unit test was added in #1741. It fails when compiled with UBSAN.
Using a local array like `char buf[size]` is undefined behaviour when
`size == 0`. This fix just makes it size 1 in this case.

The failure I got locally:

unit/test_bitops.c:28:13: runtime error: variable length array bound
evaluates to non-positive value 0

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
xbasel pushed a commit to xbasel/valkey that referenced this pull request Mar 27, 2025
The unit test was added in valkey-io#1741. It fails when compiled with UBSAN.
Using a local array like `char buf[size]` is undefined behaviour when
`size == 0`. This fix just makes it size 1 in this case.

The failure I got locally:

unit/test_bitops.c:28:13: runtime error: variable length array bound
evaluates to non-positive value 0

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
xbasel pushed a commit to xbasel/valkey that referenced this pull request Mar 27, 2025
The unit test was added in valkey-io#1741. It fails when compiled with UBSAN.
Using a local array like `char buf[size]` is undefined behaviour when
`size == 0`. This fix just makes it size 1 in this case.

The failure I got locally:

unit/test_bitops.c:28:13: runtime error: variable length array bound
evaluates to non-positive value 0

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
murphyjacob4 pushed a commit to enjoy-binbin/valkey that referenced this pull request Apr 13, 2025
The unit test was added in valkey-io#1741. It fails when compiled with UBSAN.
Using a local array like `char buf[size]` is undefined behaviour when
`size == 0`. This fix just makes it size 1 in this case.

The failure I got locally:

unit/test_bitops.c:28:13: runtime error: variable length array bound
evaluates to non-positive value 0

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
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.

3 participants