mirror of git://git.sv.gnu.org/nano.git
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.
This commit is contained in:
parent
d865d7ac8f
commit
204e1b8353
|
@ -378,10 +378,10 @@ char *mallocstrncpy(char *dest, const char *src, size_t n)
|
||||||
if (src == NULL)
|
if (src == NULL)
|
||||||
src = "";
|
src = "";
|
||||||
|
|
||||||
if (src != dest)
|
if (src == dest)
|
||||||
free(dest);
|
fprintf(stderr, "\r*** Copying a string to itself -- please report a bug ***");
|
||||||
|
|
||||||
dest = charalloc(n);
|
dest = charealloc(dest, n);
|
||||||
strncpy(dest, src, n);
|
strncpy(dest, src, n);
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
|
|
Loading…
Reference in New Issue