]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/mbsalign: fix warnings when compile without widechars
authorKarel Zak <kzak@redhat.com>
Wed, 13 Jan 2016 09:08:13 +0000 (10:08 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 13 Jan 2016 09:08:13 +0000 (10:08 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/widechar.h
lib/mbsalign.c

index b023b5fb2cc19bc71a8cc51bfcb8108894977b18..8632f769947ce6f27a4534078211b633e0cc9fdf 100644 (file)
@@ -32,6 +32,7 @@
 # define wcschr strchr
 # define wcsdup strdup
 # define wcslen strlen
+# define wcspbrk strpbrk
 
 # define wcwidth(c) 1
 
index 052fec611a869ceda0735808904fc1a4ca01cf01..2816cebbf3199377cd889ff7f5ac4d96ca552c6e 100644 (file)
@@ -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);