From ef63c7141256ae68be04bbfb2504bf8ba388370d Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Sat, 4 Jan 2014 22:48:09 +0100 Subject: [PATCH] maint: avoid compiler warnings introduced by i18n patch * src/cut.c (convfail,CONVFAIL): Change to bool to avoid a GCC warning about signed vs. unsigned. Also avoid "set but not used" of convfail in cut_characters_or_cut_bytes_no_split. (cut_fields_mb): Fix indentation. * src/expand.c: Add include for wctype.h to declare isblank(). * src/fold.c (fold_file): Add "const" attribute to 'filename' parameter to avoid "const cast away" in call in main(). * src/join.c (xfields_multibyte): Remove unused variable 't'. (keycmp): Evaluate the return value of wcrtomb(). Furthermore, when copying 'beg' to 'copy' array elements, remove the unnecessary cast to unsigned. (main): When assigning the newline string to 'newtab', cast away the implicit const. * src/pr.c: Remove the unneeded include of wctype.h and the define of iswprint(). (print_stored): Add the unsigned qualifier to 'first' and 'last' to avoid a signedness warning. * src/sort.c (getmonth_mb): Cast away the 'const' qualifier of 's' when assigning to *ea. * src/uniq.c (different_multi): Evaluate the return result of wcrtomb(); Add the include of assert.h for that. --- coreutils-i18n.patch | 72 ++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/coreutils-i18n.patch b/coreutils-i18n.patch index 59ff7ea..acef507 100644 --- a/coreutils-i18n.patch +++ b/coreutils-i18n.patch @@ -75,7 +75,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c + while (0) + +/* Get wide character on BUFPOS. BUFPOS is not included after that. -+ If byte sequence is not valid as a character, CONVFAIL is 1. Otherwise 0. */ ++ If byte sequence is not valid as a character, CONVFAIL is true. Otherwise false. */ +#define GET_NEXT_WC_FROM_BUFFER(WC, BUFPOS, BUFLEN, MBLENGTH, STATE, CONVFAIL) \ + do \ + { \ @@ -88,7 +88,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c + } \ + \ + /* Get a wide character. */ \ -+ CONVFAIL = 0; \ ++ CONVFAIL = false; \ + state_bak = STATE; \ + MBLENGTH = mbrtowc ((wchar_t *)&WC, BUFPOS, BUFLEN, &STATE); \ + \ @@ -96,7 +96,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c + { \ + case (size_t)-1: \ + case (size_t)-2: \ -+ CONVFAIL++; \ ++ CONVFAIL = true; \ + STATE = state_bak; \ + /* Fall througn. */ \ + \ @@ -199,7 +199,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c + size_t mblength; /* The byte size of a multibyte character which shows + as same character as WC. */ + mbstate_t state; /* State of the stream. */ -+ int convfail = 0; /* 1, when conversion is failed. Otherwise 0. */ ++ bool convfail = false; /* true, when conversion failed. Otherwise false. */ + /* Whether to begin printing delimiters between ranges for the current line. + Set after we've begun printing data corresponding to the first range. */ + bool print_delimiter = false; @@ -216,6 +216,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c + REFILL_BUFFER (buf, bufpos, buflen, stream); + + GET_NEXT_WC_FROM_BUFFER (wc, bufpos, buflen, mblength, state, convfail); ++ (void) convfail; /* ignore unused */ + + if (wc == WEOF) + { @@ -277,7 +278,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c + size_t mblength; /* The byte size of a multibyte character which shows + as same character as WC. */ + mbstate_t state; /* State of the stream. */ -+ int convfail = 0; /* 1, when conversion is failed. Otherwise 0. */ ++ bool convfail = false; /* true, when conversion failed. Otherwise false. */ + + current_rp = rp; + @@ -359,7 +360,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c + fwrite (field_1_buffer, sizeof (char), len - 1, stdout); + found_any_selected_field = 1; + } -+ next_item (&field_idx); ++ next_item (&field_idx); + } + + if (wc != WEOF) @@ -402,7 +403,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c + wc = WEOF; + + if (!convfail && wc == wcdelim) -+ next_item (&field_idx); ++ next_item (&field_idx); + else if (wc == WEOF || (!convfail && wc == L'\n')) + { + if (found_any_selected_field @@ -597,6 +598,11 @@ diff -urNp coreutils-8.22-orig/src/expand.c coreutils-8.22/src/expand.c +#if HAVE_WCHAR_H +# include +#endif ++ ++/* Get iswblank(). */ ++#if HAVE_WCTYPE_H ++# include ++#endif + #include "system.h" #include "error.h" @@ -1118,7 +1124,7 @@ diff -urNp coreutils-8.22-orig/src/fold.c coreutils-8.22/src/fold.c + Return 0 if successful, 1 if an error occurs. */ + +static bool -+fold_file (char *filename, size_t width) ++fold_file (char const *filename, size_t width) +{ + FILE *istream; + int saved_errno; @@ -1268,7 +1274,6 @@ diff -urNp coreutils-8.22-orig/src/join.c coreutils-8.22/src/join.c + + if (tab != NULL) + { -+ unsigned char t = tab[0]; + char *sep = ptr; + for (; ptr < lim; ptr = sep + mblength) + { @@ -1491,9 +1496,11 @@ diff -urNp coreutils-8.22-orig/src/join.c coreutils-8.22/src/join.c + if (uwc != wc) + { + mbstate_t state_wc; ++ size_t mblen; + + memset (&state_wc, '\0', sizeof (mbstate_t)); -+ wcrtomb (copy[i] + j, uwc, &state_wc); ++ mblen = wcrtomb (copy[i] + j, uwc, &state_wc); ++ assert (mblen != (size_t)-1); + } + else + memcpy (copy[i] + j, beg[i] + j, mblength); @@ -1523,8 +1530,8 @@ diff -urNp coreutils-8.22-orig/src/join.c coreutils-8.22/src/join.c - if (hard_LC_COLLATE) - return xmemcoll (beg1, len1, beg2, len2); - diff = memcmp (beg1, beg2, MIN (len1, len2)); -+ copy[0] = (unsigned char *) beg[0]; -+ copy[1] = (unsigned char *) beg[1]; ++ copy[0] = beg[0]; ++ copy[1] = beg[1]; } + if (hard_LC_COLLATE) @@ -1640,7 +1647,7 @@ diff -urNp coreutils-8.22-orig/src/join.c coreutils-8.22/src/join.c if (! newtab) - newtab = '\n'; /* '' => process the whole line. */ + { -+ newtab = "\n"; /* '' => process the whole line. */ ++ newtab = (char*)"\n"; /* '' => process the whole line. */ + } else if (optarg[1]) { @@ -1693,19 +1700,11 @@ diff -urNp coreutils-8.22-orig/src/pr.c coreutils-8.22/src/pr.c +#if HAVE_WCHAR_H +# include +#endif -+ -+/* Get iswprint(). -- for wcwidth(). */ -+#if HAVE_WCTYPE_H -+# include -+#endif -+#if !defined iswprint && !HAVE_ISWPRINT -+# define iswprint(wc) 1 -+#endif + #include "system.h" #include "error.h" #include "fadvise.h" -@@ -323,6 +349,18 @@ +@@ -323,6 +341,18 @@ #include "strftime.h" #include "xstrtol.h" @@ -2215,7 +2214,25 @@ diff -urNp coreutils-8.22-orig/src/pr.c coreutils-8.22/src/pr.c padding_not_printed = ANYWHERE; } -@@ -2595,9 +2801,9 @@ print_stored (COLUMN *p) +@@ -2564,7 +2762,7 @@ print_stored (COLUMN *p) + int i; + + int line = p->current_line++; +- char *first = &buff[line_vector[line]]; ++ unsigned char *first = &buff[line_vector[line]]; + /* FIXME + UMR: Uninitialized memory read: + * This is occurring while in: +@@ -2576,7 +2774,7 @@ print_stored (COLUMN *p) + xmalloc [xmalloc.c:94] + init_store_cols [pr.c:1648] + */ +- char *last = &buff[line_vector[line + 1]]; ++ unsigned char *last = &buff[line_vector[line + 1]]; + + pad_vertically = true; + +@@ -2595,9 +2793,9 @@ print_stored (COLUMN *p) } } @@ -3077,7 +3094,7 @@ diff -urNp coreutils-8.22-orig/src/sort.c coreutils-8.22/src/sort.c + ? monthtab[lo].val : 0); + + if (ea && result) -+ *ea = s + strlen (monthtab[lo].name); ++ *ea = (char*) s + strlen (monthtab[lo].name); + + free (month); + free (tmp); @@ -3681,11 +3698,12 @@ diff -urNp coreutils-8.22-orig/src/uniq.c coreutils-8.22/src/uniq.c +#if HAVE_WCTYPE_H +# include +#endif ++#include + #include "system.h" #include "argmatch.h" #include "linebuffer.h" -@@ -32,7 +42,19 @@ +@@ -32,7 +43,19 @@ #include "stdio--.h" #include "xmemcoll.h" #include "xstrtol.h" @@ -3901,9 +3919,11 @@ diff -urNp coreutils-8.22-orig/src/uniq.c coreutils-8.22/src/uniq.c + if (uwc != wc) + { + mbstate_t state_wc; ++ size_t mblen; + + memset (&state_wc, '\0', sizeof(mbstate_t)); -+ wcrtomb (copy[i] + j, uwc, &state_wc); ++ mblen = wcrtomb (copy[i] + j, uwc, &state_wc); ++ assert (mblen != (size_t)-1); + } + else + memcpy (copy[i] + j, str[i] + j, mblength);