Skip to content

Commit a63c872

Browse files
type-crash(): throw a no mem error when malloc fails in tokenizer
Signed-off-by: grantlouisherman <grantlouisherman041@gmail.com>
1 parent 4e3ead9 commit a63c872

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Parser/lexer/state.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ _PyTokenizer_tok_new(void)
1515
struct tok_state *tok = (struct tok_state *)PyMem_Calloc(
1616
1,
1717
sizeof(struct tok_state));
18-
if (tok == NULL)
18+
if (tok == NULL) {
19+
PyErr_NoMemory();
1920
return NULL;
21+
}
22+
2023
tok->buf = tok->cur = tok->inp = NULL;
2124
tok->fp_interactive = 0;
2225
tok->interactive_src_start = NULL;

Parser/tokenizer/helpers.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ _PyTokenizer_new_string(const char *s, Py_ssize_t len, struct tok_state *tok)
193193
char* result = (char *)PyMem_Malloc(len + 1);
194194
if (!result) {
195195
tok->done = E_NOMEM;
196+
PyErr_NoMemory();
196197
return NULL;
197198
}
198199
memcpy(result, s, len);
@@ -221,6 +222,7 @@ _PyTokenizer_translate_newlines(const char *s, int exec_input, int preserve_crlf
221222
buf = PyMem_Malloc(needed_length);
222223
if (buf == NULL) {
223224
tok->done = E_NOMEM;
225+
PyErr_NoMemory();
224226
return NULL;
225227
}
226228
for (current = buf; *s; s++, current++) {

0 commit comments

Comments
 (0)