Blame SOURCES/0005-fix-bug-introduced-by.patch

9f799c
From 6c0cca42baebb5c681f5ee7f940da8d0a1b2613d Mon Sep 17 00:00:00 2001
9f799c
From: "Thomas E. Dickey" <dickey@invisible-island.net>
9f799c
Date: Fri, 15 Mar 2019 20:06:26 -0400
9f799c
Subject: [PATCH 5/9] fix bug introduced by 	commit
9f799c
 57c8b133bbcf38a9a1e345eabeeabe2a3e07c1c8, which modified util/makestrs.c to
9f799c
 avoid a shadowing warning of a function parameter versus global variable, but
9f799c
 overlooked use of the parameter within the functions.  That caused all of the
9f799c
 resource strings in Shell.h to have the same value.
9f799c
9f799c
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
9f799c
---
9f799c
 util/makestrs.c | 122 ++++++++++++++++++++++++++++++------------------
9f799c
 1 file changed, 76 insertions(+), 46 deletions(-)
9f799c
9f799c
diff --git a/util/makestrs.c b/util/makestrs.c
9f799c
index 488c9bb..e626dee 100644
9f799c
--- a/util/makestrs.c
9f799c
+++ b/util/makestrs.c
9f799c
@@ -35,7 +35,7 @@ typedef struct _TableEnt {
9f799c
     struct _TableEnt* next;
9f799c
     char* left;
9f799c
     char* right;
9f799c
-    int offset;
9f799c
+    size_t offset;
9f799c
 } TableEnt;
9f799c
 
9f799c
 typedef struct _Table {
9f799c
@@ -44,7 +44,7 @@ typedef struct _Table {
9f799c
     TableEnt* tableentcurrent;
9f799c
     TableEnt** tableenttail;
9f799c
     char* name;
9f799c
-    int offset;
9f799c
+    size_t offset;
9f799c
 } Table;
9f799c
 
9f799c
 typedef struct _File {
9f799c
@@ -108,7 +108,7 @@ static FILE *ifopen(const char *myfile, const char *mode)
9f799c
     if (buffer == NULL)
9f799c
         return NULL;
9f799c
 
9f799c
-    snprintf(buffer, len + 1, "%s/%s", includedir, file);
9f799c
+    snprintf(buffer, len + 1, "%s/%s", includedir, myfile);
9f799c
 #endif
9f799c
 
9f799c
     ret = fopen(buffer, mode);
9f799c
@@ -123,7 +123,7 @@ static void WriteHeaderProlog (FILE *f, File *phile)
9f799c
     TableEnt* te;
9f799c
 
9f799c
     (void) fprintf (f, "#ifdef %s\n", featurestr);
9f799c
-    for (t = phile->table; t; t = t->next)
9f799c
+    for (t = phile->table; t; t = t->next) {
9f799c
 	for (te = t->tableent; te; te = te->next) {
9f799c
 	    if (strcmp (te->left, "RAtom") == 0) {
9f799c
 		(void) fprintf (f,
9f799c
@@ -135,6 +135,7 @@ static void WriteHeaderProlog (FILE *f, File *phile)
9f799c
 			prefixstr, te->left, te->right);
9f799c
 	    }
9f799c
 	}
9f799c
+    }
9f799c
     (void) fprintf (f, "%s", "#else\n");
9f799c
 }
9f799c
 
9f799c
@@ -148,10 +149,12 @@ static void IntelABIWriteHeader (FILE *f, File *phile)
9f799c
     for (t = phile->table; t; t = t->next) {
9f799c
       (void) fprintf (f, "%s %sConst char %s[];\n",
9f799c
 		      externrefstr, conststr ? conststr : fileprotstr, t->name);
9f799c
-	for (te = t->tableent; te; te = te->next)
9f799c
+	for (te = t->tableent; te; te = te->next) {
9f799c
 	    (void) fprintf (f,
9f799c
-		"#ifndef %s%s\n#define %s%s ((char*)&%s[%d])\n#endif\n",
9f799c
-		prefixstr, te->left, prefixstr, te->left, t->name, te->offset);
9f799c
+		"#ifndef %s%s\n#define %s%s ((char*)&%s[%lu])\n#endif\n",
9f799c
+		prefixstr, te->left, prefixstr, te->left, t->name,
9f799c
+		(unsigned long) te->offset);
9f799c
+	}
9f799c
     }
9f799c
 
9f799c
     (void) fprintf (f, "#endif /* %s */\n", featurestr);
9f799c
@@ -162,10 +165,12 @@ static void SPARCABIWriteHeader (FILE *f, File *phile)
9f799c
     Table* t;
9f799c
     TableEnt* te;
9f799c
 
9f799c
-    for (t = phile->table; t; t = t->next)
9f799c
-	for (te = t->tableent; te; te = te->next)
9f799c
+    for (t = phile->table; t; t = t->next) {
9f799c
+	for (te = t->tableent; te; te = te->next) {
9f799c
 	    (void) fprintf (f, "#define %s%s \"%s\"\n",
9f799c
 			    prefixstr, te->left, te->right);
9f799c
+	}
9f799c
+    }
9f799c
 }
9f799c
 
9f799c
 static void FunctionWriteHeader (FILE *f, File *phile)
9f799c
@@ -179,12 +184,14 @@ static void FunctionWriteHeader (FILE *f, File *phile)
9f799c
 		    externrefstr, conststr ? conststr : fileprotstr,
9f799c
 		    phile->table->name);
9f799c
 
9f799c
-    for (t = phile->table; t; t = t->next)
9f799c
-	for (te = t->tableent; te; te = te->next)
9f799c
+    for (t = phile->table; t; t = t->next) {
9f799c
+	for (te = t->tableent; te; te = te->next) {
9f799c
 	    (void) fprintf (f,
9f799c
-		"#ifndef %s%s\n#define %s%s (%s(%d))\n#endif\n",
9f799c
+		"#ifndef %s%s\n#define %s%s (%s(%lu))\n#endif\n",
9f799c
 		prefixstr, te->left, prefixstr, te->left, phile->table->name,
9f799c
-		te->offset);
9f799c
+		(unsigned long) te->offset);
9f799c
+	}
9f799c
+    }
9f799c
 
9f799c
     (void) fprintf (f, "#endif /* %s */\n", featurestr);
9f799c
 }
9f799c
@@ -196,13 +203,15 @@ static void ArrayperWriteHeader (FILE *f, File *phile)
9f799c
 
9f799c
     WriteHeaderProlog (f, phile);
9f799c
 
9f799c
-    for (t = phile->table; t; t = t->next)
9f799c
-        for (te = t->tableent; te; te = te->next)
9f799c
+    for (t = phile->table; t; t = t->next) {
9f799c
+        for (te = t->tableent; te; te = te->next) {
9f799c
 	    (void) fprintf (f,
9f799c
 			    "#ifndef %s%s\n%s %sConst char %s%s[];\n#endif\n",
9f799c
 			    prefixstr, te->left,
9f799c
 			    externrefstr, conststr ? conststr : fileprotstr,
9f799c
 			    prefixstr, te->left);
9f799c
+	}
9f799c
+    }
9f799c
 
9f799c
     (void) fprintf (f, "#endif /* %s */\n", featurestr);
9f799c
 }
9f799c
@@ -218,12 +227,14 @@ static void DefaultWriteHeader (FILE *f, File *phile)
9f799c
 		    externrefstr, conststr ? conststr : fileprotstr,
9f799c
 		    phile->table->name);
9f799c
 
9f799c
-    for (t = phile->table; t; t = t->next)
9f799c
-	for (te = t->tableent; te; te = te->next)
9f799c
+    for (t = phile->table; t; t = t->next) {
9f799c
+	for (te = t->tableent; te; te = te->next) {
9f799c
 	    (void) fprintf (f,
9f799c
-		"#ifndef %s%s\n#define %s%s ((char*)&%s[%d])\n#endif\n",
9f799c
+		"#ifndef %s%s\n#define %s%s ((char*)&%s[%lu])\n#endif\n",
9f799c
 		prefixstr, te->left, prefixstr, te->left, phile->table->name,
9f799c
-		te->offset);
9f799c
+		(unsigned long) te->offset);
9f799c
+	}
9f799c
+    }
9f799c
 
9f799c
     (void) fprintf (f, "#endif /* %s */\n", featurestr);
9f799c
 }
9f799c
@@ -232,7 +243,7 @@ static void CopyTmplProlog (FILE *tmpl, FILE *f)
9f799c
 {
9f799c
     char buf[1024];
9f799c
     static const char* magic_string = X_MAGIC_STRING;
9f799c
-    int magic_string_len = strlen (magic_string);
9f799c
+    size_t magic_string_len = strlen (magic_string);
9f799c
 
9f799c
     while (fgets (buf, sizeof buf, tmpl)) {
9f799c
 	if (strncmp (buf, magic_string, magic_string_len) == 0) {
9f799c
@@ -316,7 +327,7 @@ static void WriteSourceLine (TableEnt *te, int abi, int fudge)
9f799c
     (void) printf ("%s", "\n");
9f799c
 }
9f799c
 
9f799c
-static const char* const_string = "%s %sConst char %s[] = {\n";
9f799c
+#define const_string "%s %sConst char %s[] = {\n"
9f799c
 
9f799c
 static void IntelABIWriteSource (int abi)
9f799c
 {
9f799c
@@ -329,8 +340,9 @@ static void IntelABIWriteSource (int abi)
9f799c
 	for (t = phile->table; t; t = t->next) {
9f799c
 	    (void) printf (const_string, externdefstr,
9f799c
 			   conststr ? conststr : "", t->name);
9f799c
-	    for (te = t->tableent; te; te = te->next)
9f799c
+	    for (te = t->tableent; te; te = te->next) {
9f799c
 		WriteSourceLine (te, abi, 0);
9f799c
+	    }
9f799c
 	    (void) printf ("%s\n\n", "};");
9f799c
 	}
9f799c
     }
9f799c
@@ -347,17 +359,21 @@ static void IntelABIBCWriteSource (int abi)
9f799c
 	(void) printf (const_string, externdefstr,
9f799c
 		       conststr ? conststr : "", phile->table->name);
9f799c
 
9f799c
-	for (t = phile->table; t; t = t->next)
9f799c
-	    for (te = t->tableent; te; te = te->next)
9f799c
+	for (t = phile->table; t; t = t->next) {
9f799c
+	    for (te = t->tableent; te; te = te->next) {
9f799c
 		WriteSourceLine (te, abi, t->next ? 1 : 0);
9f799c
+	    }
9f799c
+	}
9f799c
 	(void) printf ("%s\n\n", "};");
9f799c
 
9f799c
 	if (phile->table->next) {
9f799c
 	    (void) printf (const_string, externdefstr,
9f799c
 			   conststr ? conststr : "", phile->table->next->name);
9f799c
-	    for (t = phile->table->next; t; t = t->next)
9f799c
-		for (te = t->tableent; te; te = te->next)
9f799c
+	    for (t = phile->table->next; t; t = t->next) {
9f799c
+		for (te = t->tableent; te; te = te->next) {
9f799c
 		    WriteSourceLine (te, abi, 0);
9f799c
+		}
9f799c
+	    }
9f799c
 	    (void) printf ("%s\n\n", "};");
9f799c
 	}
9f799c
     }
9f799c
@@ -374,9 +390,11 @@ static void FunctionWriteSource (int abi)
9f799c
 	(void) printf ("static %sConst char _%s[] = {\n",
9f799c
 		       conststr ? conststr : "", phile->table->name);
9f799c
 
9f799c
-	for (t = phile->table; t; t = t->next)
9f799c
-	    for (te = t->tableent; te; te = te->next)
9f799c
+	for (t = phile->table; t; t = t->next) {
9f799c
+	    for (te = t->tableent; te; te = te->next) {
9f799c
 		WriteSourceLine (te, abi, t->next ? 1 : 0);
9f799c
+	    }
9f799c
+	}
9f799c
 	(void) printf ("%s\n\n", "};");
9f799c
 
9f799c
 	(void) printf ("%sConst char* %s(index)\n    int index;\n{\n    return &_%s[index];\n}\n\n",
9f799c
@@ -394,7 +412,7 @@ static void ArrayperWriteSource (int abi)
9f799c
 	Table* t;
9f799c
 	TableEnt* te;
9f799c
 
9f799c
-	for (t = phile->table; t; t = t->next)
9f799c
+	for (t = phile->table; t; t = t->next) {
9f799c
 	    for (te = t->tableent; te; te = te->next) {
9f799c
 		if (strcmp (te->left, "RAtom") == 0) {
9f799c
 		    if (done_atom) return;
9f799c
@@ -405,6 +423,7 @@ static void ArrayperWriteSource (int abi)
9f799c
 			       prefixstr,
9f799c
 			       te->left, te->right);
9f799c
 	    }
9f799c
+	}
9f799c
     }
9f799c
 }
9f799c
 
9f799c
@@ -419,9 +438,11 @@ static void DefaultWriteSource (int abi)
9f799c
 	(void) printf (const_string, externdefstr, conststr ? conststr : "",
9f799c
 		       phile->table->name);
9f799c
 
9f799c
-	for (t = phile->table; t; t = t->next)
9f799c
-	    for (te = t->tableent; te; te = te->next)
9f799c
+	for (t = phile->table; t; t = t->next) {
9f799c
+	    for (te = t->tableent; te; te = te->next) {
9f799c
 		WriteSourceLine (te, abi, t->next ? 1 : 0);
9f799c
+	    }
9f799c
+	}
9f799c
 	(void) printf ("%s\n\n", "};");
9f799c
     }
9f799c
 }
9f799c
@@ -457,7 +478,10 @@ static void WriteSource(char *tagline, int abi)
9f799c
 
9f799c
     (*sourceproc[abi])(abi);
9f799c
 
9f799c
-    if (tmpl) CopyTmplEpilog (tmpl, stdout);
9f799c
+    if (tmpl) {
9f799c
+	CopyTmplEpilog (tmpl, stdout);
9f799c
+	fclose(tmpl);
9f799c
+    }
9f799c
 }
9f799c
 
9f799c
 static void DoLine(char *buf)
9f799c
@@ -586,9 +610,9 @@ static void DoLine(char *buf)
9f799c
 	{
9f799c
 	    char* right;
9f799c
 	    TableEnt* tableent;
9f799c
-	    int llen;
9f799c
-	    int rlen;
9f799c
-	    int len;
9f799c
+	    size_t llen;
9f799c
+	    size_t rlen;
9f799c
+	    size_t len;
9f799c
 
9f799c
 	    if ((right = strchr(buf, ' ')))
9f799c
 		*right++ = 0;
9f799c
@@ -602,7 +626,8 @@ static void DoLine(char *buf)
9f799c
 	    llen = len = strlen(buf) + 1;
9f799c
 	    rlen = strlen(right) + 1;
9f799c
 	    if (right != buf + 1) len += rlen;
9f799c
-	    if ((tableent = (TableEnt*)malloc(sizeof(TableEnt) + len)) == NULL)
9f799c
+	    tableent = (TableEnt*)calloc(sizeof(TableEnt) + len, 1);
9f799c
+	    if (tableent == NULL)
9f799c
 		exit(1);
9f799c
 	    tableent->left = (char *)(tableent + 1);
9f799c
 	    strcpy(tableent->left, buf);
9f799c
@@ -627,11 +652,12 @@ static void IntelABIIndexEntries (File *myfile)
9f799c
     Table* t;
9f799c
     TableEnt* te;
9f799c
 
9f799c
-    for (t = file->table; t; t = t->next)
9f799c
+    for (t = myfile->table; t; t = t->next) {
9f799c
 	for (te = t->tableent; te; te = te->next) {
9f799c
 	    te->offset = t->offset;
9f799c
 	    t->offset += strlen (te->right);
9f799c
 	    t->offset++;
9f799c
+	}
9f799c
     }
9f799c
 }
9f799c
 
9f799c
@@ -639,13 +665,14 @@ static void DefaultIndexEntries (File *myfile)
9f799c
 {
9f799c
     Table* t;
9f799c
     TableEnt* te;
9f799c
-    int offset = 0;
9f799c
+    size_t offset = 0;
9f799c
 
9f799c
-    for (t = file->table; t; t = t->next)
9f799c
+    for (t = myfile->table; t; t = t->next) {
9f799c
 	for (te = t->tableent; te; te = te->next) {
9f799c
 	    te->offset = offset;
9f799c
 	    offset += strlen (te->right);
9f799c
 	    offset++;
9f799c
+	}
9f799c
     }
9f799c
 }
9f799c
 
9f799c
@@ -656,10 +683,10 @@ static void IndexEntries (File *myfile, int abi)
9f799c
 	break;
9f799c
     case X_INTEL_ABI:
9f799c
     case X_INTEL_ABI_BC:
9f799c
-	IntelABIIndexEntries (file);
9f799c
+	IntelABIIndexEntries (myfile);
9f799c
 	break;
9f799c
     default:
9f799c
-	DefaultIndexEntries (file);
9f799c
+	DefaultIndexEntries (myfile);
9f799c
 	break;
9f799c
     }
9f799c
 }
9f799c
@@ -669,12 +696,12 @@ static char* DoComment (char *line)
9f799c
     char* tag;
9f799c
     char* eol;
9f799c
     char* ret;
9f799c
-    int len;
9f799c
+    size_t len;
9f799c
 
9f799c
     /* assume that the first line with two '$' in it is the RCS tag line */
9f799c
     if ((tag = strchr (line, '$')) == NULL) return NULL;
9f799c
     if ((eol = strchr (tag + 1, '$')) == NULL) return NULL;
9f799c
-    len = eol - tag;
9f799c
+    len = (size_t)(eol - tag);
9f799c
     if ((ret = malloc (len)) == NULL)
9f799c
 	exit (1);
9f799c
     (void) strncpy (ret, tag + 1, len - 1);
9f799c
@@ -684,7 +711,7 @@ static char* DoComment (char *line)
9f799c
 
9f799c
 int main(int argc, char *argv[])
9f799c
 {
9f799c
-    int len, i;
9f799c
+    size_t len;
9f799c
     char* tagline = NULL;
9f799c
     File* phile;
9f799c
     FILE *f;
9f799c
@@ -698,6 +725,7 @@ int main(int argc, char *argv[])
9f799c
 
9f799c
     f = stdin;
9f799c
     if (argc > 1) {
9f799c
+	int i;
9f799c
 	for (i = 1; i < argc; i++) {
9f799c
 	    if (strcmp (argv[i], "-f") == 0) {
9f799c
 		if (++i < argc)
9f799c
@@ -706,10 +734,12 @@ int main(int argc, char *argv[])
9f799c
 		    return 1;
9f799c
 	    }
9f799c
 	    if (strcmp (argv[i], "-i") == 0) {
9f799c
-		if (++i < argc)
9f799c
+		if (++i < argc) {
9f799c
 		    includedir = argv[i];
9f799c
-		else
9f799c
+		} else {
9f799c
+		    if (f != 0 && f != stdin) fclose(f);
9f799c
 		    return 1;
9f799c
+		}
9f799c
 	    }
9f799c
 	    if (strcmp (argv[i], "-sparcabi") == 0)
9f799c
 		abi = X_SPARC_ABI;
9f799c
-- 
9f799c
2.19.2
9f799c