summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2024-03-27 16:14:38 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2024-03-27 16:14:38 (GMT)
commitc60347e32076ccad4ce1fddfbe5612be5d0b2020 (patch)
treea7ff2199d94dc474e599707ee0cc510a5b945798
parent6e4ef7af0d7d94a74983de89b85a772777c282f8 (diff)
downloadtcl-c60347e32076ccad4ce1fddfbe5612be5d0b2020.zip
tcl-c60347e32076ccad4ce1fddfbe5612be5d0b2020.tar.gz
tcl-c60347e32076ccad4ce1fddfbe5612be5d0b2020.tar.bz2
Proposed fix for [edb4b065f4]
-rw-r--r--generic/tclStringObj.c4
-rw-r--r--tests/string.test52
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