aboutsummaryrefslogtreecommitdiff
path: root/Parser
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-07-06 20:31:16 +0100
committerGitHub <noreply@github.com>2020-07-06 12:31:16 -0700
commit1ac0cbca369f16f9191833dd54536482fb141a98 (patch)
tree1800eafad7ec998d61d6172c13194979b86533d6 /Parser
parentbpo-29778: Ensure python3.dll is loaded from correct locations when Python is... (diff)
downloadcpython-1ac0cbca369f16f9191833dd54536482fb141a98.tar.gz
cpython-1ac0cbca369f16f9191833dd54536482fb141a98.tar.bz2
cpython-1ac0cbca369f16f9191833dd54536482fb141a98.zip
bpo-41215: Don't use NULL by default in the PEG parser keyword list (GH-21355)
Automerge-Triggered-By: @lysnikolaou
Diffstat (limited to 'Parser')
-rw-r--r--Parser/parser.c4
-rw-r--r--Parser/pegen.c7
2 files changed, 7 insertions, 4 deletions
diff --git a/Parser/parser.c b/Parser/parser.c
index bfd5c47caf0..75dc7176a5e 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -9,8 +9,8 @@ extern int Py_DebugFlag;
#endif
static const int n_keyword_lists = 9;
static KeywordToken *reserved_keywords[] = {
- NULL,
- NULL,
+ (KeywordToken[]) {{NULL, -1}},
+ (KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) {
{"if", 510},
{"in", 518},
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 53e3d491383..42f9e0c41bf 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -525,10 +525,13 @@ _PyPegen_dummy_name(Parser *p, ...)
static int
_get_keyword_or_name_type(Parser *p, const char *name, int name_len)
{
- if (name_len >= p->n_keyword_lists || p->keywords[name_len] == NULL) {
+ assert(name_len != 0);
+ if (name_len >= p->n_keyword_lists ||
+ p->keywords[name_len] == NULL ||
+ p->keywords[name_len]->type == -1) {
return NAME;
}
- for (KeywordToken *k = p->keywords[name_len]; k->type != -1; k++) {
+ for (KeywordToken *k = p->keywords[name_len]; k != NULL && k->type != -1; k++) {
if (strncmp(k->str, name, name_len) == 0) {
return k->type;
}