aboutsummaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-05-02 11:55:01 +0000
committerCorinna Vinschen <corinna@vinschen.de>2010-05-02 11:55:01 +0000
commitffa42cf6a0aa8835f832027c7545e2476b89b834 (patch)
treed31c67e411c2e62198836716809ec3560fcbff75 /newlib
parentbe129c26e2144ba97518217d91f1d695e32217a5 (diff)
downloadnewlib-ffa42cf6a0aa8835f832027c7545e2476b89b834.zip
newlib-ffa42cf6a0aa8835f832027c7545e2476b89b834.tar.gz
newlib-ffa42cf6a0aa8835f832027c7545e2476b89b834.tar.bz2
* libc/stdlib/wctob.c (wctob): Reorganize and fix WEOF check. Rename
pwc to pmb and convert to array to avoid buffer overflow. Rename c to wc. Check wc for WEOF instead of for EOF. Return first byte of pmb if __wctomb conversion returned exactly one byte, EOF otherwise.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog7
-rw-r--r--newlib/libc/stdlib/wctob.c18
2 files changed, 15 insertions, 10 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 7d60fcc..c3e6662 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,10 @@
+2010-05-02 Corinna Vinschen <corinna@vinschen.de>
+
+ * libc/stdlib/wctob.c (wctob): Reorganize and fix WEOF check. Rename
+ pwc to pmb and convert to array to avoid buffer overflow. Rename c to
+ wc. Check wc for WEOF instead of for EOF. Return first byte of pmb if
+ __wctomb conversion returned exactly one byte, EOF otherwise.
+
2010-04-30 Corinna Vinschen <corinna@vinschen.de>
* libc/include/langinfo.h: Fix #endif positioning.
diff --git a/newlib/libc/stdlib/wctob.c b/newlib/libc/stdlib/wctob.c
index 927c1a7..d97c01f 100644
--- a/newlib/libc/stdlib/wctob.c
+++ b/newlib/libc/stdlib/wctob.c
@@ -1,26 +1,24 @@
#include <reent.h>
#include <wchar.h>
-#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#include "local.h"
int
-wctob (wint_t c)
+wctob (wint_t wc)
{
mbstate_t mbs;
- int retval = 0;
- unsigned char pwc;
+ unsigned char pmb[MB_LEN_MAX];
+
+ if (wc == WEOF)
+ return EOF;
/* Put mbs in initial state. */
memset (&mbs, '\0', sizeof (mbs));
_REENT_CHECK_MISC(_REENT);
- retval = __wctomb (_REENT, &pwc, c, __locale_charset (), &mbs);
-
- if (c == EOF || retval != 1)
- return WEOF;
- else
- return (int)pwc;
+ return __wctomb (_REENT, (char *) pmb, wc, __locale_charset (), &mbs) == 1
+ ? (int) pmb[0] : EOF;
}