summaryrefslogtreecommitdiff
path: root/Parser
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-08-15 02:51:12 -0400
committerGitHub <noreply@github.com>2018-08-15 02:51:12 -0400
commit2275b773ebfacb94f6a9c81d6a8b9d54771a68e8 (patch)
treea946c7fd46bfd3477ac312ead8f9384d186c8ed4 /Parser
parente3228a3f44e382b6cdd2b5e001b651347013a7d3 (diff)
downloadcpython-git-2275b773ebfacb94f6a9c81d6a8b9d54771a68e8.tar.gz
closes bpo-34400: Fix undefined behavior in parsetok(). (GH-4439)
Avoid undefined pointer arithmetic with NULL. (cherry picked from commit 7c4ab2afb17b99eb3f61f9c73cbd548b5e0ad2c0) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r--Parser/parsetok.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index 00d741d221..b9c9fe8fa8 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -225,7 +225,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
}
else
started = 1;
- len = b - a; /* XXX this may compute NULL - NULL */
+ len = (a != NULL && b != NULL) ? b - a : 0;
str = (char *) PyObject_MALLOC(len + 1);
if (str == NULL) {
err_ret->error = E_NOMEM;