Skip to contentSkip to conversation

LVM2/lib/config config.c

PATCH [email protected] 1 participant 1 message Jan 28, 2011

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: zkabelac at sourceware.org 2011-01-28 10:19:00

Modified files:
lib/config : config.c

Log message:
Use memcpy and add error message

strncpy (which check each byte for \0) is not need as we always copy the length size - so using memcpy is a bit cheaper.

Add missing log_error message for failed allocation.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/config/config.c.diff?cvsroot=lvm2&r1=1.87&r2=1.88

lib/config/config.c +5 -3
@@ -886,9 +886,11 @@
 {
 	size_t len = p->te - p->tb;
 	char *str = dm_pool_alloc(p->mem, len + 1);
-	if (!str)
-		return_0;
-	strncpy(str, p->tb, len);
+	if (!str) {
+		log_error("Failed to duplicate token.");
+		return 0;
+	}
+	memcpy(str, p->tb, len);
 	str[len] = '\0';
 	return str;
 }