Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH 1/2] Fix incompatible-pointer-types bugs



Fix incompatible-pointer-types in fallback code.

When the flag -Werror=incompatible-pointer-types is passed to gcc, the
fallback code will fail to compile due to incompatible pointer types.

Beginning with gcc-14, -Werror=incompatible-pointer-typees will default
to enabled. See:
https://wiki.gentoo.org/wiki/Modern_C_porting#What_changed.3F
https://inbox.sourceware.org/gcc-patches/cover.1700473918.git.fweimer@xxxxxxxxxx/
for details.

Signed-off-by: Nicholas Vinson <nvinson234@xxxxxxxxx>
---
 Src/Modules/termcap.c | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/Src/Modules/termcap.c b/Src/Modules/termcap.c
index af4009a3a..28b48c24c 100644
--- a/Src/Modules/termcap.c
+++ b/Src/Modules/termcap.c
@@ -42,18 +42,21 @@
 #ifdef HAVE_TGETENT
 
 #ifndef HAVE_BOOLCODES
-static char *boolcodes[] = {
+static const char * const zboolcodes[] = {
     "bw", "am", "ut", "cc", "xs", "YA", "YF", "YB", "xt", "xn", "eo",
     "gn", "hc", "HC", "km", "YC", "hs", "hl", "in", "YG", "da", "db",
     "mi", "ms", "nx", "xb", "NP", "ND", "NR", "os", "5i", "YD", "YE",
     "es", "hz", "ul", "xo", NULL};
+#   define BOOLCODES zboolcodes
+#else
+#   define BOOLCODES boolcodes
 #endif
 
 /**/
 static int
-ztgetflag(char *s)
+ztgetflag(const char *s)
 {
-    char **b;
+    const char * const *b;
 
     /* ncurses can tell if an existing boolean capability is *
      * off, but other curses variants can't, so we fudge it. *
@@ -63,7 +66,7 @@ ztgetflag(char *s)
     case -1:
 	break;
     case 0:
-	for (b = (char **)boolcodes; *b; ++b)
+	for (b = BOOLCODES; *b; ++b)
 	    if (s[0] == (*b)[0] && s[1] == (*b)[1])
 		return 0;
 	break;
@@ -201,18 +204,22 @@ scantermcap(UNUSED(HashTable ht), ScanFunc func, int flags)
 {
     Param pm = NULL;
     int num;
-    char **capcode, *tcstr, buf[2048], *u;
+    char *tcstr, buf[2048], *u;
+    const char * const *capcode;
 
 #ifndef HAVE_NUMCODES
-    static char *numcodes[] = {
+    static const char * const znumcodes[] = {
 	"co", "it", "lh", "lw", "li", "lm", "sg", "ma", "Co", "pa", "MW",
 	"NC", "Nl", "pb", "vt", "ws", "Yo", "Yp", "Ya", "BT", "Yc", "Yb",
 	"Yd", "Ye", "Yf", "Yg", "Yh", "Yi", "Yk", "Yj", "Yl", "Ym", "Yn",
 	NULL};
+#   define NUMCODES znumcodes
+#else
+#   define NUMCODES numcodes
 #endif
 
 #ifndef HAVE_STRCODES
-    static char *zstrcodes[] = {
+    static const char * const zstrcodes[] = {
 	"ac", "bt", "bl", "cr", "ZA", "ZB", "ZC", "ZD", "cs", "rP", "ct",
 	"MC", "cl", "cb", "ce", "cd", "ch", "CC", "CW", "cm", "do", "ho",
 	"vi", "le", "CM", "ve", "nd", "ll", "up", "vs", "ZE", "dc", "dl",
@@ -249,6 +256,9 @@ scantermcap(UNUSED(HashTable ht), ScanFunc func, int flags)
 	"S1", "Yy", "S2", "S4", "S3", "S5", "Gm", "Km", "Mi", "S6", "xl",
 	"RQ", "S7", "s0", "s1", "s2", "s3", "AB", "AF", "Yz", "ML", "YZ",
 	"MT", "Xh", "Xl", "Xo", "Xr", "Xt", "Xv", "sA", "sL", NULL};
+#   define STRCODES zstrcodes
+#else
+#   define STRCODES strcodes
 #endif
 
     pm = (Param) hcalloc(sizeof(struct param));
@@ -257,7 +267,7 @@ scantermcap(UNUSED(HashTable ht), ScanFunc func, int flags)
     pm->node.flags = PM_READONLY | PM_SCALAR;
     pm->gsu.s = &nullsetscalar_gsu;
 
-    for (capcode = (char **)boolcodes; *capcode; capcode++) {
+    for (capcode = BOOLCODES; *capcode; capcode++) {
 	if ((num = ztgetflag(*capcode)) != -1) {
 	    pm->u.str = num ? dupstring("yes") : dupstring("no");
 	    pm->node.nam = dupstring(*capcode);
@@ -268,7 +278,7 @@ scantermcap(UNUSED(HashTable ht), ScanFunc func, int flags)
     pm->node.flags = PM_READONLY | PM_INTEGER;
     pm->gsu.i = &nullsetinteger_gsu;
 
-    for (capcode = (char **)numcodes; *capcode; capcode++) {
+    for (capcode = NUMCODES; *capcode; capcode++) {
 	if ((num = tgetnum(*capcode)) != -1) {
 	    pm->u.val = num;
 	    pm->node.nam = dupstring(*capcode);
@@ -279,13 +289,7 @@ scantermcap(UNUSED(HashTable ht), ScanFunc func, int flags)
     pm->node.flags = PM_READONLY | PM_SCALAR;
     pm->gsu.s = &nullsetscalar_gsu;
 
-    for (capcode = (char **)
-#ifdef HAVE_STRCODES
-	     strcodes
-#else
-	     zstrcodes
-#endif
-	     ; *capcode; capcode++) {
+    for (capcode = STRCODES; *capcode; capcode++) {
 	if ((tcstr = (char *)tgetstr(*capcode,&u)) != NULL &&
 	    tcstr != (char *)-1) {
 	    pm->u.str = dupstring(tcstr);
-- 
2.43.0





Messages sorted by: Reverse Date, Date, Thread, Author