aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-11-01 00:00:13 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-11-01 00:00:13 +0100
commitf5d6a06d2c46127e311e31132b3c0523c24c5e40 (patch)
tree2ed6836c31f791792fa9ccbee418299fcf20d7ae /src
parentd2b611433890d2a80b4da67374482ed6bd954e40 (diff)
Check for overflow
Diffstat (limited to 'src')
-rw-r--r--src/work.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/work.c b/src/work.c
index fe4697a..1ef699d 100644
--- a/src/work.c
+++ b/src/work.c
@@ -125,7 +125,10 @@ process_file(const char *locl_filename, unsigned char **locl_buf)
for (;;) {
ptrdiff_t want = nw + st.st_blksize;
if (want > basecap) {
- /* TODO: Check for overflow (top bit set) */
+ if (want & (1 << (PTRDIFF_WIDTH - 1))) {
+ errno = EOVERFLOW;
+ cerr(EXIT_FATAL, "%s:", __func__);
+ }
basecap = (ptrdiff_t)stdc_bit_ceil((size_t)want);
if ((baseptr = realloc(baseptr, basecap)) == nullptr)
cerr(EXIT_FATAL, "realloc:");