summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
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 acb4d01..43e5583 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 fc75bae..d319a4c 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);
}