From 0ebe8eaf5bcf801c203041383eff4fcdb728cc6b Mon Sep 17 00:00:00 2001 From: barant Date: Mon, 23 Dec 2024 11:15:53 -0800 Subject: [PATCH] cleanup for valgrind. --- File.cpp | 2 +- ZString.cpp | 14 ++++++++++---- ZString.h | 8 ++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/File.cpp b/File.cpp index 962be11..51a43f6 100644 --- a/File.cpp +++ b/File.cpp @@ -34,7 +34,7 @@ namespace coreutils { File::~File() { close(fd); - setBufferSize(0); + free(buffer); } void File::setBufferSize(size_t size) { diff --git a/ZString.cpp b/ZString.cpp index 4acd788..4efef4c 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -66,8 +66,10 @@ namespace coreutils { } ZString::~ZString() { - if(cdata != NULL) - free(cdata); + if(cdata != NULL) { + std::cout << "********" << cdata << "********" << strlen(cdata) << std::endl; + free(cdata); + } } bool ZString::operator<(const ZString &valuex) const { @@ -443,8 +445,12 @@ namespace coreutils { } int ZString::skipWhitespace() { - int len = strspn(cursor, " \n\t"); - cursor += len; + char *end = data + length; + int len = 0; + while((cursor < end) && ((*cursor == ' ') || (*cursor == '\n') || (*cursor == '\t'))) { + ++cursor; + ++len; + } return len; } diff --git a/ZString.h b/ZString.h index 029e0f4..978d338 100644 --- a/ZString.h +++ b/ZString.h @@ -84,7 +84,7 @@ namespace coreutils { /// Destructor for the ZString. /// - ~ZString(); + virtual ~ZString(); /// /// A friend method used to write the value of the ZString @@ -454,9 +454,9 @@ namespace coreutils { void moveBackToLineStart(); protected: - char *data; - char *cursor; - size_t length; + char *data = NULL; + char *cursor = NULL; + size_t length = 0; char *cdata = NULL; std::vector list;