Add macro functions for checking unsigned wraps

This commit is contained in:
2025-08-04 20:30:30 +03:00
parent 0da77c00d6
commit deb4ec00f4
4 changed files with 67 additions and 10 deletions

View File

@@ -20,6 +20,9 @@
#define BH_PTR2INT(x) ((intptr_t)(x))
#define BH_INT2PTR(x) ((void*)((intptr_t)(x)))
#define BH_CHECK_UADD_WRAP(x, y, type) ((type)((x) + (y)) < (type)(y))
#define BH_CHECK_USUB_WRAP(x, y, type) ((type)((x) - (y)) > (type)(x))
#define BH_CHECK_UMUL_WRAP(x, y, type) ((x) > ((type)-1 / (y)))
typedef int (*BH_EqualCallback)(const void *, const void *);
typedef size_t (*BH_HashCallback)(const void *);