From e84c8dee1a033627e4a5f7d63ae6a9dfcdcc77dd Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Fri, 17 May 2024 10:24:33 +0200 Subject: [PATCH] BUILD: log: get rid of non-portable strnlen() func In c614fd3b9 ("MINOR: log: add +cbor encoding option"), I wrongly used strnlen() without noticing that the function is not portable (requires _POSIX_C_SOURCE >= 2008) and that it was the first occurrence in the entire project. In fact it is not a hard requirement since it's a pretty simple function. Thus to restore build compatibility with minimal/older build systems, let's actually get rid of it and use an equivalent portable code where needed (we cannot simply rely on strlen() because the string might not be NULL terminated, we must take upstream len into account). No backport needed (unless c614fd3b9 gets backported) --- src/log.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/log.c b/src/log.c index 3d66e7a8c..2bb77c955 100644 --- a/src/log.c +++ b/src/log.c @@ -2235,7 +2235,15 @@ static inline char *_lf_text_len(char *dst, const char *src, * indefinite length text in cbor, because indefinite-length text * has to be made of multiple chunks of known size as per RFC8949... */ - len = strnlen(src, len); + { + int _len; + + /* strnlen(src, len) portable equivalent: */ + for (_len = 0; _len < len && src[_len]; _len++) + ; + + len = _len; + } ret = cbor_encode_text(&ctx->encode.cbor, dst, dst + size, src, len); if (ret == NULL)