Skip to content

Commit 9b5844b

Browse files
committed
Fix undefined behavior in JIT diagnostic logging
Replace left shift of potentially negative value with multiplication to avoid undefined behavior detected by UBSan. In update_branch_imm(), the immediate value (imm) is right-shifted by 2 and can be negative. The diagnostic logging attempted to restore the original value using left shift (imm << 2), which is undefined behavior when imm is negative.
1 parent 0f13d06 commit 9b5844b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static void update_branch_imm(struct jit_state *state,
594594
assert((imm & 3) == 0);
595595
uint32_t insn;
596596
imm >>= 2;
597-
rv_log_debug("JIT: Patching branch at offset=%u, imm=%d", offset, imm << 2);
597+
rv_log_debug("JIT: Patching branch at offset=%u, imm=%d", offset, imm * 4);
598598
#if defined(__APPLE__) && defined(__aarch64__)
599599
/* Must be in write mode to read/write MAP_JIT memory on Apple ARM64 */
600600
pthread_jit_write_protect_np(false);

0 commit comments

Comments
 (0)