From df245f32ec7b87b3ca0c25fae1c219d7931da1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 27 Oct 2023 11:52:14 +0800 Subject: [PATCH] FFlist: add `FF_LIST_GET` this macro can be safer to use than `ffListGet` because it detects wrong type convertion --- src/util/FFlist.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util/FFlist.h b/src/util/FFlist.h index 276a65e13..0f71b1bff 100644 --- a/src/util/FFlist.h +++ b/src/util/FFlist.h @@ -103,4 +103,11 @@ static inline void ffListClear(FFlist* list) #define FF_LIST_AUTO_DESTROY FFlist __attribute__((__cleanup__(ffListDestroy))) +#define FF_LIST_GET(itemType, listVar, index) \ + ({ \ + assert(sizeof(itemType) == (listVar).elementSize); \ + assert((listVar).capacity > (index)); \ + (itemType*)(listVar).data + (index); \ + }) + #endif