Prevent SANDBOX_VALUE_TO_BOOL() macro from double-evaluating its argument

This commit is contained in:
刘皓 2025-08-21 10:02:26 -04:00
parent 6f4ac73a43
commit a1c9ad01be
No known key found for this signature in database
GPG key ID: 7901753DB465B711

View file

@ -65,7 +65,11 @@
sb()._end_yield(); \
} while (0)
#define SANDBOX_VALUE_TO_BOOL(value) ((value) != SANDBOX_FALSE && (value) != SANDBOX_NIL)
#ifdef __GNUC__
# define SANDBOX_VALUE_TO_BOOL(value) ({ auto _value = (value); _value != SANDBOX_FALSE && _value != SANDBOX_NIL; })
#else
# define SANDBOX_VALUE_TO_BOOL(value) ([=]() { auto _value = (value); return _value != SANDBOX_FALSE && _value != SANDBOX_NIL; }())
#endif // __GNUC__
#define SANDBOX_BOOL_TO_VALUE(boolean) ((boolean) ? SANDBOX_TRUE : SANDBOX_FALSE)