file:///srv/subversion/repos/asterisk/branches/10
................
r372656 | rmudgett | 2012-09-07 18:06:38 -0500 (Fri, 07 Sep 2012) | 8 lines
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
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10-digiumphones@372681
65c4cc65-6c06-0410-ace0-
fbb531ad65f3
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;
}