summaryrefslogtreecommitdiff
path: root/src/cmocka.c
diff options
context:
space:
mode:
authorAlois Klink <alois@aloisklink.com>2023-01-30 15:33:53 +0000
committerAndreas Schneider <asn@cryptomilk.org>2023-08-01 11:12:07 +0200
commit323e87dacc7b573a83200342dfb19e26ca720721 (patch)
tree59dd0669ffc48ab4912127484208d3f612ad54b7 /src/cmocka.c
parent6698413af74b2d953f1eda8fbb164e9cd4777287 (diff)
downloadcmocka-323e87dacc7b573a83200342dfb19e26ca720721.zip
cmocka-323e87dacc7b573a83200342dfb19e26ca720721.tar.gz
cmocka-323e87dacc7b573a83200342dfb19e26ca720721.tar.bz2
include: avoid GCC -Wuninitialized in assert_ptr*
In some cases, using the `assert_ptr_*()` macros causes GCC to throw a `-Wmaybe-unitialized` warning. For example: ```c void * my_ptr = malloc(1); // throws a `-Wmaybe-unitialized` warning assert_non_null(my_ptr); ``` This is because GCC assumes that a function accepting a `const void *` (or other constant pointer type) tries to read the pointer value. See [the `-Wmaybe-unitialized` docs][1]. We can tell GCC that the `_assert_ptr_equal`/`_assert_ptr_not_equal` functions only try to read the pointer address, not the pointer value, by using the [`access` function attribute][2]. Since CMocka supports C99, we can't use the ISO C23 attribute syntax. However, we can use the IBM/GCC/Clang `__attribute__` syntax hidden behind `#ifdef` guards, so that they're ignored on compilers that don't support `__attribute__`. [1]: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#Warning-Options [2]: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/cmocka.c')
-rw-r--r--src/cmocka.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/cmocka.c b/src/cmocka.c
index 211c315..43652d6 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -1365,6 +1365,7 @@ static bool int_values_not_equal_display_error(const intmax_t left,
/* Returns 1 if the specified pointers are equal. If the pointers are not equal
* an error is displayed and 0 is returned. */
+CMOCKA_NO_ACCESS_ATTRIBUTE
static bool ptr_values_equal_display_error(const void *left, const void *right)
{
const bool equal = left == right;
@@ -1376,6 +1377,7 @@ static bool ptr_values_equal_display_error(const void *left, const void *right)
/* Returns 1 if the specified pointers are equal. If the pointers are not equal
* an error is displayed and 0 is returned. */
+CMOCKA_NO_ACCESS_ATTRIBUTE
static bool ptr_values_not_equal_display_error(const void *left,
const void *right)
{