Welcome! Log In Create A New Profile

Advanced

[njs] Fixed equality operator with "null" value as right operand.

Valentin Bartenev
November 09, 2018 10:08AM
details: http://hg.nginx.org/njs/rev/abec5f8d55a1
branches:
changeset: 644:abec5f8d55a1
user: Valentin Bartenev <vbart@nginx.com>
date: Fri Nov 09 18:05:39 2018 +0300
description:
Fixed equality operator with "null" value as right operand.

diffstat:

njs/njs_vm.c | 9 +++++++--
njs/test/njs_unit_test.c | 3 +++
2 files changed, 10 insertions(+), 2 deletions(-)

diffs (33 lines):

diff -r c5a3ac902bc2 -r abec5f8d55a1 njs/njs_vm.c
--- a/njs/njs_vm.c Thu Nov 08 16:45:54 2018 +0300
+++ b/njs/njs_vm.c Fri Nov 09 18:05:39 2018 +0300
@@ -1519,9 +1519,14 @@ njs_vmcode_not_equal(njs_vm_t *vm, njs_v
static nxt_noinline njs_ret_t
njs_values_equal(njs_vm_t *vm, const njs_value_t *val1, const njs_value_t *val2)
{
+ nxt_bool_t nv1, nv2;
+
+ nv1 = njs_is_null_or_void(val1);
+ nv2 = njs_is_null_or_void(val2);
+
/* Void and null are equal and not comparable with anything else. */
- if (njs_is_null_or_void(val1)) {
- return (njs_is_null_or_void(val2));
+ if (nv1 || nv2) {
+ return (nv1 && nv2);
}

if (njs_is_numeric(val1) && njs_is_numeric(val2)) {
diff -r c5a3ac902bc2 -r abec5f8d55a1 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu Nov 08 16:45:54 2018 +0300
+++ b/njs/test/njs_unit_test.c Fri Nov 09 18:05:39 2018 +0300
@@ -1025,6 +1025,9 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("null == false"),
nxt_string("false") },

+ { nxt_string("0 == null"),
+ nxt_string("false") },
+
{ nxt_string("!null"),
nxt_string("true") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed equality operator with "null" value as right operand.

Valentin Bartenev 276 November 09, 2018 10:08AM



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

Online Users

Guests: 313
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