Fix -Wmaybe-uninitialized warning in js_binary_logic_slow#1530
Open
sdrsdr wants to merge 1 commit into
Open
Conversation
GCC (observed with 16.1) cannot prove that buf2 is initialized on the
BigInt shift path: js_bigint_get_si_sat(p2) is inlined and reads
buf2.tab via js_bigint_sign(), but GCC loses track of the preceding
js_bigint_set_short(&buf2, op2) store. The read is in fact always safe.
A declaration initializer (JSBigIntBuf buf2 = {0};) does not help because
the slow_big_int: label is reachable via goto, which jumps over the
initializer. Zero-initialize buf2 with memset() just after the label so it
runs on every entry path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix -Wmaybe-uninitialized warning in js_binary_logic_slow (quickjs.c).
GCC (seen with 16.1.1, Release/-O2) warns that buf2 may be used
uninitialized on the BigInt logic/shift path. js_bigint_get_si_sat(p2)
is inlined and reads buf2.tab via js_bigint_sign(), and GCC can't
correlate that with the earlier js_bigint_set_short(&buf2, op2) store.
The read is in fact always safe.
A declaration initializer (JSBigIntBuf buf2 = {0};) does not help,
because the slow_big_int: label is reached via goto, which jumps over
the initializer. The fix zero-initializes buf2 with memset() right
after the label so it runs on every entry path.
Verified on master with GCC 16.1.1: warning gone, tests.conf suite
passes (0/63 errors), api-test passes, and BigInt ops are correct
(123n<<4n=1968, -5n>>1n=-3, 6n&3n=2).
buf1 in the same function could be initialized the same way for
symmetry, though it does not currently trigger a warning. Happy to add
that if preferred.
Disclosure: prepared with AI assistance. I reviewed the code path,
reproduced the warning on master, verified the fix, and ran the test
suite myself.