From d992002d0b924230080db0306555ca629f5d558f Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sat, 7 Jun 2008 14:23:50 -0400 Subject: [PATCH] Somewhere I got the idea that wcrtomb(NULL, ...) cleared the 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index 57f677397..077e9ab0a 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -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.) */ -- 2.47.3