From 6e4ef7af0d7d94a74983de89b85a772777c282f8 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Wed, 27 Mar 2024 15:46:06 +0000 Subject: Tests for [edb4b065f49] crash. --- tests/string.test | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/string.test b/tests/string.test index 26cd8a7..1a0ac05 100644 --- a/tests/string.test +++ b/tests/string.test @@ -228,6 +228,15 @@ test string-2.36.$noComp {string compare, binary neq unequal length} { test string-2.37.$noComp {string compare with -length >= 2^32} { run {string compare -length 4294967296 ab abde} } -1 +test string-bug-edb4b065f4-1 {string compare empty string against byte array} { + string compare "" [binary decode hex 00] +} -1 +test string-bug-edb4b065f4-2 {string compare -length empty string against byte array} { + string compare -length 1 "" [binary decode hex 00] +} -1 +test string-bug-edb4b065f4-3 {string compare -nocase empty string against byte array} { + string compare -nocase "" [binary decode hex 00] +} -1 # only need a few tests on equal, since it uses the same code as # string compare, but just modifies the return output -- cgit v0.12 From c60347e32076ccad4ce1fddfbe5612be5d0b2020 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Wed, 27 Mar 2024 16:14:38 +0000 Subject: Proposed fix for [edb4b065f4] --- generic/tclStringObj.c | 4 ++-- tests/string.test | 52 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 5fe6ef7..ee2eaae 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -3717,7 +3717,7 @@ TclStringCmp( if (empty > 0) { switch (TclCheckEmptyString(value2Ptr)) { case -1: - s1 = 0; + s1 = ""; s1len = 0; s2 = TclGetStringFromObj(value2Ptr, &s2len); break; @@ -3732,7 +3732,7 @@ TclStringCmp( } else if (TclCheckEmptyString(value2Ptr) > 0) { switch (empty) { case -1: - s2 = 0; + s2 = ""; s2len = 0; s1 = TclGetStringFromObj(value1Ptr, &s1len); break; diff --git a/tests/string.test b/tests/string.test index 1a0ac05..4ae200b 100644 --- a/tests/string.test +++ b/tests/string.test @@ -228,15 +228,30 @@ test string-2.36.$noComp {string compare, binary neq unequal length} { test string-2.37.$noComp {string compare with -length >= 2^32} { run {string compare -length 4294967296 ab abde} } -1 -test string-bug-edb4b065f4-1 {string compare empty string against byte array} { - string compare "" [binary decode hex 00] +test string-2.38.$noComp {string compare empty string against byte array} { + # Bug edb4b065f4 + run {string compare "" [binary decode hex 00]} } -1 -test string-bug-edb4b065f4-2 {string compare -length empty string against byte array} { - string compare -length 1 "" [binary decode hex 00] +test string-2.38.$noComp {string compare -length empty string against byte array} { + # Bug edb4b065f4 + run {string compare -length 1 "" [binary decode hex 00]} } -1 -test string-bug-edb4b065f4-3 {string compare -nocase empty string against byte array} { - string compare -nocase "" [binary decode hex 00] +test string-2.38.$noComp {string compare -nocase empty string against byte array} { + # Bug edb4b065f4 + run {string compare -nocase "" [binary decode hex 00]} } -1 +test string-2.38.$noComp {string compare empty string against byte array} { + # Bug edb4b065f4 + run {string compare [binary decode hex 00] ""} +} 1 +test string-2.38.$noComp {string compare -length empty string against byte array} { + # Bug edb4b065f4 + run {string compare -length 1 [binary decode hex 00] ""} +} 1 +test string-2.38.$noComp {string compare -nocase empty string against byte array} { + # Bug edb4b065f4 + run {string compare -nocase [binary decode hex 00] ""} +} 1 # only need a few tests on equal, since it uses the same code as # string compare, but just modifies the return output @@ -383,6 +398,31 @@ test string-3.43.$noComp {string equal, big -length} { test string-3.44.$noComp {string equal, bigger -length} -body { run {string equal -length 18446744073709551616 abc def} } -returnCodes 1 -result {integer value too large to represent} +test string-3.45.$noComp {string equal empty string against byte array} { + # Bug edb4b065f4 + run {string equal "" [binary decode hex 00]} +} 0 +test string-3.45.$noComp {string equal -length empty string against byte array} { + # Bug edb4b065f4 + run {string equal -length 1 "" [binary decode hex 00]} +} 0 +test string-3.45.$noComp {string equal -nocase empty string against byte array} { + # Bug edb4b065f4 + run {string equal -nocase "" [binary decode hex 00]} +} 0 +test string-3.45.$noComp {string equal empty string against byte array} { + # Bug edb4b065f4 + run {string equal [binary decode hex 00] ""} +} 0 +test string-3.45.$noComp {string equal -length empty string against byte array} { + # Bug edb4b065f4 + run {string equal -length 1 [binary decode hex 00] ""} +} 0 +test string-3.45.$noComp {string equal -nocase empty string against byte array} { + # Bug edb4b065f4 + run {string equal -nocase [binary decode hex 00] ""} +} 0 + test string-4.1.$noComp {string first, not enough args} { list [catch {run {string first a}} msg] $msg -- cgit v0.12