mirror of
https://github.com/troglobit/editline.git
synced 2025-05-05 20:11:12 +08:00
Fix #17: Fix off-by-one problem with strdup() replacement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
a5aaf51530
commit
76039b458b
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user