diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2014-05-16 13:56:00 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2014-05-16 13:56:26 -0700 |
commit | 2a045bc38f853c02f682c710b8d69bd465719b26 (patch) | |
tree | 2cf341cb64709c332d337d0f0e697bf1d8174004 /lib/mbrtowc.c | |
parent | 6a26d6cbe963a8234538201e9a3b2261243d7e27 (diff) | |
download | gnulib-2a045bc38f853c02f682c710b8d69bd465719b26.tar.gz |
mbrlen, mbrtowc: fix bug with empty input
* lib/mbrtowc.c (rpl_mbrtowc) [MBRTOWC_EMPTY_INPUT_BUG]: Fix the bug.
* m4/mbrlen.m4 (gl_MBRLEN_EMPTY_INPUT): New macro. It's not used,
so this is mainly for documentation.
* m4/mbrtowc.m4 (gl_MBRTOWC_EMPTY_INPUT): New macro.
(gl_FUNC_MBRTOWC): Use it.
* tests/test-mbrtowc.c (main): Test for the bug.
Diffstat (limited to 'lib/mbrtowc.c')
-rw-r--r-- | lib/mbrtowc.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/mbrtowc.c b/lib/mbrtowc.c index 9415fd751b..5743f437f6 100644 --- a/lib/mbrtowc.c +++ b/lib/mbrtowc.c @@ -328,7 +328,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) size_t rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { -# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG +# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG || MBRTOWC_EMPTY_INPUT_BUG if (s == NULL) { pwc = NULL; @@ -337,6 +337,11 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) } # endif +# if MBRTOWC_EMPTY_INPUT_BUG + if (n == 0) + return (size_t) -2; +# endif + # if MBRTOWC_RETVAL_BUG { static mbstate_t internal_state; |