Skip to content

Commit b4e8fcb

Browse files
committed
Avoid UB.
1 parent 14b98a5 commit b4e8fcb

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

sqlite3/libc/string.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <stdint.h>
77
#include <wasm_simd128.h>
8-
#include <__macro_PAGESIZE.h>
98

109
#ifdef __cplusplus
1110
extern "C" {
@@ -244,16 +243,16 @@ char *strrchr(const char *s, int c) {
244243
// http://0x80.pl/notesen/2018-10-18-simd-byte-lookup.html
245244

246245
typedef struct {
247-
__u8x16 l;
248-
__u8x16 h;
246+
__u8x16 lo;
247+
__u8x16 hi;
249248
} __wasm_v128_bitmap256_t;
250249

251250
__attribute__((always_inline))
252251
static void __wasm_v128_setbit(__wasm_v128_bitmap256_t *bitmap, int i) {
253252
uint8_t hi_nibble = (uint8_t)i >> 4;
254253
uint8_t lo_nibble = (uint8_t)i & 0xf;
255-
bitmap->l[lo_nibble] |= 1 << (hi_nibble - 0);
256-
bitmap->h[lo_nibble] |= 1 << (hi_nibble - 8);
254+
bitmap->lo[lo_nibble] |= (uint8_t)((uint32_t)1 << (hi_nibble - 0));
255+
bitmap->hi[lo_nibble] |= (uint8_t)((uint32_t)1 << (hi_nibble - 8));
257256
}
258257

259258
#ifndef __wasm_relaxed_simd__
@@ -272,11 +271,10 @@ static v128_t __wasm_v128_chkbits(__wasm_v128_bitmap256_t bitmap, v128_t v) {
272271
v128_t indices_0_7 = v & wasm_u8x16_const_splat(0x8f);
273272
v128_t indices_8_15 = indices_0_7 ^ wasm_u8x16_const_splat(0x80);
274273

275-
v128_t row_0_7 = wasm_i8x16_swizzle(bitmap.l, indices_0_7);
276-
v128_t row_8_15 = wasm_i8x16_swizzle(bitmap.h, indices_8_15);
274+
v128_t row_0_7 = wasm_i8x16_swizzle(bitmap.lo, indices_0_7);
275+
v128_t row_8_15 = wasm_i8x16_swizzle(bitmap.hi, indices_8_15);
277276

278277
v128_t bitsets = row_0_7 | row_8_15;
279-
280278
return wasm_i8x16_eq(bitsets & bitmask, bitmask);
281279
}
282280

0 commit comments

Comments
 (0)