cinera.c: Fix segfault on partial hmmlib1 credit

This commit is contained in:
Matt Mascarenhas 2021-06-07 13:19:03 +01:00
parent b0501d20ac
commit 07795b7cbd
1 changed files with 30 additions and 15 deletions

View File

@ -23,7 +23,7 @@ typedef struct
version CINERA_APP_VERSION = {
.Major = 0,
.Minor = 8,
.Patch = 17
.Patch = 18
};
#include <stdarg.h> // NOTE(matt): varargs
@ -6687,6 +6687,14 @@ void
ErrorRole(string HMMLFilepath, string Role)
{
ErrorFilenameAndLineNumber(&HMMLFilepath, 0, S_ERROR, ED_INDEXING);
if(Role.Length == 0)
{
fprintf(stderr, "Credit lacks a role\n");
fprintf(stderr, " A complete credit takes the form:\n"
" credit = creditable_person:their_role\n");
}
else
{
fprintf(stderr, "No such role: %s%.*s%s\n",
ColourStrings[CS_YELLOW_BOLD],
(int)Role.Length, Role.Base,
@ -6698,6 +6706,7 @@ ErrorRole(string HMMLFilepath, string Role)
" plural = \"Rollae\";\n"
" position = -1;\n"
" }\n", (int)Role.Length, Role.Base);
}
WaitForInput();
}
#endif
@ -6800,6 +6809,12 @@ Uncredited(HMML_VideoMetaData *Metadata, credit *C)
return Result;
}
bool
IsValidCredit(credit *Credit)
{
return Credit->Person && Credit->Role;
}
void
MergeCredits(memory_book *Credits, project *CurrentProject, HMML_VideoMetaData *Metadata)
{
@ -6807,7 +6822,7 @@ MergeCredits(memory_book *Credits, project *CurrentProject, HMML_VideoMetaData *
for(int ProjectCreditIndex = 0; ProjectCreditIndex < CurrentProject->Credit.ItemCount; ++ProjectCreditIndex)
{
credit *Credit = GetPlaceInBook(&CurrentProject->Credit, ProjectCreditIndex);
if(!Uncredited(Metadata, Credit) && Credit->Role && !GetCredit(Credits, Credit))
if(IsValidCredit(Credit) && !Uncredited(Metadata, Credit) && !GetCredit(Credits, Credit))
{
credit *New = MakeSpaceInBook(Credits);
New->Person = Credit->Person;
@ -6821,7 +6836,7 @@ MergeCredits(memory_book *Credits, project *CurrentProject, HMML_VideoMetaData *
credit Credit = {};
Credit.Person = GetPersonFromConfig(Wrap0(This->name));
Credit.Role = GetRoleByID(Config, Wrap0(This->role));
if(!Uncredited(Metadata, &Credit) && Credit.Role && !GetCredit(Credits, &Credit))
if(IsValidCredit(&Credit) && !Uncredited(Metadata, &Credit) && !GetCredit(Credits, &Credit))
{
credit *New = MakeSpaceInBook(Credits);
New->Person = Credit.Person;
@ -6840,7 +6855,7 @@ MergeCredits(memory_book *Credits, project *CurrentProject, HMML_VideoMetaData *
credit Credit = {};
Credit.Person = GetPersonFromConfig(Wrap0(This->value));
Credit.Role = GetRoleByID(Config, Wrap0(RoleIDStrings[ThisAttribute->RoleID]));
if(!Uncredited(Metadata, &Credit) && Credit.Role && !GetCredit(Credits, &Credit))
if(IsValidCredit(&Credit) && !Uncredited(Metadata, &Credit) && !GetCredit(Credits, &Credit))
{
credit *New = MakeSpaceInBook(Credits);
New->Person = Credit.Person;