From cf68aae5dfd819ceba984649bf017853c306639f Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Wed, 6 Jul 2022 07:09:40 +0900 Subject: [PATCH] JavaScript: avoid assertion failures when making an empty tag Related to #900, #1112, and #3427. When the parser tries making a tag with empty name, an assertion in registerEntry fails. The parser side should be fixed but it will take a time. This change puts guard conditions around registerEntry to avoid the failures. THIS IS A TEMPORARILY SOLUTION. Signed-off-by: Masatake YAMATO --- .../parser-javascript.r/tagging-empty-name.d/README | 2 ++ .../tagging-empty-name.d/input.js | 1 + parsers/jscript.c | 12 ++++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 Units/parser-javascript.r/tagging-empty-name.d/README create mode 100644 Units/parser-javascript.r/tagging-empty-name.d/input.js diff --git a/Units/parser-javascript.r/tagging-empty-name.d/README b/Units/parser-javascript.r/tagging-empty-name.d/README new file mode 100644 index 0000000000..f6ba959835 --- /dev/null +++ b/Units/parser-javascript.r/tagging-empty-name.d/README @@ -0,0 +1,2 @@ +This is a crash test. +See #900, #1112, and #3427. diff --git a/Units/parser-javascript.r/tagging-empty-name.d/input.js b/Units/parser-javascript.r/tagging-empty-name.d/input.js new file mode 100644 index 0000000000..aaae4e1105 --- /dev/null +++ b/Units/parser-javascript.r/tagging-empty-name.d/input.js @@ -0,0 +1 @@ +const diff --git a/parsers/jscript.c b/parsers/jscript.c index 1c4103c432..c22d0514ca 100644 --- a/parsers/jscript.c +++ b/parsers/jscript.c @@ -474,7 +474,11 @@ static int makeJsRefTagsForNameChain (char *name_chain, const tokenInfo *token, e.extensionFields.scopeIndex = scope; index = makeTagEntry (&e); - registerEntry (index); + /* We shold remove This condition. We should fix the callers passing + * an empty name instead. makeTagEntry() returns CORK_NIL if the tag + * name is empty. */ + if (index != CORK_NIL) + registerEntry (index); } return next @@ -556,7 +560,11 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind, markTagExtraBit (&e, XTAG_ANONYMOUS); index = makeTagEntry (&e); - registerEntry (index); + /* We shold remove This condition. We should fix the callers passing + * an empty name instead. makeTagEntry() returns CORK_NIL if the tag + * name is empty. */ + if (index != CORK_NIL) + registerEntry (index); return index; }