diff --git a/src/Common/TString.h b/src/Common/TString.h index 93c776cd..52819624 100644 --- a/src/Common/TString.h +++ b/src/Common/TString.h @@ -229,7 +229,7 @@ public: _TString Trimmed() const { - int start, end; + int start = -1, end = -1; for (u32 iChar = 0; iChar < Size(); iChar++) { @@ -240,6 +240,9 @@ public: } } + // If start is still -1 then there are no non-whitespace characters in this string. Return early. + if (start == -1) return ""; + for (int iChar = Size() - 1; iChar >= 0; iChar--) { if (!IsWhitespace(mInternalString[iChar])) @@ -259,11 +262,13 @@ public: inline _TString ChopFront(u32 amount) const { + if (Size() <= amount) return ""; return SubString(amount, Size() - amount); } inline _TString ChopBack(u32 amount) const { + if (Size() <= amount) return ""; return SubString(0, Size() - amount); } @@ -712,14 +717,14 @@ public: } // Static - static TBasicString FromInt32(u32 value, int width = 0, int base = 16) + static TBasicString FromInt32(s32 value, int width = 0, int base = 16) { std::basic_stringstream sstream; sstream << std::setbase(base) << std::setw(width) << std::setfill('0') << value; return sstream.str(); } - static TBasicString FromInt64(u64 value, int width = 0, int base = 16) + static TBasicString FromInt64(s64 value, int width = 0, int base = 16) { std::basic_stringstream sstream; sstream << std::setbase(base) << std::setw(width) << std::setfill('0') << value; diff --git a/src/FileIO/CTextInStream.cpp b/src/FileIO/CTextInStream.cpp index 45d6f69f..d2a7fbdb 100644 --- a/src/FileIO/CTextInStream.cpp +++ b/src/FileIO/CTextInStream.cpp @@ -2,6 +2,11 @@ #include #include +CTextInStream::CTextInStream() +{ + mpFStream = nullptr; +} + CTextInStream::CTextInStream(const std::string& rkFile) { mpFStream = nullptr;