]> wimlib.net Git - wimlib/blobdiff - src/encoding.c
Fixes
[wimlib] / src / encoding.c
index e0f4e2d06666521b367b39e928f485fda7d6c3bd..e8bc40273f4180ab19f6a83cc0e178a5b84ce756 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <iconv.h>
 #include <stdlib.h>
+#include <errno.h>
 
 bool wimlib_mbs_is_utf8 = false;
 
@@ -101,6 +102,11 @@ put_iconv(iconv_t *cd)
        errno = errno_save;
 }
 
+/* Prevent printing an error message if a character conversion error occurs
+ * while printing an error message.  (This variable is not per-thread but it
+ * doesn't matter too much since it's just the error messages.) */
+static bool error_message_being_printed = false;
+
 #define DEFINE_CHAR_CONVERSION_FUNCTIONS(varname1, longname1, chartype1,\
                                         varname2, longname2, chartype2,\
                                         worst_case_len_expr,           \
@@ -128,7 +134,11 @@ varname1##_to_##varname2##_nbytes(const chartype1 *in, size_t in_nbytes,\
                                                                        \
        len = iconv(*cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); \
        if (len == (size_t)-1) {                                        \
-               err_msg;                                                \
+               if (!error_message_being_printed) {                     \
+                       error_message_being_printed = true;             \
+                       err_msg;                                        \
+                       error_message_being_printed = false;            \
+               }                                                       \
                ret = err_return;                                       \
        } else {                                                        \
                *out_nbytes_ret = sizeof(buf) - outbytesleft;           \
@@ -247,7 +257,7 @@ utf8_str_contains_nonascii_chars(const utf8char *utf8_str)
 {
        do {
                if ((unsigned char)*utf8_str > 127)
-                       return false;
+                       return true;
        } while (*++utf8_str);
-       return true;
+       return false;
 }