Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 981aa46

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 3e630c5 commit 981aa46

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)