diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2009-03-02 23:30:59 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2009-03-02 23:30:59 +0000 |
commit | 95d85fcb1ad3fc0eeffa8e6b26bee429983116e3 (patch) | |
tree | 47dc95a41106a813a4b777edf8bbe6b37191dfb7 | |
parent | 49b09e5afa22995997518beca6bdb71408b0f479 (diff) | |
download | newlib-95d85fcb1ad3fc0eeffa8e6b26bee429983116e3.zip newlib-95d85fcb1ad3fc0eeffa8e6b26bee429983116e3.tar.gz newlib-95d85fcb1ad3fc0eeffa8e6b26bee429983116e3.tar.bz2 |
2009-03-02 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdlib/wctomb_r.c (_wctomb_r): When checking single-byte
charset, cast wchar to size_t in case wchar_t is signed.
* libc/stdlib/wctomb.c (wctomb): Add similar single-byte check.
-rw-r--r-- | newlib/ChangeLog | 6 | ||||
-rw-r--r-- | newlib/libc/stdlib/wctomb.c | 7 | ||||
-rw-r--r-- | newlib/libc/stdlib/wctomb_r.c | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index b307cfc..bab663c 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,9 @@ +2009-03-02 Jeff Johnston <jjohnstn@redhat.com> + + * libc/stdlib/wctomb_r.c (_wctomb_r): When checking single-byte + charset, cast wchar to size_t in case wchar_t is signed. + * libc/stdlib/wctomb.c (wctomb): Add similar single-byte check. + 2009-03-02 Corinna Vinschen <corinna@vinschen.de> * libc/stdlib/wctomb_r.c (_wctomb_r): Return EILSEQ in case of an diff --git a/newlib/libc/stdlib/wctomb.c b/newlib/libc/stdlib/wctomb.c index f2c6249..2ab7b03 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 11418b5..b5205fc 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; |