Fix #17: Fix off-by-one problem with strdup() replacement

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2018-06-14 21:59:18 +02:00
parent a5aaf51530
commit 76039b458b

View File

@ -218,14 +218,18 @@ void rl_ttyset(int Reset)
#ifndef HAVE_STRDUP
/* Return an allocated copy of a string. */
char *strdup(const char *p)
char *strdup(const char *s)
{
char *new = malloc(sizeof(char) * strlen(p));
size_t len;
char *ptr;
if (new) {
strcpy(new, p);
return new;
}
if (!s)
return NULL;
len = strlen(s) + 1;
ptr = malloc(len);
if (ptr)
return memcpy(ptr, s, len);
return NULL;
}