Warn when xy_strdup() called with NULL

This commit is contained in:
Aoran Zeng 2025-08-09 19:38:14 +08:00
parent ca6498b547
commit 4ff53269f0
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98

View File

@ -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);