Fixed NULL assignment to ZString.

This commit is contained in:
Brad Arant 2024-10-16 11:15:54 -07:00
parent 8648ab3152
commit 34e2ca0566
2 changed files with 16 additions and 3 deletions

View File

@ -33,8 +33,18 @@ namespace coreutils {
cursor = data;
}
ZString::ZString(const char *data) : data((char *)data), length(strlen(data)), cursor((char *)data) {}
ZString::ZString(const char *data) {
if((char *)data != NULL) {
this->data = (char *)data;
this->length = strlen(data);
this->cursor = (char *)data;
} else {
this->data = NULL;
this->length = 0;
this->cursor = NULL;
}
}
ZString::ZString(char *data, size_t length) : data(data), length(length), cursor(data) {}
ZString::ZString(unsigned char *data, size_t length) : data((char *)data), length(length), cursor((char *)data) {}

View File

@ -84,7 +84,7 @@ int main(int argc, char **argv) {
coreutils::ZString test14("25.5");
coreutils::ZString test15("xyx");
std::cout << test14.startsWithDouble() << ":" << test15.startsWithDouble() << std::endl;
std::cout << test14.startsWithNumber() << ":" << test15.startsWithNumber() << std::endl;
coreutils::ZString test16("This is a test of substring");
std::cout << test16.substring(10) << std::endl;
@ -102,5 +102,8 @@ int main(int argc, char **argv) {
coreutils::ZString test19("1,");
std::cout << test19.asDouble() << ":" << test19.unparsed() << std::endl;
std::cout << "Null assignment" << std::endl;
coreutils::ZString test20(NULL);
}