From 4ff53269f024e7bd4b5b0958d6dd3dfc3dce685c Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sat, 9 Aug 2025 19:38:14 +0800 Subject: [PATCH] Warn when` xy_strdup()` called with NULL --- lib/xy.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/xy.h b/lib/xy.h index d44bc3b..c08f66b 100644 --- a/lib/xy.h +++ b/lib/xy.h @@ -287,6 +287,12 @@ xy_strjoin (unsigned int count, ...) static char * xy_strdup (const char *str) { + if (!str) + { + fprintf (stderr, "xy.h: xy_strdup() called with NULL!"); + return NULL; + } + size_t len = strlen (str); char *new = xy_malloc0 (len + 1); strcpy (new, str);