pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/150275/files

sets.com/assets/primer-primitives-b39ad27f3538ace3.css" /> gh-150207: Raise MemoryError on tokenizer allocation failure instead of crashing by grantlouisherman · Pull Request #150275 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a crash when a memory allocation fails during tokenizer initialization. A proper :exc:`MemoryError` is now raised instead.
5 changes: 4 additions & 1 deletion Parser/lexer/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ _PyTokenizer_tok_new(void)
struct tok_state *tok = (struct tok_state *)PyMem_Calloc(
1,
sizeof(struct tok_state));
if (tok == NULL)
if (tok == NULL) {
PyErr_NoMemory();
return NULL;
}

tok->buf = tok->cur = tok->inp = NULL;
tok->fp_interactive = 0;
tok->interactive_src_start = NULL;
Expand Down
1 change: 1 addition & 0 deletions Parser/tokenizer/file_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ _PyTokenizer_FromFile(FILE *fp, const char* enc,
return NULL;
if ((tok->buf = (char *)PyMem_Malloc(BUFSIZ)) == NULL) {
_PyTokenizer_Free(tok);
PyErr_NoMemory();
return NULL;
}
tok->cur = tok->inp = tok->buf;
Expand Down
2 changes: 2 additions & 0 deletions Parser/tokenizer/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ _PyTokenizer_new_string(const char *s, Py_ssize_t len, struct tok_state *tok)
char* result = (char *)PyMem_Malloc(len + 1);
if (!result) {
tok->done = E_NOMEM;
PyErr_NoMemory();
return NULL;
}
memcpy(result, s, len);
Expand Down Expand Up @@ -221,6 +222,7 @@ _PyTokenizer_translate_newlines(const char *s, int exec_input, int preserve_crlf
buf = PyMem_Malloc(needed_length);
if (buf == NULL) {
tok->done = E_NOMEM;
PyErr_NoMemory();
return NULL;
}
for (current = buf; *s; s++, current++) {
Expand Down
1 change: 1 addition & 0 deletions Parser/tokenizer/readline_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ _PyTokenizer_FromReadline(PyObject* readline, const char* enc,
return NULL;
if ((tok->buf = (char *)PyMem_Malloc(BUFSIZ)) == NULL) {
_PyTokenizer_Free(tok);
PyErr_NoMemory();
return NULL;
}
tok->cur = tok->inp = tok->buf;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy