Welcome! Log In Create A New Profile

Advanced

[njs] Removed unnecessary NULL checks introduced in 86f55a7dc4a4.

Alexander Borisov
June 01, 2020 11:12AM
details: https://hg.nginx.org/njs/rev/c37e682982b1
branches:
changeset: 1410:c37e682982b1
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Mon Jun 01 18:09:28 2020 +0300
description:
Removed unnecessary NULL checks introduced in 86f55a7dc4a4.

Found by Clang static analyzer.

diffstat:

src/njs_parser.c | 20 +++++++-------------
src/test/njs_unit_test.c | 3 +--
2 files changed, 8 insertions(+), 15 deletions(-)

diffs (50 lines):

diff -r c9f07d5eef98 -r c37e682982b1 src/njs_parser.c
--- a/src/njs_parser.c Mon Jun 01 18:09:27 2020 +0300
+++ b/src/njs_parser.c Mon Jun 01 18:09:28 2020 +0300
@@ -1929,7 +1929,7 @@ njs_parser_property_definition_after(njs

proto_init = 0;

- if (property != NULL && property->index != NJS_TOKEN_OPEN_BRACKET
+ if (property->index != NJS_TOKEN_OPEN_BRACKET
&& njs_is_string(&property->u.value))
{
njs_string_get(&property->u.value, &name);
@@ -3891,18 +3891,12 @@ njs_parser_coalesce_expression(njs_parse
return njs_parser_stack_pop(parser);
}

- if (node != NULL) {
- type = node->token_type;
-
- if (parser->lexer->prev_type != NJS_TOKEN_CLOSE_PARENTHESIS
- && (type == NJS_TOKEN_LOGICAL_OR || type == NJS_TOKEN_LOGICAL_AND))
- {
- njs_parser_syntax_error(parser, "Either \"??\" or \"%s\" "
- "expression must be parenthesized",
- (type == NJS_TOKEN_LOGICAL_OR) ? "||"
- : "&&");
- return NJS_DONE;
- }
+ type = node->token_type;
+
+ if (parser->lexer->prev_type != NJS_TOKEN_CLOSE_PARENTHESIS
+ && (type == NJS_TOKEN_LOGICAL_OR || type == NJS_TOKEN_LOGICAL_AND))
+ {
+ return njs_parser_failed(parser);
}

njs_lexer_consume_token(parser->lexer, 1);
diff -r c9f07d5eef98 -r c37e682982b1 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Mon Jun 01 18:09:27 2020 +0300
+++ b/src/test/njs_unit_test.c Mon Jun 01 18:09:28 2020 +0300
@@ -1344,8 +1344,7 @@ static njs_unit_test_t njs_test[] =
njs_str("false") },

{ njs_str("1 && 1 ?? true"),
- njs_str("SyntaxError: Either \"??\" or \"&&\" expression "
- "must be parenthesized in 1") },
+ njs_str("SyntaxError: Unexpected token \"??\" in 1") },

{ njs_str("null ?? 0 || 1"),
njs_str("SyntaxError: Unexpected token \"||\" in 1") },
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Removed unnecessary NULL checks introduced in 86f55a7dc4a4.

Alexander Borisov 187 June 01, 2020 11:12AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 315
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready