From 194ed4e6e66cab28c3b5c0226cdfe6cc382d1f5a Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 24 Nov 2023 12:11:21 +0100 Subject: [PATCH] Macro SKIP_BACK now evaluates its argument only once. --- lib/birdlib.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/birdlib.h b/lib/birdlib.h index 9e60da39..9004704c 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -26,7 +26,11 @@ #define OFFSETOF(s, i) ((size_t) &((s *)0)->i) #endif -#define SKIP_BACK(s, i, p) ({ s *_ptr = ((s *)((char *)p - OFFSETOF(s, i))); SAME_TYPE(&_ptr->i, p); _ptr; }) +#define SKIP_BACK(s, i, p) ({ \ + typeof(p) _orig = p; \ + s *_ptr = ((s *)((char *)_orig - OFFSETOF(s, i))); \ + SAME_TYPE(&_ptr->i, _orig); \ + _ptr; }) #define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1)) #define CPU_STRUCT_ALIGN (MAX_(_Alignof(void*), _Alignof(u64))) #define BIRD_CPU_ALIGN(s) BIRD_ALIGN((s), CPU_STRUCT_ALIGN)