[svn-commits] rmudgett: branch 1.8 r372655 - /branches/1.8/main/astmm.c

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


Author: rmudgett
Date: Fri Sep  7 18:05:21 2012
New Revision: 372655

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=372655
Log:
Fix MALLOC_DEBUG version of ast_strndup().

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

Modified:
    branches/1.8/main/astmm.c

Modified: branches/1.8/main/astmm.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/astmm.c?view=diff&rev=372655&r1=372654&r2=372655
==============================================================================
--- branches/1.8/main/astmm.c (original)
+++ branches/1.8/main/astmm.c Fri Sep  7 18:05:21 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