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