diff options
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r-- | newlib/libc/stdlib/wctomb.c | 7 | ||||
-rw-r--r-- | newlib/libc/stdlib/wctomb_r.c | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/newlib/libc/stdlib/wctomb.c b/newlib/libc/stdlib/wctomb.c index f2c62496f..2ab7b0339 100644 --- a/newlib/libc/stdlib/wctomb.c +++ b/newlib/libc/stdlib/wctomb.c @@ -48,6 +48,7 @@ effects vary with the locale. #include <newlib.h> #include <stdlib.h> +#include <errno.h> int _DEFUN (wctomb, (s, wchar), @@ -62,6 +63,12 @@ _DEFUN (wctomb, (s, wchar), if (s == NULL) return 0; + /* Verify that wchar is a valid single-byte character. */ + if ((size_t)wchar >= 0x100) { + errno = EILSEQ; + return -1; + } + *s = (char) wchar; return 1; #endif /* not _MB_CAPABLE */ diff --git a/newlib/libc/stdlib/wctomb_r.c b/newlib/libc/stdlib/wctomb_r.c index 11418b564..b5205fcaa 100644 --- a/newlib/libc/stdlib/wctomb_r.c +++ b/newlib/libc/stdlib/wctomb_r.c @@ -207,7 +207,7 @@ _DEFUN (_wctomb_r, (r, s, wchar, state), return 0; /* otherwise we are dealing with a single byte character */ - if (wchar >= 0x100) + if ((size_t)wchar >= 0x100) { r->_errno = EILSEQ; return -1; |