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.
			
			
This commit is contained in:
		| @@ -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> | 2009-03-02  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* libc/stdlib/wctomb_r.c (_wctomb_r): Return EILSEQ in case of an | 	* libc/stdlib/wctomb_r.c (_wctomb_r): Return EILSEQ in case of an | ||||||
|   | |||||||
| @@ -48,6 +48,7 @@ effects vary with the locale. | |||||||
|  |  | ||||||
| #include <newlib.h> | #include <newlib.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <errno.h> | ||||||
|  |  | ||||||
| int | int | ||||||
| _DEFUN (wctomb, (s, wchar), | _DEFUN (wctomb, (s, wchar), | ||||||
| @@ -62,6 +63,12 @@ _DEFUN (wctomb, (s, wchar), | |||||||
|         if (s == NULL) |         if (s == NULL) | ||||||
|                 return 0; |                 return 0; | ||||||
|  |  | ||||||
|  | 	/* Verify that wchar is a valid single-byte character.  */ | ||||||
|  | 	if ((size_t)wchar >= 0x100) { | ||||||
|  | 		errno = EILSEQ; | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|         *s = (char) wchar; |         *s = (char) wchar; | ||||||
|         return 1; |         return 1; | ||||||
| #endif /* not _MB_CAPABLE */ | #endif /* not _MB_CAPABLE */ | ||||||
|   | |||||||
| @@ -207,7 +207,7 @@ _DEFUN (_wctomb_r, (r, s, wchar, state), | |||||||
|     return 0; |     return 0; | ||||||
|   |   | ||||||
|   /* otherwise we are dealing with a single byte character */ |   /* otherwise we are dealing with a single byte character */ | ||||||
|   if (wchar >= 0x100) |   if ((size_t)wchar >= 0x100) | ||||||
|     { |     { | ||||||
|       r->_errno = EILSEQ; |       r->_errno = EILSEQ; | ||||||
|       return -1; |       return -1; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user