Commit 204e1b83 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

memory: squeal when there is something wrong, instead of stumbling on

When copying a string, source and destination may not be equal --
complain loudly when they are, instead of failing to free memory.

Also, instead of freeing the destination string and then allocating
it afresh, just reallocate it -- that should be slightly quicker.
No related merge requests found
Showing with 3 additions and 3 deletions
+3 -3
......@@ -378,10 +378,10 @@ char *mallocstrncpy(char *dest, const char *src, size_t n)
if (src == NULL)
src = "";
if (src != dest)
free(dest);
if (src == dest)
fprintf(stderr, "\r*** Copying a string to itself -- please report a bug ***");
dest = charalloc(n);
dest = charealloc(dest, n);
strncpy(dest, src, n);
return dest;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment