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.
This commit is contained in:
Bernhard Voelker 2014-01-04 22:48:09 +01:00 committed by Ondřej Vašík
parent 963813cd96
commit ef63c71412

View File

@ -75,7 +75,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c
+ while (0) + while (0)
+ +
+/* Get wide character on BUFPOS. BUFPOS is not included after that. +/* 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) \ +#define GET_NEXT_WC_FROM_BUFFER(WC, BUFPOS, BUFLEN, MBLENGTH, STATE, CONVFAIL) \
+ do \ + do \
+ { \ + { \
@ -88,7 +88,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c
+ } \ + } \
+ \ + \
+ /* Get a wide character. */ \ + /* Get a wide character. */ \
+ CONVFAIL = 0; \ + CONVFAIL = false; \
+ state_bak = STATE; \ + state_bak = STATE; \
+ MBLENGTH = mbrtowc ((wchar_t *)&WC, BUFPOS, BUFLEN, &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)-1: \
+ case (size_t)-2: \ + case (size_t)-2: \
+ CONVFAIL++; \ + CONVFAIL = true; \
+ STATE = state_bak; \ + STATE = state_bak; \
+ /* Fall througn. */ \ + /* 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 + size_t mblength; /* The byte size of a multibyte character which shows
+ as same character as WC. */ + as same character as WC. */
+ mbstate_t state; /* State of the stream. */ + 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. + /* Whether to begin printing delimiters between ranges for the current line.
+ Set after we've begun printing data corresponding to the first range. */ + Set after we've begun printing data corresponding to the first range. */
+ bool print_delimiter = false; + 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); + REFILL_BUFFER (buf, bufpos, buflen, stream);
+ +
+ GET_NEXT_WC_FROM_BUFFER (wc, bufpos, buflen, mblength, state, convfail); + GET_NEXT_WC_FROM_BUFFER (wc, bufpos, buflen, mblength, state, convfail);
+ (void) convfail; /* ignore unused */
+ +
+ if (wc == WEOF) + 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 + size_t mblength; /* The byte size of a multibyte character which shows
+ as same character as WC. */ + as same character as WC. */
+ mbstate_t state; /* State of the stream. */ + 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; + 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); + fwrite (field_1_buffer, sizeof (char), len - 1, stdout);
+ found_any_selected_field = 1; + found_any_selected_field = 1;
+ } + }
+ next_item (&field_idx); + next_item (&field_idx);
+ } + }
+ +
+ if (wc != WEOF) + if (wc != WEOF)
@ -402,7 +403,7 @@ diff -urNp coreutils-8.22-orig/src/cut.c coreutils-8.22/src/cut.c
+ wc = WEOF; + wc = WEOF;
+ +
+ if (!convfail && wc == wcdelim) + if (!convfail && wc == wcdelim)
+ next_item (&field_idx); + next_item (&field_idx);
+ else if (wc == WEOF || (!convfail && wc == L'\n')) + else if (wc == WEOF || (!convfail && wc == L'\n'))
+ { + {
+ if (found_any_selected_field + 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 +#if HAVE_WCHAR_H
+# include <wchar.h> +# include <wchar.h>
+#endif +#endif
+
+/* Get iswblank(). */
+#if HAVE_WCTYPE_H
+# include <wctype.h>
+#endif
+ +
#include "system.h" #include "system.h"
#include "error.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. */ + Return 0 if successful, 1 if an error occurs. */
+ +
+static bool +static bool
+fold_file (char *filename, size_t width) +fold_file (char const *filename, size_t width)
+{ +{
+ FILE *istream; + FILE *istream;
+ int saved_errno; + 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) + if (tab != NULL)
+ { + {
+ unsigned char t = tab[0];
+ char *sep = ptr; + char *sep = ptr;
+ for (; ptr < lim; ptr = sep + mblength) + 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) + if (uwc != wc)
+ { + {
+ mbstate_t state_wc; + mbstate_t state_wc;
+ size_t mblen;
+ +
+ memset (&state_wc, '\0', sizeof (mbstate_t)); + 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 + else
+ memcpy (copy[i] + j, beg[i] + j, mblength); + 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) - if (hard_LC_COLLATE)
- return xmemcoll (beg1, len1, beg2, len2); - return xmemcoll (beg1, len1, beg2, len2);
- diff = memcmp (beg1, beg2, MIN (len1, len2)); - diff = memcmp (beg1, beg2, MIN (len1, len2));
+ copy[0] = (unsigned char *) beg[0]; + copy[0] = beg[0];
+ copy[1] = (unsigned char *) beg[1]; + copy[1] = beg[1];
} }
+ if (hard_LC_COLLATE) + 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) if (! newtab)
- newtab = '\n'; /* '' => process the whole line. */ - newtab = '\n'; /* '' => process the whole line. */
+ { + {
+ newtab = "\n"; /* '' => process the whole line. */ + newtab = (char*)"\n"; /* '' => process the whole line. */
+ } + }
else if (optarg[1]) 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 +#if HAVE_WCHAR_H
+# include <wchar.h> +# include <wchar.h>
+#endif +#endif
+
+/* Get iswprint(). -- for wcwidth(). */
+#if HAVE_WCTYPE_H
+# include <wctype.h>
+#endif
+#if !defined iswprint && !HAVE_ISWPRINT
+# define iswprint(wc) 1
+#endif
+ +
#include "system.h" #include "system.h"
#include "error.h" #include "error.h"
#include "fadvise.h" #include "fadvise.h"
@@ -323,6 +349,18 @@ @@ -323,6 +341,18 @@
#include "strftime.h" #include "strftime.h"
#include "xstrtol.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; 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); + ? monthtab[lo].val : 0);
+ +
+ if (ea && result) + if (ea && result)
+ *ea = s + strlen (monthtab[lo].name); + *ea = (char*) s + strlen (monthtab[lo].name);
+ +
+ free (month); + free (month);
+ free (tmp); + 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 +#if HAVE_WCTYPE_H
+# include <wctype.h> +# include <wctype.h>
+#endif +#endif
+#include <assert.h>
+ +
#include "system.h" #include "system.h"
#include "argmatch.h" #include "argmatch.h"
#include "linebuffer.h" #include "linebuffer.h"
@@ -32,7 +42,19 @@ @@ -32,7 +43,19 @@
#include "stdio--.h" #include "stdio--.h"
#include "xmemcoll.h" #include "xmemcoll.h"
#include "xstrtol.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) + if (uwc != wc)
+ { + {
+ mbstate_t state_wc; + mbstate_t state_wc;
+ size_t mblen;
+ +
+ memset (&state_wc, '\0', sizeof(mbstate_t)); + 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 + else
+ memcpy (copy[i] + j, str[i] + j, mblength); + memcpy (copy[i] + j, str[i] + j, mblength);