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

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