From c61b8d63121a906e20216bee927c6e3a48f5c6b7 Mon Sep 17 00:00:00 2001 From: Matthieu Baerts Date: Thu, 12 May 2022 18:57:38 +0200 Subject: [PATCH] api: force setting _GNU_SOURCE Without that, a warning is emitted when compiling libyaml with musl libc: api.c: In function 'yaml_strdup': api.c:66:27: warning: implicit declaration of function 'strdup'; did you mean 'strcmp'? [-Wimplicit-function-declaration] return (yaml_char_t *)strdup((char *)str); ^~~~~~ strcmp If the warning is ignored, a program using libyaml starts but crashes because strdup() is returning garbage: (gdb) b parser.c:1365 Breakpoint 11 at 0x43ecf4: file parser.c, line 1365. (gdb) run (...) Breakpoint 1, yaml_parser_append_tag_directive ( parser=parser@entry=0x7ffffff5f0, value=..., allow_duplicates=allow_duplicates@entry=1, mark=...) at parser.c:1365 1365 in parser.c (gdb) p copy $1 = { handle = 0xffffffffb8000fe0 , prefix = 0xffffffffb7f76fe0 } The solution is to follow strdup()'s manpage and define _GNU_SOURCE before including string.h. I guess when using other libc, it fallbacks to another version or maybe _GNU_SOURCE is set by default. Fixes: 625fcfe ("Refactor internal and external API.") Signed-off-by: Matthieu Baerts Change-Id: Ida011378a9d4da24735c4d4fdfdfb9d5f80ec970 --- src/api.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/api.c b/src/api.c index 16f88bd7..8f531ab8 100644 --- a/src/api.c +++ b/src/api.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE +#include #include "yaml_private.h"