[svn-commits] rmudgett: branch 11 r372657 - in /branches/11: ./ main/astmm.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Sep 7 18:07:52 CDT 2012


Author: rmudgett
Date: Fri Sep  7 18:07:49 2012
New Revision: 372657

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=372657
Log:
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

Modified:
    branches/11/   (props changed)
    branches/11/main/astmm.c

Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: branches/11/main/astmm.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/astmm.c?view=diff&rev=372657&r1=372656&r2=372657
==============================================================================
--- branches/11/main/astmm.c (original)
+++ branches/11/main/astmm.c Fri Sep  7 18:07:49 2012
@@ -272,16 +272,17 @@
 char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
 {
 	size_t len;
-	void *ptr;
-
-	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);
+	char *ptr;
+
+	if (!s) {
+		return NULL;
+	}
+
+	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;
 }




More information about the svn-commits mailing list