]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Somewhere I got the idea that wcrtomb(NULL, ...) cleared the
authorTim Kientzle <kientzle@gmail.com>
Sat, 7 Jun 2008 18:23:50 +0000 (14:23 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 7 Jun 2008 18:23:50 +0000 (14:23 -0400)
provided shift state.  This is wrong; memset() seems to be
the correct portable way to clear the shift state.
Submitted by: NAKAJIMA Michihiro
MFP4 after: 3 days

SVN-Revision: 109

libarchive/archive_string.c

index 57f6773978813f1fba1578c86f733f9aa7fac870..077e9ab0ad552ac9c7f0bf91435b5ab0a96ba1a2 100644 (file)
@@ -180,6 +180,8 @@ my_wcrtomb_utf8(char *p, wchar_t wc, mbstate_t *s)
        (void)s; /* UNUSED */
 
        if (p == NULL)
+               /* Since this routine never uses shift state, we don't
+                * need to clear it here. */
                return (0);
        if (wc <= 0x7f) {
                p[0] = (char)wc;
@@ -220,12 +222,14 @@ my_wcstombs(struct archive_string *as, const wchar_t *w,
        mbstate_t shift_state;
        char buff[256];
 
+       /* Clear the shift state before starting. */
+       memset(&shift_state, 0, sizeof(shift_state));
+
        /*
         * Convert one wide char at a time into 'buff', whenever that
         * fills, append it to the string.
         */
        p = buff;
-       wcrtomb(NULL, L'\0', &shift_state);
        while (*w != L'\0') {
                /* Flush the buffer when we have <=16 bytes free. */
                /* (No encoding has a single character >16 bytes.) */