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 = { version CINERA_APP_VERSION = {
.Major = 0, .Major = 0,
.Minor = 8, .Minor = 8,
.Patch = 17 .Patch = 18
}; };
#include <stdarg.h> // NOTE(matt): varargs #include <stdarg.h> // NOTE(matt): varargs
@ -6687,17 +6687,26 @@ void
ErrorRole(string HMMLFilepath, string Role) ErrorRole(string HMMLFilepath, string Role)
{ {
ErrorFilenameAndLineNumber(&HMMLFilepath, 0, S_ERROR, ED_INDEXING); ErrorFilenameAndLineNumber(&HMMLFilepath, 0, S_ERROR, ED_INDEXING);
fprintf(stderr, "No such role: %s%.*s%s\n", if(Role.Length == 0)
ColourStrings[CS_YELLOW_BOLD], {
(int)Role.Length, Role.Base, fprintf(stderr, "Credit lacks a role\n");
ColourStrings[CS_END]); fprintf(stderr, " A complete credit takes the form:\n"
fprintf(stderr, "Perhaps you'd like to add a new role to your config file, e.g.:\n" " credit = creditable_person:their_role\n");
" role = \"%.*s\"\n" }
" {\n" else
" name = \"Roller\";\n" {
" plural = \"Rollae\";\n" fprintf(stderr, "No such role: %s%.*s%s\n",
" position = -1;\n" ColourStrings[CS_YELLOW_BOLD],
" }\n", (int)Role.Length, Role.Base); (int)Role.Length, Role.Base,
ColourStrings[CS_END]);
fprintf(stderr, "Perhaps you'd like to add a new role to your config file, e.g.:\n"
" role = \"%.*s\"\n"
" {\n"
" name = \"Roller\";\n"
" plural = \"Rollae\";\n"
" position = -1;\n"
" }\n", (int)Role.Length, Role.Base);
}
WaitForInput(); WaitForInput();
} }
#endif #endif
@ -6800,6 +6809,12 @@ Uncredited(HMML_VideoMetaData *Metadata, credit *C)
return Result; return Result;
} }
bool
IsValidCredit(credit *Credit)
{
return Credit->Person && Credit->Role;
}
void void
MergeCredits(memory_book *Credits, project *CurrentProject, HMML_VideoMetaData *Metadata) 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) for(int ProjectCreditIndex = 0; ProjectCreditIndex < CurrentProject->Credit.ItemCount; ++ProjectCreditIndex)
{ {
credit *Credit = GetPlaceInBook(&CurrentProject->Credit, 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); credit *New = MakeSpaceInBook(Credits);
New->Person = Credit->Person; New->Person = Credit->Person;
@ -6821,7 +6836,7 @@ MergeCredits(memory_book *Credits, project *CurrentProject, HMML_VideoMetaData *
credit Credit = {}; credit Credit = {};
Credit.Person = GetPersonFromConfig(Wrap0(This->name)); Credit.Person = GetPersonFromConfig(Wrap0(This->name));
Credit.Role = GetRoleByID(Config, Wrap0(This->role)); 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); credit *New = MakeSpaceInBook(Credits);
New->Person = Credit.Person; New->Person = Credit.Person;
@ -6840,7 +6855,7 @@ MergeCredits(memory_book *Credits, project *CurrentProject, HMML_VideoMetaData *
credit Credit = {}; credit Credit = {};
Credit.Person = GetPersonFromConfig(Wrap0(This->value)); Credit.Person = GetPersonFromConfig(Wrap0(This->value));
Credit.Role = GetRoleByID(Config, Wrap0(RoleIDStrings[ThisAttribute->RoleID])); 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); credit *New = MakeSpaceInBook(Credits);
New->Person = Credit.Person; New->Person = Credit.Person;