Bound-check GetErr

This commit is contained in:
Dianne Skoll
2024-12-09 20:03:15 -05:00
parent d9796e72e5
commit 9f9ae77895
4 changed files with 20 additions and 4 deletions

View File

@@ -255,3 +255,9 @@ EXTERN char *ErrMsg[]
#endif /* MK_GLOBALS */
;
#endif /* L_ERR_OVERRIDE */
EXTERN int NumErrs
#ifdef MK_GLOBALS
= sizeof(ErrMsg) / sizeof(ErrMsg[0])
#endif
;

View File

@@ -2028,9 +2028,8 @@ int GetOnceDate(void)
char const *GetErr(int r)
{
char const *s = GetTranslatedString(ErrMsg[r]);
if (s) {
return s;
if (r < 0 || r >= NumErrs) {
r = E_SWERR;
}
return ErrMsg[r];
return t(ErrMsg[r]);
}

View File

@@ -269,3 +269,4 @@ void InitUserFunctions(void);
void InitTranslationTable(void);
char const *GetTranslatedString(char const *orig);
char const *GetErr(int r);
char const *t(char const *s);

View File

@@ -212,6 +212,15 @@ GetTranslatedString(char const *orig)
return item->translated;
}
char const *t(char const *orig)
{
char const *n = GetTranslatedString(orig);
if (n) {
return n;
}
return orig;
}
int
DoTranslate(ParsePtr p)
{
@@ -272,3 +281,4 @@ get_translation_hash_stats(int *total, int *maxlen, double *avglen)
*maxlen = s.max_len;
*avglen = s.avg_len;
}