Skip to content

Commit

Permalink
t_look should return -1 on miss, as 0 is a valid index
Browse files Browse the repository at this point in the history
  • Loading branch information
marcioAlmada committed Mar 22, 2015
1 parent 041c6ec commit bfd0279
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions ext/tokenizer/tokenizer.c
Expand Up @@ -193,8 +193,7 @@ static int t_look(zend_bool ahead, zval *tokens, int index, int attempts)
int token_type,
length = zend_hash_num_elements(Z_ARRVAL_P(tokens));

while(attempts && (index < length)) {
(ahead) ? ++index : --index;
while(attempts && ((ahead ? ++index : --index) < length)) {
switch (token_type = t_get_type(tokens, index)) {
case T_WHITESPACE: case T_COMMENT: case T_DOC_COMMENT:
break;
Expand All @@ -206,7 +205,7 @@ static int t_look(zend_bool ahead, zval *tokens, int index, int attempts)
}
}

return 0;
return -1;
}

static zend_always_inline void t_stringify(zval *tokens, int index)
Expand All @@ -219,12 +218,12 @@ static zend_always_inline void t_stringify(zval *tokens, int index)

static zend_always_inline void t_stringify_next(zval *tokens, int index, int attempts)
{
if((index = t_look(1, tokens, index, attempts))) t_stringify(tokens, index);
if(-1 != (index = t_look(1, tokens, index, attempts))) t_stringify(tokens, index);
}

static zend_always_inline void t_stringify_previous(zval *tokens, int index, int attempts)
{
if((index = t_look(0, tokens, index, attempts))) t_stringify(tokens, index);
if(-1 != (index = t_look(0, tokens, index, attempts))) t_stringify(tokens, index);
}

static void t_parse(zval *tokens)
Expand Down

0 comments on commit bfd0279

Please sign in to comment.