msvcrt[3/5]: test and fix _mbsnextc

Mikolaj Zalewski mikolajz at google.com
Mon Aug 20 12:18:37 CDT 2007


_mbsnextc also uses mbcp
-------------- next part --------------
From b9887457d0aa55fecf71acc95dc189b511417e00 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Miko=C5=82aj_Zalewski?= <mikolaj at zalewski.pl>
Date: Sun, 19 Aug 2007 22:34:12 -0700
Subject: [PATCH] msvcrt: test and fix _mbsnextc

---
 dlls/msvcrt/mbcs.c         |    4 ++--
 dlls/msvcrt/tests/string.c |   10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index fa1e207..c69cc25 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -282,9 +282,9 @@ int CDECL _getmbcp(void)
  */
 unsigned int CDECL _mbsnextc(const unsigned char* str)
 {
-  if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*str))
+  if(_ismbblead(*str))
     return *str << 8 | str[1];
-  return *str; /* ASCII CP or SB char */
+  return *str;
 }
 
 /*********************************************************************
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index 6ac3fe2..8b55cf3 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -25,6 +25,8 @@
 #include <stdlib.h>
 #include <mbctype.h>
 
+#define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
+
 static void* (*pmemcpy)(void *, const void *, size_t n);
 static int* (*pmemcmp)(void *, const void *, size_t n);
 
@@ -163,6 +165,7 @@ static void test_mbcp(void)
 {
     int mb_orig_max = __mb_cur_max;
     int curr_mbcp = _getmbcp();
+    unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
 
     /* some two single-byte code pages*/
     test_codepage(1252);
@@ -182,6 +185,13 @@ static void test_mbcp(void)
     ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
     ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
     ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
+
+
+    /* _mbsnextc */
+    expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
+    expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x");  /* lead + invalid tail */
+    expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x");    /* single char */
+
     _setmbcp(curr_mbcp);
 }
 
-- 
1.4.4.2


More information about the wine-patches mailing list