Skip to content

Commit 451f0fa

Browse files
committed
bpo-34400: Fix undefined behavior in parsetok()
1 parent aa4e4a4 commit 451f0fa

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix undefined behavior in parsetok.c. Patch by Zackery Spytz.

Parser/parsetok.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
225225
}
226226
else
227227
started = 1;
228-
len = b - a; /* XXX this may compute NULL - NULL */
228+
len = a != NULL && b != NULL ? b - a : 0;
229229
str = (char *) PyObject_MALLOC(len + 1);
230230
if (str == NULL) {
231231
err_ret->error = E_NOMEM;

0 commit comments

Comments
 (0)