From 267b869440988be9d6ff00b0f5576ba292ed8765 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Sat, 9 Mar 2024 12:14:56 +0300 Subject: [PATCH] extol.c: add file size limit --- c-programming/jokes/extol.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/c-programming/jokes/extol.c b/c-programming/jokes/extol.c index 5074486..2144168 100644 --- a/c-programming/jokes/extol.c +++ b/c-programming/jokes/extol.c @@ -16,12 +16,15 @@ enum } EXTOL_MODE; #define EXTOL_PROTOTYPE "int extol(FILE* f)" +#define EXTOL_FILE_NAME "extol.txt" +#define EXTOL_FILE_LIMIT 128 int extol (FILE *f) { static bool spec_run = true; int result; + off_t size; if (spec_run == false) { @@ -38,6 +41,21 @@ extol (FILE *f) exit (EXIT_FAILURE); } fseek (fs, 0L, SEEK_END); + size = ftello (fs); + if (size == -1) + { + perror ("ftello"); + exit (EXIT_FAILURE); + } + else if (size > EXTOL_FILE_LIMIT) + { + FILE *new_fs = freopen (EXTOL_FILE_NAME, "w", fs); + if (new_fs == NULL) + { + perror ("freopen"); + exit (EXIT_FAILURE); + } + } result = extol (fs); for (result <<= 4, result &= ~15; (result & 15) != 15; result++) fputc ('=', fs);