summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlois Klink <alois@aloisklink.com>2022-12-30 11:24:28 +0000
committerAndreas Schneider <asn@cryptomilk.org>2023-01-29 10:35:41 +0100
commite99e764e59214e962a317e1eb9118fa5641d0661 (patch)
tree9b64299f6161f92a14c8168b1db5b44cc15ee737
parent0acfe428ed3e580a391678337bd45d773de92dc6 (diff)
downloadcmocka-e99e764e59214e962a317e1eb9118fa5641d0661.zip
cmocka-e99e764e59214e962a317e1eb9118fa5641d0661.tar.gz
cmocka-e99e764e59214e962a317e1eb9118fa5641d0661.tar.bz2
include: Add cast_int_to_cmocka_value() macro
This macro is used to cast data as an integer to a `CMockaValueData`. For backwards compatibility reasons, this explicitly casts to `uintmax_t`, just like the `cast_to_uintmax_type()` macro. For most compilers, this will supress warnings about passing float/intmax_t to this macro. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/cmocka.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/cmocka.h b/include/cmocka.h
index 0127df0..d96ea82 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -72,6 +72,19 @@ int __stdcall IsDebuggerPresent();
#define cast_ptr_to_uintmax_type(value) \
cast_to_uintmax_type(cast_to_uintptr_type(value))
+/**
+ * Perform a cast from an integer to CMockaValueData.
+ *
+ * For backwards compatibility reasons, this explicitly casts to `uintmax_t`.
+ * For most compilers, this will supress warnings about passing float/intmax_t
+ * to this macro.
+ */
+#define cast_int_to_cmocka_value(value) \
+ (CMockaValueData) \
+ { \
+ .uint_val = (uintmax_t)(value) \
+ }
+
/* GCC have printf type attribute check. */
#ifdef __GNUC__
#define CMOCKA_PRINTF_ATTRIBUTE(a,b) \