From: Igor Sysoev Date: Mon, 8 Feb 2016 15:18:24 +0000 (+0300) Subject: Segfault has been fixed when "if" operator has an empty "then" X-Git-Tag: 0.1.0~72 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=2017c344b2ccf57e5d525317f646ad8a2b800121;p=njs.git Segfault has been fixed when "if" operator has an empty "then" branch. --- diff --git a/njs/njs_generator.c b/njs/njs_generator.c index 305521c0..f5680cf9 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -361,7 +361,7 @@ njs_generate_if_statement(njs_vm_t *vm, njs_parser_t *parser, previous = (u_char *) cond_jump; label = &cond_jump->offset; - if (node->right->token == NJS_TOKEN_BRANCHING) { + if (node->right != NULL && node->right->token == NJS_TOKEN_BRANCHING) { /* The "then" branch in a case of "if/then/else" statement. */ diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 176d30d3..ceb17dda 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -1387,13 +1387,30 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a \n if (!a) a = 3; a"), nxt_string("3") }, - { nxt_string("a = 1; if (true) a = 2; else a = 3; a"), + /* if. */ + + { nxt_string("if (0);"), + nxt_string("undefined") }, + + { nxt_string("if (0) {}"), + nxt_string("undefined") }, + + { nxt_string("if (0);else;"), + nxt_string("undefined") }, + + { nxt_string("var a = 1; if (true); else a = 2; a"), + nxt_string("1") }, + + { nxt_string("var a = 1; if (false); else a = 2; a"), + nxt_string("2") }, + + { nxt_string("var a = 1; if (true) a = 2; else a = 3; a"), nxt_string("2") }, - { nxt_string("a = 3; if (true) if (false); else a = 2; a"), + { nxt_string("var a = 3; if (true) if (false); else a = 2; a"), nxt_string("2") }, - { nxt_string("a = 3; if (true) if (false); else; a = 2; a"), + { nxt_string("var a = 3; if (true) if (false); else; a = 2; a"), nxt_string("2") }, /* switch. */