diff options
author | David Robillard <d@drobilla.net> | 2020-04-02 16:35:22 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-04-02 17:40:56 +0200 |
commit | 8c6f2c0d38fa0035a5990214d93bb9b766088a9f (patch) | |
tree | 9b1b31d8b2e4d95f5211d3a8173949a11cc1dcec | |
parent | 91e47ef4791092b428140540c45ac4a8ea5ff5d0 (diff) | |
download | pugl-8c6f2c0d38fa0035a5990214d93bb9b766088a9f.tar.gz pugl-8c6f2c0d38fa0035a5990214d93bb9b766088a9f.tar.bz2 pugl-8c6f2c0d38fa0035a5990214d93bb9b766088a9f.zip |
Make puglSetString() safe to call with equal source and destination
This is sometimes used by puglSetWindowTitle() using the existing title.
-rw-r--r-- | pugl/detail/implementation.c | 8 |
1 files changed, 5 insertions, 3 deletions
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 |