]> git.proxmox.com Git - pve-firewall.git/commitdiff
add compile time test for log struct size
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 15 Mar 2014 09:24:02 +0000 (10:24 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 15 Mar 2014 09:24:02 +0000 (10:24 +0100)
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.

src/pvefw-logger.c

index 31218a29f91d56d7d06bd59474e96532e857bc59..3a069f1e1c4c4f7e868a3a2fe7cba64cfb031860 100644 (file)
@@ -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;