Skip to content

Commit 8a4ef9b

Browse files
committed
fixup! fixup! bpo-40619: Correctly handle error text and offset for <string> input
1 parent 3e395f0 commit 8a4ef9b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Parser/pegen/pegen.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,10 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
399399

400400
if (!error_line) {
401401
Py_ssize_t size = p->tok->inp - p->tok->buf;
402-
error_line = PyUnicode_DecodeUTF8(p->tok->buf,
403-
p->tok->buf[size-1] == '\n' ? size - 1 : size,
404-
"replace");
402+
if (size && p->tok->buf[size-1] == '\n') {
403+
size--;
404+
}
405+
error_line = PyUnicode_DecodeUTF8(p->tok->buf, size, "replace");
405406
if (!error_line) {
406407
goto error;
407408
}

0 commit comments

Comments
 (0)