Skip to content

Conversation

@GHamrouni
Copy link

@GHamrouni GHamrouni commented Dec 23, 2025

The code previously called abs() on the result of an unsigned subtraction (uint32_t).
While the code relied on underflow and implicit casting to int to function, Clang flags this as having no effect (or undefined behavior).

Compiler Error:

gcc -Wall -g -MMD -Werror -D_GNU_SOURCE -fno-math-errno -fno-trapping-math -Os -c -o mquickjs.o mquickjs.c
mquickjs.c:1476:17: error: taking the absolute value of unsigned type 'uint32_t' (aka 'unsigned int') has no effect [-Werror,-Wabsolute-value]
 1476 |             d = abs(ce1->str_pos[pos_type] - pos);
      |                 ^
mquickjs.c:1476:17: note: remove the call to 'abs' since unsigned values cannot be negative
 1476 |             d = abs(ce1->str_pos[pos_type] - pos);
      |                 ^~~
1 error generated.
make: *** [mquickjs.o] Error 1

Resolution: Replaced the abs() call with a manual conditional subtraction to correctly calculate the distance between the two unsigned positions without relying on implicit casts or underflow.

@GHamrouni GHamrouni changed the title This patch fixes a build failure on Apple Clang 17.0.0 related to the distance calculation in js_string_convert_pos Fix a build failure on Apple Clang 17.0.0 related to the distance calculation in js_string_convert_pos Dec 23, 2025
@creationix creationix mentioned this pull request Dec 24, 2025
@bellard
Copy link
Owner

bellard commented Dec 24, 2025

already fixed

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