jdict

command line tool for looking up terms in yomidict dictionaries
git clone anongit@rnpnr.xyz:jdict.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 310e995a718b5ea7c6c722f7318f85764127b94f
Parent: de2b61c14c1c69bcd509f1269efc70fbb13ffcf3
Author: Randy Palamar
Date:   Tue, 14 Nov 2023 06:20:38 -0700

avoid SIZE_MAX by using (size_t)-1

Diffstat:
Mjdict.c | 5++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/jdict.c b/jdict.c @@ -4,7 +4,6 @@ #include <limits.h> #include <pthread.h> #include <stddef.h> -#include <stdint.h> /* for SIZE_MAX */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -204,7 +203,7 @@ parse_term_bank(DictEnt *ents, size_t len, const char *tbank) die("couldn't mmap file: %s\n", tbank); /* allocate tokens */ - if ((SIZE_MAX - 1) / YOMI_TOKS_PER_ENT < len) + if (((size_t)-1 - 1) / YOMI_TOKS_PER_ENT < len) die("ntoks multiplication overflowed: %s\n", tbank); ntoks = len * YOMI_TOKS_PER_ENT + 1; toks = xreallocarray(toks, ntoks, sizeof(YomiTok)); @@ -320,7 +319,7 @@ make_dict(struct Dict *dict, size_t *nlen) } while (nents == 0); /* alloc enough memory for all ents */ - if (SIZE_MAX / nbanks < nents) + if ((size_t)-1 / nbanks < nents) die("dict has too many entries: %s\n", dict->rom); lents = nents * nbanks; ents = xreallocarray(ents, lents, sizeof(DictEnt));