From ce4878e1032a759ae6855ba5672af5db4a76f5b6 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Tue, 5 Jul 2022 20:28:13 -0500 Subject: [PATCH] Fixed off-by-one error in the TString 'pop' function. --- tstring.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tstring.c b/tstring.c index 20ccfd5..16d278a 100644 --- a/tstring.c +++ b/tstring.c @@ -74,10 +74,10 @@ void TStringPop(char buffer[8], TString* string) { if (!string) 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]); - if (width) { + if (width > 0) { //If we've been provided a buffer, then populate it with the glyph we're removing. if (buffer) { memset(buffer, '\0', 8); @@ -132,6 +132,8 @@ void TStringRemoveRange(int startIndex, int count, TString* string) { memcpy(&string->Characters[startByte], buffer, remainder); } + memset(&string->Characters[endByte], '\0', string->ByteCount - endByte); + string->Length -= glyphCount; string->ByteCount -= endByte - startByte; }