shithub: scc

Download patch

ref: 16ac0a93b39ea62401f2d2edb5f203ffe2e746b0
parent: 85b514f5c1368e93ba0f368366fd68db0a4eb3d6
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Mar 6 06:12:36 EST 2018

[ar/nm] Synchronize the file name criteria

We get rid of final / added in COFF and elf.

--- a/ar/main.c
+++ b/ar/main.c
@@ -336,16 +336,17 @@
 static char *
 getfname(struct ar_hdr *hdr)
 {
-	static char fname[FILENAME_MAX];
+	static char fname[SARNAM+1];
 	size_t i;
-	char *bp = fname;
 
-	for (i = 0; i < sizeof(hdr->ar_name); i++) {
-		if ((*bp = hdr->ar_name[i]) == ' ')
+	memcpy(fname, hdr->ar_name, SARNAM);
+	fname[SARNAM] = '\0';
+
+	for (i = SARNAM-1; i >= 0; --i) {
+		if (fname[i] != ' ' && fname[i] != '/')
 			break;
-		++bp;
+		fname[i] = '\0';
 	}
-	*bp = '\0';
 	return fname;
 }
 
--- a/nm/main.c
+++ b/nm/main.c
@@ -43,14 +43,17 @@
 getfname(struct ar_hdr *hdr, char *dst)
 {
 	char *p;
+	int i;
 
 	memcpy(dst, hdr->ar_name, SARNAM);
 	dst[SARNAM] = '\0';
-	if ((p = strchr(dst, ' ')) != NULL)
-		*p = '\0';
-	if ((p =  strchr(dst, '/')) != NULL)
-		*p = '\0';
-	return (*p == '\0') ? NULL : dst;
+
+	for (i = SARNAM-1; i >= 0; i--) {
+		if (dst[i] != ' ' && dst[i] != '/')
+			break;
+		dst[i] = '\0';
+	}
+	return dst;
 }
 
 static void
@@ -68,9 +71,6 @@
 		if (strncmp(hdr.ar_fmag, ARFMAG, strlen(ARFMAG)))
 			goto corrupted;
 
-		if (!getfname(&hdr, member))
-			goto corrupted;
-
 		siz = 0;
 		sscanf(hdr.ar_size, "%10ld", &siz);
 		if (siz == 0)
@@ -86,12 +86,13 @@
 		}
 		pos += siz;
 
+		getfname(&hdr, member);
 		if (object(fname, fp)) {
 			nm(fname, hdr.ar_name, fp);
 		} else {
 			fprintf(stderr,
 			        "nm: skipping member %s in archive %s\n",
-			        hdr.ar_name, fname);
+			        member, fname);
 		}
 		fseek(fp, pos, SEEK_SET);
 	}