From: Timo Sirainen Date: Thu, 13 Sep 2018 12:30:22 +0000 (+0300) Subject: lib: i_zero*() - Give compiler error if it's wrongly used on an array X-Git-Tag: 2.3.9~1397 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=151ad1bbcc6305643440254e15718a836ab2926e;p=thirdparty%2Fdovecot%2Fcore.git lib: i_zero*() - Give compiler error if it's wrongly used on an array --- diff --git a/src/lib/macros.h b/src/lib/macros.h index b12f3764cb..16c69b2f27 100644 --- a/src/lib/macros.h +++ b/src/lib/macros.h @@ -235,8 +235,10 @@ #endif /* Convenience wrappers for initializing a struct */ -#define i_zero(p) memset(p, 0, sizeof(*(p))) -#define i_zero_safe(p) safe_memset(p, 0, sizeof(*(p))) +#define i_zero(p) \ + memset(p, 0 + + COMPILE_ERROR_IF_TRUE(sizeof(p) > sizeof(void *)), sizeof(*(p))) +#define i_zero_safe(p) \ + safe_memset(p, 0 + + COMPILE_ERROR_IF_TRUE(sizeof(p) > sizeof(void *)), sizeof(*(p))) #define ST_CHANGED(st_a, st_b) \ ((st_a).st_mtime != (st_b).st_mtime || \