summaryrefslogtreecommitdiff
path: root/Parser
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2018-12-07 05:17:43 -0700
committerSerhiy Storchaka <storchaka@gmail.com>2018-12-07 14:17:43 +0200
commit602d307ac5e8a2da38a193dca3bdfef5994dfe67 (patch)
tree8e876e0142683a7564a391dc6396bc6d33f08639 /Parser
parent2db190bb356d00422087e1286637887efb8d97c5 (diff)
downloadcpython-git-602d307ac5e8a2da38a193dca3bdfef5994dfe67.tar.gz
bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. (GH-11015) (GH-11020)
(cherry picked from commit 4c49da0cb7434c676d70b9ccf38aca82ac0d64a9)
Diffstat (limited to 'Parser')
-rw-r--r--Parser/myreadline.c43
-rw-r--r--Parser/tokenizer.c5
2 files changed, 42 insertions, 6 deletions
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index edb291a669..58dc0f75fe 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -153,20 +153,37 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn)
wbuf = (wchar_t*)PyMem_RawMalloc(wbuflen * sizeof(wchar_t));
if (wbuf)
wcscpy_s(wbuf, wbuflen, wbuf_local);
+ else {
+ PyErr_NoMemory();
+ goto exit;
+ }
+ }
+ else {
+ wchar_t *tmp = PyMem_RawRealloc(wbuf, wbuflen * sizeof(wchar_t));
+ if (tmp == NULL) {
+ PyErr_NoMemory();
+ goto exit;
+ }
+ wbuf = tmp;
}
- else
- wbuf = (wchar_t*)PyMem_RawRealloc(wbuf, wbuflen * sizeof(wchar_t));
}
if (wbuf[0] == '\x1a') {
buf = PyMem_RawMalloc(1);
if (buf)
buf[0] = '\0';
+ else {
+ PyErr_NoMemory();
+ }
goto exit;
}
u8len = WideCharToMultiByte(CP_UTF8, 0, wbuf, total_read, NULL, 0, NULL, NULL);
buf = PyMem_RawMalloc(u8len + 1);
+ if (buf == NULL) {
+ PyErr_NoMemory();
+ goto exit;
+ }
u8len = WideCharToMultiByte(CP_UTF8, 0, wbuf, total_read, buf, u8len, NULL, NULL);
buf[u8len] = '\0';
@@ -211,8 +228,12 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
int wlen;
wlen = MultiByteToWideChar(CP_UTF8, 0, prompt, -1,
NULL, 0);
- if (wlen &&
- (wbuf = PyMem_RawMalloc(wlen * sizeof(wchar_t)))) {
+ if (wlen) {
+ wbuf = PyMem_RawMalloc(wlen * sizeof(wchar_t));
+ if (wbuf == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
wlen = MultiByteToWideChar(CP_UTF8, 0, prompt, -1,
wbuf, wlen);
if (wlen) {
@@ -236,8 +257,10 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
n = 100;
p = (char *)PyMem_RawMalloc(n);
- if (p == NULL)
+ if (p == NULL) {
+ PyErr_NoMemory();
return NULL;
+ }
fflush(sys_stdout);
if (prompt)
@@ -314,6 +337,10 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
if (_PyOS_ReadlineLock == NULL) {
_PyOS_ReadlineLock = PyThread_allocate_lock();
+ if (_PyOS_ReadlineLock == NULL) {
+ PyErr_SetString(PyExc_MemoryError, "can't allocate lock");
+ return NULL;
+ }
}
_PyOS_ReadlineTState = PyThreadState_GET();
@@ -341,8 +368,12 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
len = strlen(rv) + 1;
res = PyMem_Malloc(len);
- if (res != NULL)
+ if (res != NULL) {
memcpy(res, rv, len);
+ }
+ else {
+ PyErr_NoMemory();
+ }
PyMem_RawFree(rv);
return res;
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index fbc98880c9..1a36f1c384 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -953,6 +953,11 @@ tok_nextc(struct tok_state *tok)
buflen = PyBytes_GET_SIZE(u);
buf = PyBytes_AS_STRING(u);
newtok = PyMem_MALLOC(buflen+1);
+ if (newtok == NULL) {
+ Py_DECREF(u);
+ tok->done = E_NOMEM;
+ return EOF;
+ }
strcpy(newtok, buf);
Py_DECREF(u);
}