From d0239074a40630a8db1179cf8c09488a8ecfdd65 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Wed, 16 Oct 2024 11:37:18 -0700 Subject: [PATCH] Fixed erroneous operator== on ZString. --- ZString.cpp | 16 +++------------- ZString.h | 2 +- testing/zstring_test.cpp | 2 ++ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/ZString.cpp b/ZString.cpp index 132b545..b4b2496 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -104,22 +104,12 @@ namespace coreutils { return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) > 0); } - bool ZString::operator==(const ZString &valuex) { - if((valuex.getLength() == 0) && (length != 0)) - return false; + bool ZString::operator==(const ZString valuex) { + if(valuex.getLength() != length) + return false; return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0); } - // bool ZString::operator==(std::string value) { - // if(value.length() != length) - // return false; - // return (strncmp(data, value.c_str(), length) == 0); - // } - -// bool ZString::operator==(const char *valuex) const { -// return (strncmp(data, valuex, length) == 0); -// } - bool ZString::operator!=(const ZString &valuex) const { // if(length != valuex.getLength()) // return false; diff --git a/ZString.h b/ZString.h index 258f574..c332e4a 100644 --- a/ZString.h +++ b/ZString.h @@ -114,7 +114,7 @@ namespace coreutils { bool operator>(const ZString &valuex) const; bool operator<=(const ZString &valuex) const; bool operator>=(const ZString &valuex) const; - bool operator==(const ZString &valuex); + bool operator==(const ZString valuex); bool operator!=(const ZString &valuex) const; bool operator!=(const char *valuex) const; diff --git a/testing/zstring_test.cpp b/testing/zstring_test.cpp index b4d9d66..cc51a68 100644 --- a/testing/zstring_test.cpp +++ b/testing/zstring_test.cpp @@ -105,5 +105,7 @@ int main(int argc, char **argv) { std::cout << "Null assignment" << std::endl; coreutils::ZString test20(NULL); + std::cout << "[" << test20 << "]" << std::endl; + std::cout << "Comparisons with null value: " << (test20 == "true") << std::endl; }