mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 04:21:24 +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
|
#ifndef HAVE_STRDUP
|
||||||
/* Return an allocated copy of a string. */
|
/* 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) {
|
if (!s)
|
||||||
strcpy(new, p);
|
return NULL;
|
||||||
return new;
|
|
||||||
}
|
len = strlen(s) + 1;
|
||||||
|
ptr = malloc(len);
|
||||||
|
if (ptr)
|
||||||
|
return memcpy(ptr, s, len);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user