Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 80415:f3e512b5ffb3
Issue #16416: Fix error handling in _Py_wchar2char() _Py_char2wchar() functions
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Mon, 12 Nov 2012 23:32:21 +0100 |
| parents | 7ed9993d53b4 |
| children | 5f2624db78bd |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Mon Nov 12 17:04:43 2012 -0500 +++ b/Objects/unicodeobject.c Mon Nov 12 23:32:21 2012 +0100 @@ -4691,7 +4691,10 @@ #ifdef __APPLE__ /* Simplified UTF-8 decoder using surrogateescape error handler, - used to decode the command line arguments on Mac OS X. */ + used to decode the command line arguments on Mac OS X. + + Return a pointer to a newly allocated wide character string (use + PyMem_Free() to free the memory), or NULL on memory allocation error. */ wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size) @@ -4702,10 +4705,8 @@ /* Note: size will always be longer than the resulting Unicode character count */ - if (PY_SSIZE_T_MAX / sizeof(wchar_t) < (size + 1)) { - PyErr_NoMemory(); - return NULL; - } + if (PY_SSIZE_T_MAX / sizeof(wchar_t) < (size + 1)) + return NULL; unicode = PyMem_Malloc((size + 1) * sizeof(wchar_t)); if (!unicode) return NULL;
