aboutsummaryrefslogtreecommitdiffstats
path: root/src/misc.c
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2023-11-19 21:49:53 +0200
committerMartin Pärtel <martin.partel@gmail.com>2023-11-19 21:49:53 +0200
commit5c8390f75925797a81973925a14cdf8ab092a3bc (patch)
treef998c665b983a173cffc6ada9113494ffac96268 /src/misc.c
parentbea88937f4564e282063fb44aeac485012cfae87 (diff)
parentdb61be1897ffe8f4d1a72bed62c8c892d06a1983 (diff)
downloadbindfs-5c8390f75925797a81973925a14cdf8ab092a3bc.tar.gz
Merge remote-tracking branch 'origin/master' into vagrant-ci
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/misc.c b/src/misc.c
index 122497d..fdebff9 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -19,6 +19,7 @@
#include "misc.h"
#include <stdarg.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -166,7 +167,7 @@ bool path_starts_with(const char *path, const char* prefix, size_t prefix_len)
const char* path_part = path + (prefix_part - prefix);
const char* path_slash = strchr(path_part, '/');
- size_t path_part_len = path_slash ? path_slash - path_part : path_len - (path_part - path);
+ size_t path_part_len = path_slash ? (size_t)(path_slash - path_part) : path_len - (path_part - path);
return prefix_part_len == path_part_len;
}
@@ -328,12 +329,12 @@ void grow_memory_block(struct memory_block *a, size_t amount)
if (new_cap == 0) {
new_cap = 8;
} else {
+ if (new_cap > SIZE_MAX / 2) {
+ fprintf(stderr, "Memory block too large.");
+ abort();
+ }
new_cap *= 2;
}
- if (new_cap < 0) { // Overflow
- fprintf(stderr, "Memory block too large.");
- abort();
- }
}
a->ptr = (char *)realloc(a->ptr, new_cap);
a->capacity = new_cap;