diff options
Diffstat (limited to 'src/internal.c')
-rw-r--r-- | src/internal.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/internal.c b/src/internal.c index 2da5e9e..c607fa7 100644 --- a/src/internal.c +++ b/src/internal.c @@ -47,11 +47,14 @@ puglSetBlob(PuglBlob* const dest, const void* const data, const size_t len) void puglSetString(char** dest, const char* string) { - if (*dest != string) { - const size_t len = strlen(string); + const size_t len = string ? strlen(string) : 0U; - *dest = (char*)realloc(*dest, len + 1); - strncpy(*dest, string, len + 1); + if (!len) { + free(*dest); + *dest = NULL; + } else { + *dest = (char*)realloc(*dest, len + 1U); + strncpy(*dest, string, len + 1U); } } |