From 983a8446337abd80cce3883a864b82367b78d52f Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 30 Jul 2023 18:45:47 +0200 Subject: [PATCH] zustr2stp.h: Add ZUSTR2STP() macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's a wrapper around zustr2stp() that calls SIZEOF_ARRAY() internally. The function call is usually --in our code base, always-- called with an array as the second argument. For such an argument, one should call SIZEOF_ARRAY(). To avoid mistakes, and simplify usage, let's add this macro that does it internally. BTW, this macro doesn't have any issues of double evaluation, because sizeof() doesn't evaluate its argument (unless it's a VLA, but then the static_assert(3) within SIZEOF_ARRAY() makes sure VLAs are not allowed). Cc: Christian Göttsche Cc: Serge Hallyn Cc: Iker Pedrosa Signed-off-by: Alejandro Colomar --- lib/zustr2stp.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/zustr2stp.h b/lib/zustr2stp.h index 987a7ba8..7775fc6d 100644 --- a/lib/zustr2stp.h +++ b/lib/zustr2stp.h @@ -14,6 +14,10 @@ #include #include "mempcpy.h" +#include "sizeof.h" + + +#define ZUSTR2STP(dst, src) zustr2stp(dst, src, SIZEOF_ARRAY(src)) inline char *zustr2stp(char *restrict dst, const char *restrict src, size_t sz);