Skip to content

Commit

Permalink
Merge pull request universal-ctags#1757 from masatake/readtags--handl…
Browse files Browse the repository at this point in the history
…ing-broken-input

readtags: handle broken input patterns
  • Loading branch information
masatake authored May 23, 2018
2 parents bf8aa43 + 481f026 commit 0b0c73f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions Tmain/readtags-broken-input.d/exit-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
21 changes: 21 additions & 0 deletions Tmain/readtags-broken-input.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# Copyright: 2018 Masatake YAMATO
# License: GPL-2

READTAGS=$3
#V="valgrind --leak-check=full --track-origins=yes -v"
V=

. ../utils.sh

if ! [ -x "${READTAGS}" ]; then
skip "no readtags"
fi

for i in 1 2 3 4 5 6; do
${V} ${READTAGS} -t ./target.tags - greet${i} > /dev/null || exit 1
done

${READTAGS} -t ./target.tags - greetA
${READTAGS} -t ./target.tags - greetB
Empty file.
2 changes: 2 additions & 0 deletions Tmain/readtags-broken-input.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
greetA input.java /^ public void greet (String word) {$/
greetB input.java ?^ public void greet (String word) {$?
8 changes: 8 additions & 0 deletions Tmain/readtags-broken-input.d/target.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
greet1 input.java /^ public void greet (String word) {$;" m line:9 method:input.hello.anonXXX
greetA input.java /^ public void greet (String word) {$/;" m line:9 method:input.hello.anonXXX
greet2 input.java k:v
greet3 input.java
greet4 input.java
greet5
greetB input.java ?^ public void greet (String word) {$?;" m line:9 method:input.hello.anonXXX
greet6 input.java ?^ public void greet (String word) {$;" m line:9 method:input.hello.anonXXX
19 changes: 10 additions & 9 deletions read/readtags.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct sTagFile {
/* defines tag search state */
struct {
/* file position of last match for tag */
off_t pos;
off_t pos;
/* name of tag last searched for */
char *name;
/* length of name for partial matches */
Expand Down Expand Up @@ -403,10 +403,7 @@ static void parseTagLine (tagFile *file, tagEntry *const entry)
size_t p_len = strlen (p);
char *tab = strchr (p, TAB);

entry->fields.list = NULL;
entry->fields.count = 0;
entry->kind = NULL;
entry->fileScope = 0;
memset(entry, 0, sizeof(*entry));

entry->name = p;
if (tab != NULL)
Expand Down Expand Up @@ -471,10 +468,14 @@ static void parseTagLine (tagFile *file, tagEntry *const entry)
{
/* invalid pattern */
}
fieldsPresent = (strncmp (p, ";\"", 2) == 0);
*p = '\0';
if (fieldsPresent)
parseExtensionFields (file, entry, p + 2);

if (p)
{
fieldsPresent = (strncmp (p, ";\"", 2) == 0);
*p = '\0';
if (fieldsPresent)
parseExtensionFields (file, entry, p + 2);
}
}
}
if (entry->fields.count > 0)
Expand Down

0 comments on commit 0b0c73f

Please sign in to comment.