Skip to content

Commit 00aebab

Browse files
closes bpo-34400: Fix undefined behavior in parsetok(). (GH-4439)
Avoid undefined pointer arithmetic with NULL. (cherry picked from commit 7c4ab2a) Co-authored-by: Zackery Spytz <[email protected]>
1 parent 1f34aec commit 00aebab

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
@@ -176,7 +176,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
176176
}
177177
else
178178
started = 1;
179-
len = b - a; /* XXX this may compute NULL - NULL */
179+
len = (a != NULL && b != NULL) ? b - a : 0;
180180
str = (char *) PyObject_MALLOC(len + 1);
181181
if (str == NULL) {
182182
fprintf(stderr, "no mem for next token\n");

0 commit comments

Comments
 (0)