Skip to content

Commit

Permalink
fix segfault on column number 0; support negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-martian committed Jun 25, 2024
1 parent afeae77 commit dae5c8f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lexdcompiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ LexdCompiler::finishLexicon()
die("Lexicon '%S' is empty.", err(name(currentLexiconId)));
}
appendLexicon(currentLexiconId, currentLexicon);

currentLexicon.clear();
currentLexicon_tags.clear();
}
Expand Down Expand Up @@ -632,6 +632,7 @@ LexdCompiler::readToken(char_iter& iter, UnicodeString& line)
if(iter.span().first == begin_charspan.first)
die("Syntax error - missing index in parenthesis");
part = (unsigned int)StringUtils::stoi(to_ustring(line.tempSubStringBetween(begin_charspan.first, iter.span().first)));
if (part == 0) die("Invalid column number (0)");
++iter;
}

Expand Down
14 changes: 13 additions & 1 deletion tests/feature/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ tests = \

sources = $(foreach test,$(tests),test-$(test).lexd)

check: $(foreach src,$(sources),$(O)/$(src).txt.strings.check)
check-pos: $(foreach src,$(sources),$(O)/$(src).txt.strings.check)

negtests = \
col0 \

negsources = $(foreach test,$(negtests),negtest-$(test).lexd)

check-neg: $(foreach src,$(negsources),$(O)/$(src).txt.error)

check: check-pos check-neg

O=.

Expand All @@ -54,6 +63,9 @@ $(O)/%.strings.diff: $(O)/%.strings %.strings.gold
diff -U0 $^ > $@; [ $$? != 2 ]
$(O)/%.strings.check: $(O)/%.strings.diff
[ -s "$<" ] && cat "$<" && exit 1; touch $@
$(O)/%.lexd.txt.error: ../../src/lexd %.lexd | $(O)
$^ $(LEXD_TEST_FLAGS) > /dev/null 2> $@; [ $$? = 1 ]
clean:
rm $(foreach src,$(sources),$(O)/$(src).txt.strings.check)
rm $(foreach src,$(negsources),$(O)/$(src).txt.error)
rmdir $(O)
5 changes: 5 additions & 0 deletions tests/feature/negtest-col0.lexd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PATTERNS
X(0)

LEXICON X
a:b

0 comments on commit dae5c8f

Please sign in to comment.