Skip to content

Commit 003a5e7

Browse files
author
Victor Stinner
committed
Use PyErr_Format() in decoding_fgets()
Avoid a buffer of 500 bytes allocated on the stack.
1 parent 740f53a commit 003a5e7

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

Parser/tokenizer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,14 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
580580
}
581581
}
582582
if (badchar) {
583-
char buf[500];
584583
/* Need to add 1 to the line number, since this line
585584
has not been counted, yet. */
586-
sprintf(buf,
585+
PyErr_Format(PyExc_SyntaxError,
587586
"Non-UTF-8 code starting with '\\x%.2x' "
588587
"in file %.200s on line %i, "
589588
"but no encoding declared; "
590589
"see http://python.org/dev/peps/pep-0263/ for details",
591590
badchar, tok->filename, tok->lineno + 1);
592-
PyErr_SetString(PyExc_SyntaxError, buf);
593591
return error_ret(tok);
594592
}
595593
#endif

0 commit comments

Comments
 (0)