Subject: Re: lib/36938: mbtowc misbehaving after invalid char sequence
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Neil Booth <neil@daikokuya.co.uk>
List: netbsd-bugs
Date: 11/04/2007 02:10:03
The following reply was made to PR lib/36938; it has been noted by GNATS.

From: Neil Booth <neil@daikokuya.co.uk>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/36938: mbtowc misbehaving after invalid char sequence
Date: Sun, 4 Nov 2007 09:22:38 +0900

 tnozaki marked this bug closed, but it seems did not understand
 the report.
 
 The testcase is fixed as given, but only when the explicitly
 marked **unnecessary** line is included.  If you remove the
 unnecessary assertion, the code fails again.
 
 As a result, please fix the original bug and please check
 that the "fix" that was committed is actually correct.
 
 Thank you.  For clarity, the below program should succeed,
 but does not.  Note I have added #if 0 this time.
 
 Neil.
 
 #include <assert.h>
 #include <locale.h>
 #include <stdlib.h>
 
 /* Valid 2-byte shift-JIS character, not valid UTF-8 sequence.  */
 const char sjis[] = "\x95\x5c";  
 /* Valid UTF-8, of course.  */
 const char space[] = " ";
 
 int main (void)
 {
   wchar_t wc;
 
   setlocale (LC_CTYPE, "ja_JP.UTF-8");
 
   /* Assert it is not state-dependent.  */
   assert (mbtowc (&wc, 0, 1) == 0);
 
   /* Assert my charset beliefs.  */
   assert (mbtowc (&wc, space, sizeof space) == 1);
   assert (mbtowc (&wc, sjis, sizeof sjis) == -1);
 #if 0
   /* Unnecessary assertion that we're not state-dependent, but
      just in case some state needs resetting.  */
   assert (mbtowc (&wc, 0, 1) == 0);
 #endif
   /* This assertion fails - I believe incorrectly.  */
   assert (mbtowc (&wc, space, sizeof space) == 1);
 
   return 0;
 }