[git commit prelink 1/1] wchar: bug #1471: fix cornercase in mbrtowc
Bernhard Reutner-Fischer
rep.dot.nop at gmail.com
Sun Nov 28 19:50:38 UTC 2010
commit: http://git.uclibc.org/uClibc/commit/?id=86b4bf7d3194a06281f053be341031d9196874c2
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/prelink
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
libc/misc/wchar/wchar.c | 2 ++
test/.gitignore | 1 +
test/locale-mbwc/Makefile.in | 4 ++--
test/locale-mbwc/tst2_mbrtowc.c | 21 +++++++++++++++++++++
4 files changed, 26 insertions(+), 2 deletions(-)
create mode 100644 test/locale-mbwc/tst2_mbrtowc.c
diff --git a/libc/misc/wchar/wchar.c b/libc/misc/wchar/wchar.c
index 7380ac9..ab6c617 100644
--- a/libc/misc/wchar/wchar.c
+++ b/libc/misc/wchar/wchar.c
@@ -286,6 +286,8 @@ size_t mbrtowc(wchar_t *__restrict pwc, const char *__restrict s,
s = empty_string;
n = 1;
} else if (*s == '\0') {
+ if (pwc)
+ *pwc = '\0';
/* According to the ISO C 89 standard this is the expected behaviour. */
return 0;
} else if (!n) {
diff --git a/test/.gitignore b/test/.gitignore
index a4af61d..ffef258 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -96,6 +96,7 @@ locale-mbwc/tst_wctomb
locale-mbwc/tst_wctrans
locale-mbwc/tst_wctype
locale-mbwc/tst_wcwidth
+locale-mbwc/tst2_mbrtowc
locale/show-ucs-data
locale/tst-digits
locale/tst-langinfo
diff --git a/test/locale-mbwc/Makefile.in b/test/locale-mbwc/Makefile.in
index 05c232a..7c0e9d5 100644
--- a/test/locale-mbwc/Makefile.in
+++ b/test/locale-mbwc/Makefile.in
@@ -15,8 +15,8 @@ TESTS := tst_iswalnum tst_iswalpha tst_iswcntrl \
tst_wcspbrk tst_wcsrtombs tst_wcsspn tst_wcsstr \
tst_wcstod tst_wcstok tst_wcstombs tst_wcswidth \
tst_wcsxfrm tst_wctob tst_wctomb tst_wctrans \
- tst_wctype tst_wcwidth tst_strfmon
-
+ tst_wctype tst_wcwidth tst_strfmon \
+ tst2_mbrtowc
# NOTE: For now disabled tst_strfmon to avoid build failure.
TESTS_DISABLED := tst_strfmon
diff --git a/test/locale-mbwc/tst2_mbrtowc.c b/test/locale-mbwc/tst2_mbrtowc.c
new file mode 100644
index 0000000..92e1283
--- /dev/null
+++ b/test/locale-mbwc/tst2_mbrtowc.c
@@ -0,0 +1,21 @@
+#include <wchar.h>
+#include <assert.h>
+#include <stdlib.h>
+
+/* bugs.uclibc.org/1471 : make sure output is 0 */
+static int
+do_test(void)
+{
+ wchar_t output;
+ int result;
+
+ output = L'A'; /* anything other than 0 will do... */
+ result = mbrtowc (&output, "", 1, 0);
+
+ assert (result == 0);
+ assert (output == 0);
+
+ return EXIT_SUCCESS;
+}
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
--
1.7.2.2
More information about the uClibc-cvs
mailing list