Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f2ed1f

Browse files
author
Victor Stinner
committed
Fix ast_error_finish() and err_input(): filename can be NULL
Fix my previous commit (r85569).
1 parent 4c7c8c3 commit 2f2ed1f

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Python/ast.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ ast_error_finish(const char *filename)
131131
Py_INCREF(Py_None);
132132
loc = Py_None;
133133
}
134-
filename_obj = PyUnicode_DecodeFSDefault(filename);
134+
if (filename != NULL)
135+
filename_obj = PyUnicode_DecodeFSDefault(filename);
136+
else {
137+
Py_INCREF(Py_None);
138+
filename_obj = Py_None;
139+
}
135140
if (filename_obj != NULL)
136141
tmp = Py_BuildValue("(NlOO)", filename_obj, lineno, offset, loc);
137142
else

Python/pythonrun.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,12 @@ err_input(perrdetail *err)
20542054
errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text),
20552055
"replace");
20562056
}
2057-
filename = PyUnicode_DecodeFSDefault(err->filename);
2057+
if (err->filename != NULL)
2058+
filename = PyUnicode_DecodeFSDefault(err->filename);
2059+
else {
2060+
Py_INCREF(Py_None);
2061+
filename = Py_None;
2062+
}
20582063
if (filename != NULL)
20592064
v = Py_BuildValue("(NiiN)", filename,
20602065
err->lineno, err->offset, errtext);

0 commit comments

Comments
 (0)