From 304de510732b5bf301c6d97ca26f876dca26886e Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 1 Feb 2017 14:42:48 +0000 Subject: Fix [d0f7ba56f0e8f93b7efb5b09ebc30a824bdd577a|d0f7ba56f0]: INST_EQ first-argument NaN shortcut is too aggressive --- generic/tclExecute.c | 22 ++++------------------ tests/expr.test | 9 +++++++++ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/generic/tclExecute.c b/generic/tclExecute.c index bfb9d17..608b420 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -4496,16 +4496,17 @@ TclExecuteByteCode( Tcl_WideInt w1, w2; #endif - if (GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK) { + if (GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK + || GetNumberFromObj(NULL, value2Ptr, &ptr2, &type2) != TCL_OK) { /* * At least one non-numeric argument - compare as strings. */ goto stringCompare; } - if (type1 == TCL_NUMBER_NAN) { + if (type1 == TCL_NUMBER_NAN || type2 == TCL_NUMBER_NAN) { /* - * NaN first arg: NaN != to everything, other compares are false. + * NaN arg: NaN != to everything, other compares are false. */ iResult = (*pc == INST_NEQ); @@ -4515,21 +4516,6 @@ TclExecuteByteCode( compare = MP_EQ; goto convertComparison; } - if (GetNumberFromObj(NULL, value2Ptr, &ptr2, &type2) != TCL_OK) { - /* - * At least one non-numeric argument - compare as strings. - */ - - goto stringCompare; - } - if (type2 == TCL_NUMBER_NAN) { - /* - * NaN 2nd arg: NaN != to everything, other compares are false. - */ - - iResult = (*pc == INST_NEQ); - goto foundResult; - } switch (type1) { case TCL_NUMBER_LONG: l1 = *((const long *)ptr1); diff --git a/tests/expr.test b/tests/expr.test index bd5ed8f..3a69407 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -910,6 +910,15 @@ test expr-22.9 {non-numeric floats: shared object equality and NaN} { set x NaN expr {$x == $x} } 0 +# Make sure [Bug d0f7ba56f0] stays fixed. +test expr-22.10 {non-numeric arguments: equality and NaN} { + set x NaN + expr {$x > "Gran"} +} 1 +test expr-22.11 {non-numeric arguments: equality and NaN} { + set x NaN + expr {"Gran" < $x} +} 1 # Tests for exponentiation handling test expr-23.1 {CompileExponentialExpr: just exponential expr} {expr 4**2} 16 -- cgit v0.12