Fixed off-by-one error in the TString 'pop' function.

This commit is contained in:
2022-07-05 20:28:13 -05:00
parent 0a61197cb6
commit ce4878e103
+4 -2
View File
@@ -74,10 +74,10 @@ void TStringPop(char buffer[8], TString* string) {
if (!string) return; if (!string) return;
if (string->ByteCount == 0) return; if (string->ByteCount == 0) return;
for (int i = string->ByteCount; i >= 0; i--) { for (int i = string->ByteCount - 1; i >= 0; i--) {
unsigned int width = GetGlyphByteWidth(string->Characters[i]); unsigned int width = GetGlyphByteWidth(string->Characters[i]);
if (width) { if (width > 0) {
//If we've been provided a buffer, then populate it with the glyph we're removing. //If we've been provided a buffer, then populate it with the glyph we're removing.
if (buffer) { if (buffer) {
memset(buffer, '\0', 8); memset(buffer, '\0', 8);
@@ -132,6 +132,8 @@ void TStringRemoveRange(int startIndex, int count, TString* string) {
memcpy(&string->Characters[startByte], buffer, remainder); memcpy(&string->Characters[startByte], buffer, remainder);
} }
memset(&string->Characters[endByte], '\0', string->ByteCount - endByte);
string->Length -= glyphCount; string->Length -= glyphCount;
string->ByteCount -= endByte - startByte; string->ByteCount -= endByte - startByte;
} }