From: Dietmar Maurer Date: Sat, 15 Mar 2014 09:24:02 +0000 (+0100) Subject: add compile time test for log struct size X-Git-Url: https://git.proxmox.com/?p=pve-firewall.git;a=commitdiff_plain;h=5b06fd6c0e9ce50c58cfb32f6820d1ebce5858c4;ds=inline add compile time test for log struct size The STATIC_ASSERT macro declares an external function (which is never used). The declaratin fails if the expression evaluates to false, because that would result in a negative array bound. --- diff --git a/src/pvefw-logger.c b/src/pvefw-logger.c index 31218a2..3a069f1 100644 --- a/src/pvefw-logger.c +++ b/src/pvefw-logger.c @@ -73,7 +73,7 @@ Example: #define PIDFILE "/var/run/pvefw-logger.pid" #define LQ_LEN 512 -#define LE_MAX (512 - 16) // try to fit into 512 bytes +#define LE_MAX (512 - 4) // try to fit into 512 bytes #define MAX_CHAIN_LEN 28 @@ -82,6 +82,11 @@ struct log_entry { char buf[LE_MAX]; }; +#define STATIC_ASSERT(cond) \ + extern void pve_static_assert(int test[(cond) ? 1 : -1]) + +STATIC_ASSERT(sizeof(struct log_entry) == 512); + int outfd = -1; gboolean terminate_threads = FALSE;