Skip to content

Fix -Wmaybe-uninitialized warning in js_binary_logic_slow#1530

Open
sdrsdr wants to merge 1 commit into
quickjs-ng:masterfrom
sdrsdr:fix/bigint-maybe-uninitialized-warning
Open

Fix -Wmaybe-uninitialized warning in js_binary_logic_slow#1530
sdrsdr wants to merge 1 commit into
quickjs-ng:masterfrom
sdrsdr:fix/bigint-maybe-uninitialized-warning

Conversation

@sdrsdr

@sdrsdr sdrsdr commented Jun 10, 2026

Copy link
Copy Markdown

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.

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.
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.

1 participant