From 5a8ad742d956b8f30f196d8967d183bcbd57152c Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 24 Jul 2010 02:39:45 +0200 Subject: [PATCH] Adding -Wcast-qual revealed some more interesting casts. --- configure | 2 +- configure.ac | 2 +- src/complete.c | 6 +++--- src/editline.c | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/configure b/configure index 6910daf..7448e97 100755 --- a/configure +++ b/configure @@ -11274,7 +11274,7 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext CFLAGS="$saved_cflags" -AM_CFLAGS="-std=gnu99 $inline_cflags -W -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow" +AM_CFLAGS="-std=gnu99 $inline_cflags -W -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow -Wcast-qual" ### The following magic for determining the location of termcap library is from GNU Texinfo diff --git a/configure.ac b/configure.ac index 5bd3472..4b155cc 100644 --- a/configure.ac +++ b/configure.ac @@ -111,7 +111,7 @@ AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="") CFLAGS="$saved_cflags" -AM_CFLAGS="-std=gnu99 $inline_cflags -W -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow" +AM_CFLAGS="-std=gnu99 $inline_cflags -W -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow -Wcast-qual" AC_SUBST(AM_CFLAGS) ### The following magic for determining the location of termcap library is from GNU Texinfo diff --git a/src/complete.c b/src/complete.c index 44ed547..64e97f5 100644 --- a/src/complete.c +++ b/src/complete.c @@ -23,11 +23,11 @@ #define MAX_TOTAL_MATCHES (256 << sizeof(char *)) -/* Wrap strcmp() for qsort() */ +/* Wrap strcmp() for qsort() -- weird construct to pass -Wcast-qual */ static int compare(const void *p1, const void *p2) { - char **v1 = (char **)p1; - char **v2 = (char **)p2; + char *const *v1 = (char *const *)p1; + char *const *v2 = (char *const *)p2; return strcmp(*v1, *v2); } diff --git a/src/editline.c b/src/editline.c index 881f12d..67a1bbf 100644 --- a/src/editline.c +++ b/src/editline.c @@ -452,7 +452,7 @@ static el_status_t insert_string(const char *p) char *new; char *q; - len = strlen((char *)p); + len = strlen(p); if (rl_end + len >= Length) { new = malloc(sizeof(char) * (Length + len + MEM_INC)); if (!new) @@ -566,13 +566,13 @@ static const char *search_hist(const char *search, const char *(*move)(void)) int len; int pos; int (*match)(const char *s1, const char *s2, size_t n); - char *pat; + const char *pat; /* Save or get remembered search pattern. */ if (search && *search) { if (old_search) free(old_search); - old_search = (char *)strdup((char *)search); + old_search = strdup(search); } else { if (old_search == NULL || *old_search == '\0') @@ -583,16 +583,16 @@ static const char *search_hist(const char *search, const char *(*move)(void)) /* Set up pattern-finder. */ if (*search == '^') { match = strncmp; - pat = (char *)(search + 1); + pat = search + 1; } else { match = substrcmp; - pat = (char *)search; + pat = search; } len = strlen(pat); for (pos = H.Pos; (*move)() != NULL; ) - if ((*match)((char *)H.Lines[H.Pos], pat, len) == 0) + if (match(H.Lines[H.Pos], pat, len) == 0) return H.Lines[H.Pos]; H.Pos = pos;