Skip to content

Commit 9ac3a19

Browse files
committed
Avoid undefined behavior.
1 parent 6e5b379 commit 9ac3a19

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libc-top-half/musl/src/string/strlen.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ size_t strlen(const char *s)
1616
#if defined(__wasm_simd128__) && defined(__wasilibc_simd_string)
1717
// strlen must stop as soon as it finds the terminator.
1818
// Aligning ensures loads beyond the terminator are safe.
19+
// Casting through uintptr_t makes this implementation-defined,
20+
// rather than undefined behavior.
1921
uintptr_t align = (uintptr_t)s % sizeof(v128_t);
20-
const v128_t *v = (v128_t *)(s - align);
22+
const v128_t *v = (v128_t *)((uintptr_t)s - align);
2123

2224
for (;;) {
2325
// Bitmask is slow on AArch64, all_true is much faster.

0 commit comments

Comments
 (0)