Skip to content

Commit ff4be24

Browse files
authored
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.
1 parent 61369d4 commit ff4be24

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

core/shared/utils/bh_assert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "bh_assert.h"
77

88
void
9-
bh_assert_internal(int v, const char *file_name, int line_number,
9+
bh_assert_internal(int64 v, const char *file_name, int line_number,
1010
const char *expr_string)
1111
{
1212
if (v)

core/shared/utils/bh_assert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ extern "C" {
1414

1515
#if BH_DEBUG != 0
1616
void
17-
bh_assert_internal(int v, const char *file_name, int line_number,
17+
bh_assert_internal(int64 v, const char *file_name, int line_number,
1818
const char *expr_string);
1919
#define bh_assert(expr) \
20-
bh_assert_internal((int)(uintptr_t)(expr), __FILE__, __LINE__, #expr)
20+
bh_assert_internal((int64)(uintptr_t)(expr), __FILE__, __LINE__, #expr)
2121
#else
2222
#define bh_assert(expr) (void)0
2323
#endif /* end of BH_DEBUG */

0 commit comments

Comments
 (0)