Skip to content

Commit 1973be4

Browse files
authored
Merge pull request #2740 from masatake/r-r6class-avoid-entering-infinite-loop
R6class: avoid entering infinite loop
2 parents 59e53e3 + 19bff7a commit 1973be4

File tree

11 files changed

+44
-19
lines changed

11 files changed

+44
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e <- R6Class(public = list({}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# NOTHING HERE
2+
File renamed without changes.

main/tokeninfo.c

+4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ void tokenReadFull (tokenInfo *token, void *data)
108108
tokenDelete (backlog);
109109
}
110110
else
111+
{
111112
token->klass->read (token, data);
113+
if (!tokenIsEOF (token))
114+
token->klass->read_counter++;
115+
}
112116
}
113117

114118
void tokenRead (tokenInfo *token)

main/tokeninfo.h

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ struct tokenInfoClass {
5353
void (*copy) (tokenInfo *dest, tokenInfo *src, void *data);
5454
objPool *pool;
5555
ptrArray *backlog;
56+
57+
/* read_counter is incremented every time when reading a
58+
* new token from the input stream unless the new token is EOF.
59+
*
60+
* When filling a tokenInfo from an entry in the backlog, we don't
61+
* regard it as "reading a new token".
62+
*/
63+
int read_counter;
5664
};
5765

5866
void *newToken (struct tokenInfoClass *klass);

parsers/r-r6class.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ static void parseListMain (rSubparser *s,
130130

131131
rTokenReadNoNewline (token);
132132

133-
while (! (tokenIsEOF (token) || tokenIsTypeVal (token, ')')))
133+
while (! tokenIsTypeVal (token, ')'))
134134
{
135-
rParseStatement (token, classIndex, false);
136-
if (tokenIsTypeVal (token, '\n'))
135+
if (!rParseStatement (token, classIndex, false))
136+
break;
137+
else if (tokenIsTypeVal (token, '\n'))
137138
rTokenReadNoNewline (token);
138139
}
139140
((struct r6Subparser *)s)->access = last_access;

parsers/r-s4class.c

+12-11
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ static void parseRepresentation (rSubparser *s, tokenInfo *const token, int pare
9393
if (tokenIsTypeVal (token, '('))
9494
{
9595
rTokenReadNoNewline (token);
96-
while (!(tokenIsEOF (token)
97-
|| tokenIsTypeVal (token, ')') || tokenIsTypeVal (token, ',')))
96+
while (!(tokenIsTypeVal (token, ')') || tokenIsTypeVal (token, ',')))
9897
{
99-
rParseStatement (token, parent, false);
100-
if (tokenIsTypeVal (token, '\n'))
98+
if (!rParseStatement (token, parent, false))
99+
break;
100+
else if (tokenIsTypeVal (token, '\n'))
101101
rTokenReadNoNewline (token);
102102
}
103103
}
@@ -204,10 +204,11 @@ static bool parseMethodArgs (rSubparser *s, tokenInfo *const token, int parent,
204204
{
205205
rTokenReadNoNewline (token);
206206
/* anonymous function for implementing this method may be here.*/
207-
while (!(tokenIsEOF (token) || tokenIsTypeVal (token, ')')))
207+
while (!tokenIsTypeVal (token, ')'))
208208
{
209-
rParseStatement (token, parent, true);
210-
if (tokenIsTypeVal (token, '\n'))
209+
if (!rParseStatement (token, parent, true))
210+
break;
211+
else if (tokenIsTypeVal (token, '\n'))
211212
rTokenReadNoNewline (token);
212213
}
213214
}
@@ -228,11 +229,11 @@ static bool parseMethodArgs (rSubparser *s, tokenInfo *const token, int parent,
228229
static bool parseGenericArgs (rSubparser *s, tokenInfo *const token, int parent,
229230
tokenInfo *const open_paren)
230231
{
231-
while (!(tokenIsEOF (token)
232-
|| tokenIsTypeVal (token, ')')))
232+
while (!tokenIsTypeVal (token, ')'))
233233
{
234-
rParseStatement (token, parent, true);
235-
if (tokenIsTypeVal (token, '\n'))
234+
if (!rParseStatement (token, parent, true))
235+
break;
236+
else if (tokenIsTypeVal (token, '\n'))
236237
rTokenReadNoNewline (token);
237238
}
238239
return false;

parsers/r.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static struct tokenInfoClass rTokenInfoClass = {
194194
/*
195195
* FUNCTION PROTOTYPES
196196
*/
197-
static void parseStatement (tokenInfo *const token, int parent, bool in_arglist, bool in_continuous_pair);
197+
static bool parseStatement (tokenInfo *const token, int parent, bool in_arglist, bool in_continuous_pair);
198198
static void parsePair (tokenInfo *const token, int parent, tokenInfo *const funcall);
199199

200200
static int notifyReadRightSideSymbol (tokenInfo *const symbol,
@@ -930,10 +930,11 @@ static void parsePair (tokenInfo *const token, int parent, tokenInfo *const func
930930
R_TRACE_LEAVE();
931931
}
932932

933-
static void parseStatement (tokenInfo *const token, int parent,
933+
static bool parseStatement (tokenInfo *const token, int parent,
934934
bool in_arglist, bool in_continuous_pair)
935935
{
936936
R_TRACE_ENTER();
937+
int last_count = rTokenInfoClass.read_counter;
937938

938939
do
939940
{
@@ -1071,13 +1072,16 @@ static void parseStatement (tokenInfo *const token, int parent,
10711072
while (!tokenIsEOF (token));
10721073

10731074
R_TRACE_LEAVE();
1075+
1076+
return (last_count != rTokenInfoClass.read_counter);
10741077
}
10751078

1076-
extern void rParseStatement (tokenInfo *const token, int parentIndex, bool in_arglist)
1079+
extern bool rParseStatement (tokenInfo *const token, int parentIndex, bool in_arglist)
10771080
{
10781081
pushLanguage (Lang_R);
1079-
parseStatement (token, parentIndex, in_arglist, true);
1082+
bool r = parseStatement (token, parentIndex, in_arglist, true);
10801083
popLanguage ();
1084+
return r;
10811085
}
10821086

10831087
static int notifyReadRightSideSymbol (tokenInfo *const symbol,

parsers/r.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ extern void rTeardownCollectingSignature (tokenInfo *const token);
9797
*/
9898

9999
extern void rTokenReadNoNewline (tokenInfo *const token);
100-
extern void rParseStatement (tokenInfo *const token, int parentIndex, bool inArgList);
100+
101+
/* This function returns true if a new token is read.
102+
* EOF is exception. If EOF is read, this function returns FALSE. */
103+
extern bool rParseStatement (tokenInfo *const token, int parentIndex, bool inArgList);
104+
101105
extern vString *rExtractNameFromString (vString* str);
102106

103107
#endif /* CTAGS_PARSER_TEX_H */

0 commit comments

Comments
 (0)