summaryrefslogtreecommitdiffstats
path: root/newlib
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2012-05-30 14:42:52 +0000
committerCorinna Vinschen <corinna@vinschen.de>2012-05-30 14:42:52 +0000
commit53bbfeed98c82b018bdfa5e719abd31ac1beba40 (patch)
treeb29d5331ddcf47df13de9a57427cbda25288de29 /newlib
parent0b592aeef28a5942322ea353096b85d0e8600459 (diff)
downloadcygnal-53bbfeed98c82b018bdfa5e719abd31ac1beba40.tar.gz
cygnal-53bbfeed98c82b018bdfa5e719abd31ac1beba40.tar.bz2
cygnal-53bbfeed98c82b018bdfa5e719abd31ac1beba40.zip
* libc/stdio/fgetws.c (_fgetws_r): Call _mbsnrtowcs_r rather than
_mbsrtowcs_r and restrict number of wide chars to n - 1.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog5
-rw-r--r--newlib/libc/stdio/fgetws.c10
2 files changed, 12 insertions, 3 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index b40d62abb..8704d6a06 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,5 +1,10 @@
2012-05-30 Corinna Vinschen <vinschen@redhat.com>
+ * libc/stdio/fgetws.c (_fgetws_r): Call _mbsnrtowcs_r rather than
+ _mbsrtowcs_r and restrict number of wide chars to n - 1.
+
+2012-05-30 Corinna Vinschen <vinschen@redhat.com>
+
* libc/stdio/local.h (_newlib_flockfile_start): New macro to
secure stream related critical section against thread cancellation.
(_newlib_flockfile_exit): Ditto.
diff --git a/newlib/libc/stdio/fgetws.c b/newlib/libc/stdio/fgetws.c
index cbfd84eb2..3cf45a976 100644
--- a/newlib/libc/stdio/fgetws.c
+++ b/newlib/libc/stdio/fgetws.c
@@ -110,9 +110,13 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
{
src = (char *) fp->_p;
nl = memchr (fp->_p, '\n', fp->_r);
- nconv = _mbsrtowcs_r (ptr, wsp, &src,
- nl != NULL ? (nl - fp->_p + 1) : fp->_r,
- &fp->_mbstate);
+ nconv = _mbsnrtowcs_r (ptr, wsp, &src,
+ /* Read all bytes up to the next NL, or up to the
+ end of the buffer if there is no NL. */
+ nl != NULL ? (nl - fp->_p + 1) : fp->_r,
+ /* But never more than n - 1 wide chars. */
+ n - 1,
+ &fp->_mbstate);
if (nconv == (size_t) -1)
/* Conversion error */
goto error;