From 9ef17b7bd810cf46b9432345fa872b82d5e50d92 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Sun, 8 Sep 2024 13:28:20 +0200 Subject: Added some static assertion based sanity checks. Signed-off-by: Toni Uhlig --- nDPId.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nDPId.c b/nDPId.c index 8e1c6a8ff..ba997c25e 100644 --- a/nDPId.c +++ b/nDPId.c @@ -17,6 +17,9 @@ #include #include #include +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#include +#endif #include #include #include @@ -221,6 +224,10 @@ struct nDPId_flow_extended unsigned long long int total_l4_payload_len[FD_COUNT]; struct ndpi_proto detected_l7_protocol; }; +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +_Static_assert(offsetof(struct nDPId_flow_extended, flow_basic) == 0, + "Offset of flow_basic is not zero any more. nDPId won't work anymore w/o changing it's core!"); +#endif /* * Skipped flows need at least some information. @@ -229,6 +236,10 @@ struct nDPId_flow_skipped { struct nDPId_flow_basic flow_basic; // Do not move this element! }; +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +_Static_assert(offsetof(struct nDPId_flow_skipped, flow_basic) == 0, + "Offset of flow_basic is not zero any more. nDPId won't work anymore w/o changing it's core!"); +#endif /* * Structure which is important for the detection process. @@ -265,6 +276,10 @@ struct nDPId_flow } finished; }; }; +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +_Static_assert(offsetof(struct nDPId_flow, flow_extended) == 0, + "Offset of flow_extended is not zero any more. nDPId won't work anymore w/o changing it's core!"); +#endif struct nDPId_workflow { -- cgit v1.2.3