]> granicus.if.org Git - python/commitdiff
Use PyErr_Format() in decoding_fgets()
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 28 Apr 2010 17:06:46 +0000 (17:06 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 28 Apr 2010 17:06:46 +0000 (17:06 +0000)
Avoid a buffer of 500 bytes allocated on the stack.

Parser/tokenizer.c

index 77fec7400857428cb688a3b7c602f542f4aee9e3..aef081de342812598a035b4e2d35592da8829228 100644 (file)
@@ -580,16 +580,14 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
                        }
        }
        if (badchar) {
-               char buf[500];
                /* Need to add 1 to the line number, since this line
                   has not been counted, yet.  */
-               sprintf(buf,
+               PyErr_Format(PyExc_SyntaxError,
                        "Non-UTF-8 code starting with '\\x%.2x' "
                        "in file %.200s on line %i, "
                        "but no encoding declared; "
                        "see http://python.org/dev/peps/pep-0263/ for details",
                        badchar, tok->filename, tok->lineno + 1);
-               PyErr_SetString(PyExc_SyntaxError, buf);
                return error_ret(tok);
        }
 #endif