commit 46566572d60332406d8c8c2e6111c3192c3412df
parent b4a5fac744cac7f8da2f97d26a23a31d0502dcce
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 14 Oct 2019 19:40:06 +0200
utils: don't accept NULL for the string to be copied
This should not occur, so crash when it does happen.
Diffstat:
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/utils.c b/src/utils.c
@@ -316,9 +316,6 @@ void *nrealloc(void *ptr, size_t howmuch)
* freeing the destination. Usage: "dest = mallocstrncpy(dest, src, n);". */
char *mallocstrncpy(char *dest, const char *src, size_t n)
{
- if (src == NULL)
- src = "";
-
dest = charealloc(dest, n);
strncpy(dest, src, n);
@@ -329,7 +326,7 @@ char *mallocstrncpy(char *dest, const char *src, size_t n)
* "dest = mallocstrcpy(dest, src);". */
char *mallocstrcpy(char *dest, const char *src)
{
- return mallocstrncpy(dest, src, (src == NULL) ? 1 : strlen(src) + 1);
+ return mallocstrncpy(dest, src, strlen(src) + 1);
}
/* Return an allocated copy of the given string. */