Commit: 71c128e25ab3410b85043321e417b04ac23ee532
Parent: 4a391eeaec3cf22c21c427adadc092d8ad71fe27
Author: Randy Palamar
Date: Sat, 28 Oct 2023 23:00:00 -0600
handle a couple unlikely error cases
Diffstat:
1 file changed, 7 insertions(+), 0 deletions(-)
diff --git a/jdict.c b/jdict.c
@@ -222,6 +222,8 @@ make_dict(struct Dict *dict, size_t *nents)
nbanks--;
closedir(dir);
+ if (nbanks == 0)
+ return NULL;
for (i = 1; i <= nbanks; i++) {
snprintf(tbank, LEN(tbank), "%s/term_bank_%d.json", path, (int)i);
@@ -299,6 +301,11 @@ find_and_print_defs(struct Dict *dict, char **terms, size_t nterms)
DictEnt *ents;
ents = *make_dicts(dict, 1, &nents);
+ if (!ents) {
+ fputs("failed to allocate dict: ", stdout);
+ puts(dict->rom);
+ return;
+ }
puts(dict->name);
for (i = 0; i < nterms; i++)