Browse Source

logsys.c: avoid an unnecessary strlen call

* exec/logsys.c (strcpy_cutoff): Use strlen, then memcpy,
not strcpy, then strlen.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2143 fd59a12c-fef9-0310-b244-a6a79926bd2f
Jim Meyering 17 years ago
parent
commit
0b264ba292
1 changed files with 4 additions and 4 deletions
  1. 4 4
      exec/logsys.c

+ 4 - 4
exec/logsys.c

@@ -279,12 +279,12 @@ do {									\
  */
 static inline int strcpy_cutoff (char *dest, const char *src, int cutoff)
 {
-	unsigned int len;
-
 	if (cutoff <= 0) {
-		strcpy (dest, src);
-		return (strlen (dest));
+		size_t len = strlen (src);
+		memcpy (dest, src, len + 1);
+		return (len);
 	} else {
+		size_t len;
 		strncpy (dest, src, cutoff);
 		dest[cutoff] = '\0';
 		len = strlen (dest);