-
Notifications
You must be signed in to change notification settings - Fork 949
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
bf_set_ui when LIMB_BITS == 32 and shift = 0 depends on undefined behavior #131
Comments
Note that the above ret depends on the compiler and the compiler flags. A minimum repro to this undefined behavior: #define LIMB_BITS 32
#include <stdio.h>
#include <stdint.h>
uint32_t opaque(uint32_t x) {
return x == 0x3;
}
int main() {
uint32_t temp = 7;
uint32_t x = 0x8b0a00a4;
uint32_t k = LIMB_BITS - opaque(x) * LIMB_BITS;
temp = temp >> k;
printf("%d\n", k); // 32
printf("%d\n", temp);
printf("%d\n", temp>>32);
} On my system, |
ulan
added a commit
to ulan/javy
that referenced
this issue
Dec 1, 2023
As reported upstream in bellard/quickjs#131: shifting by `(LIMB_BITS - shift)` when `LIMB_BITS == 32` and `shift == 0` produces wrong results on 32-bit targets. This fix replaces all occurences of `(LIMB_BITS - shift)` with calls to the existing helpers: `shld()` and `shrd`, which are moved to the beginning of the file so that they are defined before their new usages. The helpers properly handle the cases when `shift` is zero. Fixes issue 556
ulan
added a commit
to ulan/javy
that referenced
this issue
Dec 1, 2023
As reported upstream in bellard/quickjs#131: shifting by `(LIMB_BITS - shift)` when `LIMB_BITS == 32` and `shift == 0` produces wrong results on 32-bit targets. This fix replaces all occurences of `(LIMB_BITS - shift)` with calls to the existing helpers: `shld()` and `shrd`, which are moved to the beginning of the file so that they are defined before their new usages. The helpers properly handle the cases when `shift` is zero. Fixes issue 556
same as #133 |
saghul
pushed a commit
to quickjs-ng/quickjs
that referenced
this issue
Dec 2, 2023
saghul
pushed a commit
to quickjs-ng/quickjs
that referenced
this issue
Dec 2, 2023
GerHobbelt
pushed a commit
to GerHobbelt/quickjs
that referenced
this issue
Jun 21, 2024
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2. - [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md) - [Commits](isaacs/minimatch@v3.0.4...v3.1.2) --- updated-dependencies: - dependency-name: minimatch dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
bluesky950520
pushed a commit
to bluesky950520/quickjs
that referenced
this issue
Mar 14, 2025
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
This expression in libbf.c, function
bf_set_ui
, whenLIMB_BITS == 32
andshift = 0
:becomes
And
a0
isuint32_t
, according to C99 and C17 spec (for bitwise shift):So shifting it for 32 bit is an undefined behavior, and it did produce wrong result in our JS-on-Wasm runtime based on quickjs.
A quick snippet to repro:
The text was updated successfully, but these errors were encountered: