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.
This commit is contained in:
Marcin Kolny 2023-03-28 05:18:39 +01:00 committed by GitHub
parent 61369d48fd
commit ff4be24726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -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)

View File

@ -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 */