From f4ea9dce90c9a7a284a2e00ffabe5f888cd4e925 Mon Sep 17 00:00:00 2001 From: tony Date: Mon, 5 Oct 2015 20:48:03 +0800 Subject: [PATCH] *fixed a wrong evaluation bug in nested IF statements, thanks to Julien Krief for pointing it out. --- HISTORY | 1 + core/my_basic.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index b15eea7..e0ab3f2 100755 --- a/HISTORY +++ b/HISTORY @@ -3,6 +3,7 @@ Added a LIST collection Added a DICT collection Added TYPE statement Added an mb_get_type_string function +Fixed a wrong evaluation bug in nested IF statements, thanks to Julien Krief for pointing it out Sep. 30 2015 Improved UTF8 string manipulation diff --git a/core/my_basic.c b/core/my_basic.c index 6e47aa4..54cf802 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -79,7 +79,7 @@ extern "C" { /** Macros */ #define _VER_MAJOR 1 #define _VER_MINOR 1 -#define _VER_REVISION 78 +#define _VER_REVISION 79 #define _VER_SUFFIX #define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION)) #define _STRINGIZE(A) _MAKE_STRINGIZE(A) @@ -5272,6 +5272,7 @@ int _skip_if_chunk(mb_interpreter_t* s, _ls_node_t** l) { _ls_node_t* ast = 0; _ls_node_t* tmp = 0; _object_t* obj = 0; + int nested = 0; mb_assert(s && l); @@ -5285,7 +5286,13 @@ int _skip_if_chunk(mb_interpreter_t* s, _ls_node_t** l) { obj = (_object_t*)(ast->data); *l = ast; ast = ast->next; - } while(!_IS_FUNC(obj, _core_if) && !_IS_FUNC(obj, _core_elseif) && !_IS_FUNC(obj, _core_else) && !_IS_FUNC(obj, _core_endif)); + if(_IS_FUNC((_object_t*)(ast->data), _core_if)) { + ++nested; + } else if(nested && _IS_FUNC((_object_t*)(ast->data), _core_endif)) { + --nested; + ast = ast->next; + } + } while(nested || (!_IS_FUNC(obj, _core_elseif) && !_IS_FUNC(obj, _core_else) && !_IS_FUNC(obj, _core_endif))); _exit: return result;