diff --git a/src/journal.re.c b/src/journal.re.c index a86d599..3993f78 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -201,8 +201,6 @@ struct journal journal(const char *const dir_journal) { /* Because it's in a flat array, the pointers are not stable while we are loading it, and we need to store the offsets. */ *v.offset = (uintptr_t)(contents - j.backing.data); - /* fixme: not representing with int should be a lazy error, - since we use `printf`. */ } d = 0, int_array_clear(&days); if(chdir("..") == -1) goto catch; diff --git a/src/text.c b/src/text.c index c2a1ea8..2c6126e 100644 --- a/src/text.c +++ b/src/text.c @@ -3,6 +3,7 @@ #include "text.h" #include +#include #define ARRAY_NAME char #define ARRAY_TYPE char @@ -28,10 +29,12 @@ char *text_append_file(struct char_array *text, const char *const fn) { assert(text && fn); start = text->size; if(!(fp = fopen(fn, "r"))) goto catch; - /* Read entire file in chunks. */ + /* Read entire file in chunks. We don't allow any text file to go over + `INT_MAX` because `printf("%.*s", int, char *)` is used. */ do if(!(cursor = char_array_buffer(text, granularity)) || (nread = fread(cursor, 1, granularity, fp), ferror(fp)) - || !char_array_append(text, nread)) goto catch; + || !char_array_append(text, nread) + || text->size - start >= INT_MAX) goto catch; while(nread == granularity); /* File to `C` string. */ if(!(cursor = char_array_new(text))) goto catch;