From ace6c94c46f2f9a59337de70c24c88b6caa420bd Mon Sep 17 00:00:00 2001 From: Martin Stjernholm <mast@lysator.liu.se> Date: Tue, 15 Mar 2011 02:07:34 +0100 Subject: [PATCH] Safer way to test for another null value in Null.`==. --- src/builtin.cmod | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/builtin.cmod b/src/builtin.cmod index 1041a96d30..41f95e62e5 100644 --- a/src/builtin.cmod +++ b/src/builtin.cmod @@ -3746,8 +3746,23 @@ PIKECLASS Null push_int(0); return; } + + /* Look for the is_val_null constant directly in the program of + * other, without going through its `[]. When this is called in a + * codec, other can be a completely arbitrary object which may not + * have a `[] that works in that context. */ + push_int (0); + ref_push_program (other->u.object->prog); push_constant_text("is_val_null"); - o_index(); + if (program_index_no_free (Pike_sp - 3, Pike_sp - 2, Pike_sp - 1) && + Pike_sp[-3].type == T_INT && Pike_sp[-3].u.integer) { + pop_n_elems (4); + push_int (1); + } + else { + pop_n_elems (4); + push_int (0); + } } /*! @decl string encode_json() -- GitLab