summaryrefslogtreecommitdiff
path: root/Parser
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-04-23 00:41:19 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-04-23 00:41:19 +0200
commit3fd7679f3cf2bccebd1f4b4ac727d89258d520a9 (patch)
tree3e443f1550e17c3612adefedad73fea94f897d0b /Parser
parent5381833c87d83ccc9957d60d388a70a5fed9d550 (diff)
downloadcpython-3fd7679f3cf2bccebd1f4b4ac727d89258d520a9.tar.gz
Issue #9319: Fix a crash on parsing a Python source code without encoding
cookie and not valid in UTF-8: use "<file>" as the filename instead of reading from NULL.
Diffstat (limited to 'Parser')
-rw-r--r--Parser/tokenizer.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 3f6be2f640..5ba12a409d 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -586,7 +586,10 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
if (badchar) {
/* Need to add 1 to the line number, since this line
has not been counted, yet. */
- filename = PyUnicode_DecodeFSDefault(tok->filename);
+ if (tok->filename != NULL)
+ filename = PyUnicode_DecodeFSDefault(tok->filename);
+ else
+ filename = PyUnicode_FromString("<file>");
if (filename != NULL) {
PyErr_Format(PyExc_SyntaxError,
"Non-UTF-8 code starting with '\\x%.2x' "