Fix MALLOC_DEBUG version of ast_strndup().

(closes issue ASTERISK-20349)
Reported by: Brent Eagles
........

Merged revisions 372655 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 372656 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 372657 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@372658 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett 2012-09-07 23:10:05 +00:00
parent 8b90b7a565
commit e315657287
1 changed files with 8 additions and 7 deletions

View File

@ -272,16 +272,17 @@ char *__ast_strdup(const char *s, const char *file, int lineno, const char *func
char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
{
size_t len;
void *ptr;
char *ptr;
if (!s)
if (!s) {
return NULL;
}
len = strlen(s) + 1;
if (len > n)
len = n;
if ((ptr = __ast_alloc_region(len, FUNC_STRNDUP, file, lineno, func, 0)))
strcpy(ptr, s);
len = strnlen(s, n);
if ((ptr = __ast_alloc_region(len + 1, FUNC_STRNDUP, file, lineno, func, 0))) {
memcpy(ptr, s, len);
ptr[len] = '\0';
}
return ptr;
}