diff --git a/src/futil.c b/src/futil.c index 890cf76..2fb1f33 100644 --- a/src/futil.c +++ b/src/futil.c @@ -11,7 +11,7 @@ int ReadAllString(const char* path, char** content_ptr, size_t* bytes_read) { } char *content = NULL, *temp; - size_t used = 0, capacity = 0, read = 0; //Allows initialize stack allocated values to zero! + size_t used = 0, capacity = 0, read = 0; //Always initialize stack allocated values to zero! while(1) { if (used + FUTIL_READ_SIZE + 1 > capacity) { diff --git a/src/tstring.c b/src/tstring.c index 4267db1..35f70cd 100644 --- a/src/tstring.c +++ b/src/tstring.c @@ -128,15 +128,16 @@ void TStringRemoveRange(int startIndex, int count, TString* string) { } if (remainder > 0) { + memset(buffer, 0, sizeof buffer); memcpy(buffer, &string->Characters[string->ByteCount - remainder], remainder); printf("Buffer: %s\n", buffer); memcpy(&string->Characters[startByte + fullBuffers * sizeof buffer], buffer, remainder); } - memset(&string->Characters[string->ByteCount - endByte - startByte], '\0', endByte - startByte); - string->Length -= glyphCount; - string->ByteCount -= endByte - startByte; + string->ByteCount -= endByte - startByte; + + memset(&string->Characters[string->ByteCount], '\0', string->Capacity - string->ByteCount); } void TStringInsertText(const char* text, int index, TString* string) {