[gamecode] Ensure static string refs are initialized

That was a fun one to track down :P
This commit is contained in:
Bill Currie 2020-03-08 21:29:31 +09:00
parent a013714bd0
commit 5f299cbac7
1 changed files with 7 additions and 6 deletions

View File

@ -267,7 +267,7 @@ PR_LoadStrings (progs_t *pr)
if (res->static_strings) if (res->static_strings)
free (res->static_strings); free (res->static_strings);
res->static_strings = malloc (count * sizeof (strref_t)); res->static_strings = calloc (count, sizeof (strref_t));
count = 0; count = 0;
str = pr->pr_strings; str = pr->pr_strings;
while (str < end) { while (str < end) {
@ -344,7 +344,7 @@ get_string (progs_t *pr, string_t num)
case str_free: case str_free:
break; break;
} }
PR_Error (pr, "internal string error"); PR_Error (pr, "internal string error: %d", __LINE__);
} else { } else {
if (num >= pr->pr_stringsize) if (num >= pr->pr_stringsize)
return 0; return 0;
@ -436,7 +436,8 @@ PR_SetReturnString (progs_t *pr, const char *s)
requeue_strref (res, sr); requeue_strref (res, sr);
} else if ((sr->type == str_return && !sr->rs_slot) } else if ((sr->type == str_return && !sr->rs_slot)
|| (sr->type != str_return && sr->rs_slot)) { || (sr->type != str_return && sr->rs_slot)) {
PR_Error (pr, "internal string error"); PR_Error (pr, "internal string error: %d %d %p", __LINE__,
sr->type, sr->rs_slot);
} }
return string_index (res, sr); return string_index (res, sr);
} }
@ -445,7 +446,7 @@ PR_SetReturnString (progs_t *pr, const char *s)
// slot is empty // slot is empty
if ((sr = res->rs_slot->strref)) { if ((sr = res->rs_slot->strref)) {
if (sr->type != str_return || sr->rs_slot != res->rs_slot) { if (sr->type != str_return || sr->rs_slot != res->rs_slot) {
PR_Error (pr, "internal string error"); PR_Error (pr, "internal string error: %d", __LINE__);
} }
pr_strfree (pr, sr->s.string); pr_strfree (pr, sr->s.string);
} else { } else {
@ -576,7 +577,7 @@ PR_FreeString (progs_t *pr, string_t str)
break; break;
case str_return: case str_return:
default: default:
PR_Error (pr, "internal string error"); PR_Error (pr, "internal string error: %d", __LINE__);
} }
free_string_ref (res, sr); free_string_ref (res, sr);
return; return;
@ -593,7 +594,7 @@ PR_FreeTempStrings (progs_t *pr)
for (sr = pr->pr_xtstr; sr; sr = t) { for (sr = pr->pr_xtstr; sr; sr = t) {
t = sr->next; t = sr->next;
if (sr->type != str_temp) if (sr->type != str_temp)
PR_Error (pr, "internal string error"); PR_Error (pr, "internal string error: %d", __LINE__);
if (R_STRING (pr) < 0 && string_index (res, sr) == R_STRING (pr) if (R_STRING (pr) < 0 && string_index (res, sr) == R_STRING (pr)
&& pr->pr_depth) { && pr->pr_depth) {
prstack_t *frame = pr->pr_stack + pr->pr_depth - 1; prstack_t *frame = pr->pr_stack + pr->pr_depth - 1;