#define CMSG_BUFFER_TYPE(x) union { uint8_t align_check[(size) >= CMSG_SPACE(0) && (size) == CMSG_ALIGN(size) ? 1 : -1]; }
#define SD_ID128_MAKE(...) ((const sd_id128) {})
+/* sizeof() does not evaluate its argument, so *ptr inside sizeof() is not a real dereference.
+ * The SIZEOF() macro is an alias for sizeof() that hides the argument from coccinelle to avoid
+ * false positives from check-pointer-deref.cocci. See assert-fundamental.h for the definition. */
+#define SIZEOF(x) 8
+
/* Work around a bug in zlib.h parsing on Fedora (and possibly others)
* See: https://github.com/coccinelle/coccinelle/issues/413 */
#define Z_EXPORT
* the coccinelle check-pointer-deref warning for parameters that are safely handled before any
* dereference (e.g. passed to a NULL-safe helper like iovec_is_set()). */
#define POINTER_MAY_BE_NULL(ptr) ({ (void) (ptr); })
+
+/* sizeof() does not evaluate its argument - it is a compile-time constant expression - so *ptr
+ * inside sizeof() is not a real dereference. However, coccinelle cannot distinguish this from an
+ * actual dereference, and when sizeof(*ptr) appears in a variable initializer the assert(ptr) that
+ * follows cannot come first (declarations must precede statements). Use this macro in place
+ * of sizeof() to avoid the false positive - coccinelle sees SIZEOF() as a function call (via
+ * parsing_hacks.h) and never looks inside the argument. */
+#define SIZEOF(x) sizeof(x)
}
static int tpm2_marshal_private(const TPM2B_PRIVATE *private, void **ret, size_t *ret_size) {
- size_t max_size = sizeof(*private), blob_size = 0;
+ size_t max_size = SIZEOF(*private), blob_size = 0;
_cleanup_free_ void *blob = NULL;
TSS2_RC rc;
}
int tpm2_marshal_public(const TPM2B_PUBLIC *public, void **ret, size_t *ret_size) {
- size_t max_size = sizeof(*public), blob_size = 0;
+ size_t max_size = SIZEOF(*public), blob_size = 0;
_cleanup_free_ void *blob = NULL;
TSS2_RC rc;
}
int tpm2_marshal_nv_public(const TPM2B_NV_PUBLIC *nv_public, void **ret, size_t *ret_size) {
- size_t max_size = sizeof(*nv_public), blob_size = 0;
+ size_t max_size = SIZEOF(*nv_public), blob_size = 0;
_cleanup_free_ void *blob = NULL;
TSS2_RC rc;