cinera.c: Fix buffer sizing crash bug

This commit is contained in:
Matt Mascarenhas 2020-05-10 16:56:37 +01:00
parent 3728c8aaee
commit f20a35e0de
1 changed files with 10 additions and 9 deletions

View File

@ -17,7 +17,7 @@ typedef struct
version CINERA_APP_VERSION = { version CINERA_APP_VERSION = {
.Major = 0, .Major = 0,
.Minor = 7, .Minor = 7,
.Patch = 2 .Patch = 3
}; };
#include <stdarg.h> // NOTE(matt): varargs #include <stdarg.h> // NOTE(matt): varargs
@ -12113,12 +12113,13 @@ CloseNodeNewLine(buffer *B, uint32_t *IndentationLevel, html_element_id Element)
AppendStringToBuffer(B, Wrap0(">")); AppendStringToBuffer(B, Wrap0(">"));
} }
string string
StripFromStringStart(string From, string Strip) TrimString(string S, uint32_t CharsFromStart, uint32_t CharsFromEnd)
{ {
string Result = From; string Result = S;
Result.Base += Strip.Length; Result.Length -= (CharsFromStart + CharsFromEnd);
Result.Length -= Strip.Length; Result.Base += CharsFromStart;
return Result; return Result;
} }
@ -12203,11 +12204,11 @@ GenerateIndexOfProjectAndChildren(buffer *Index, db_header_project *StoredP, pro
if(*StoredP->Unit) if(*StoredP->Unit)
{ {
// TODO(matt): That rigorous notion of numbering, goddammit?! // TODO(matt): That rigorous notion of numbering, goddammit?!
char Number[16] = {}; string NumberL = TrimString(Wrap0i(Entry->HMMLBaseFilename, sizeof(Entry->HMMLBaseFilename)),
string NumberL = StripFromStringStart(Wrap0i(Entry->HMMLBaseFilename, sizeof(Entry->HMMLBaseFilename)), P->ID.Length, 0);
P->ID); char Number[NumberL.Length + 1];
ClearCopyStringNoFormat(Number, sizeof(Number), NumberL);
CopyStringNoFormat(Number, sizeof(Number), NumberL);
if(CurrentProject->NumberingScheme == NS_LINEAR) if(CurrentProject->NumberingScheme == NS_LINEAR)
{ {
for(int i = 0; Number[i]; ++i) for(int i = 0; Number[i]; ++i)