From ff4be24726c7f3feb9e7fff291ecee0b9aa7d0ae Mon Sep 17 00:00:00 2001 From: Marcin Kolny Date: Tue, 28 Mar 2023 05:18:39 +0100 Subject: [PATCH] Fix bh_assert for 64-bit platforms (#2071) In some cases, the memory address of some variables may have 4 least significant bytes set to zero. Because we cast the pointer to int, we look only at 4 least significant bytes; the assertion may fail because 4 least significant bytes are 0. Change bh_assert implementation to cast the assert expr to int64_t and it works well with 64-bit architectures. --- core/shared/utils/bh_assert.c | 2 +- core/shared/utils/bh_assert.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/shared/utils/bh_assert.c b/core/shared/utils/bh_assert.c index f341df4df..246c55d1b 100644 --- a/core/shared/utils/bh_assert.c +++ b/core/shared/utils/bh_assert.c @@ -6,7 +6,7 @@ #include "bh_assert.h" void -bh_assert_internal(int v, const char *file_name, int line_number, +bh_assert_internal(int64 v, const char *file_name, int line_number, const char *expr_string) { if (v) diff --git a/core/shared/utils/bh_assert.h b/core/shared/utils/bh_assert.h index 06f7f3b6c..b7c995af8 100644 --- a/core/shared/utils/bh_assert.h +++ b/core/shared/utils/bh_assert.h @@ -14,10 +14,10 @@ extern "C" { #if BH_DEBUG != 0 void -bh_assert_internal(int v, const char *file_name, int line_number, +bh_assert_internal(int64 v, const char *file_name, int line_number, const char *expr_string); #define bh_assert(expr) \ - bh_assert_internal((int)(uintptr_t)(expr), __FILE__, __LINE__, #expr) + bh_assert_internal((int64)(uintptr_t)(expr), __FILE__, __LINE__, #expr) #else #define bh_assert(expr) (void)0 #endif /* end of BH_DEBUG */