From: Karel Zak Date: Wed, 13 Jan 2016 09:08:13 +0000 (+0100) Subject: lib/mbsalign: fix warnings when compile without widechars X-Git-Tag: v2.28-rc1~199 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6426f926ee3d23fe416cd82e0325f249ba973798;p=thirdparty%2Futil-linux.git lib/mbsalign: fix warnings when compile without widechars Signed-off-by: Karel Zak --- diff --git a/include/widechar.h b/include/widechar.h index b023b5fb2c..8632f76994 100644 --- a/include/widechar.h +++ b/include/widechar.h @@ -32,6 +32,7 @@ # define wcschr strchr # define wcsdup strdup # define wcslen strlen +# define wcspbrk strpbrk # define wcwidth(c) 1 diff --git a/lib/mbsalign.c b/lib/mbsalign.c index 052fec611a..2816cebbf3 100644 --- a/lib/mbsalign.c +++ b/lib/mbsalign.c @@ -301,7 +301,7 @@ mbs_truncate(char *str, size_t *width) done: free(wcs); #else - if (*width < bytes) + if (bytes >= 0 && *width < (size_t) bytes) bytes = *width; #endif if (bytes >= 0) @@ -350,10 +350,11 @@ mbsalign (const char *src, char *dest, size_t dest_size, size_t n_cols = src_size - 1; size_t n_used_bytes = n_cols; /* Not including NUL */ size_t n_spaces = 0, space_left; + +#ifdef HAVE_WIDECHAR bool conversion = false; bool wc_enabled = false; -#ifdef HAVE_WIDECHAR /* In multi-byte locales convert to wide characters to allow easy truncation. Also determine number of screen columns used. */ @@ -407,9 +408,9 @@ mbsalign (const char *src, char *dest, size_t dest_size, n_cols = wc_truncate (str_wc, *width); n_used_bytes = wcstombs (newstr, str_wc, src_size); } -#endif mbsalign_unibyte: +#endif if (n_cols > *width) /* Unibyte truncation required. */ { @@ -456,9 +457,9 @@ mbsalign_unibyte: dest = mempcpy (dest, str_to_print, min (n_used_bytes, space_left)); mbs_align_pad (dest, dest_end, end_spaces); } - +#ifdef HAVE_WIDECHAR mbsalign_cleanup: - +#endif free (str_wc); free (newstr);