From 8c6f2c0d38fa0035a5990214d93bb9b766088a9f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 2 Apr 2020 16:35:22 +0200 Subject: Make puglSetString() safe to call with equal source and destination This is sometimes used by puglSetWindowTitle() using the existing title. --- pugl/detail/implementation.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'pugl/detail') diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c index 6bb019d..d17d14c 100644 --- a/pugl/detail/implementation.c +++ b/pugl/detail/implementation.c @@ -76,10 +76,12 @@ puglStrerror(const PuglStatus status) void puglSetString(char** dest, const char* string) { - const size_t len = strlen(string); + if (*dest != string) { + const size_t len = strlen(string); - *dest = (char*)realloc(*dest, len + 1); - strncpy(*dest, string, len + 1); + *dest = (char*)realloc(*dest, len + 1); + strncpy(*dest, string, len + 1); + } } void -- cgit v1.2.1