From bfd0279e84c283790161cf8ed9e0bdceb5b90836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Almada?= Date: Sun, 22 Mar 2015 00:16:03 -0300 Subject: [PATCH] t_look should return -1 on miss, as 0 is a valid index --- ext/tokenizer/tokenizer.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c index 4701a2f77465d..d613b59d649dd 100644 --- a/ext/tokenizer/tokenizer.c +++ b/ext/tokenizer/tokenizer.c @@ -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; @@ -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) @@ -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)