Prechádzať zdrojové kódy

fix redundant computations of strlen in glob append function

len was already passed as an argument, so don't use strcat, and use
memcpy instead of strcpy.
Rich Felker 6 rokov pred
rodič
commit
09a805a623
1 zmenil súbory, kde vykonal 5 pridanie a 2 odobranie
  1. 5 2
      src/regex/glob.c

+ 5 - 2
src/regex/glob.c

@@ -41,8 +41,11 @@ static int append(struct match **tail, const char *name, size_t len, int mark)
 	if (!new) return -1;
 	(*tail)->next = new;
 	new->next = NULL;
-	strcpy(new->name, name);
-	if (mark) strcat(new->name, "/");
+	memcpy(new->name, name, len+1);
+	if (mark) {
+		new->name[len] = '/';
+		new->name[len+1] = 0;
+	}
 	*tail = new;
 	return 0;
 }