aboutsummaryrefslogtreecommitdiffstats
path: root/src/misc.c
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2019-06-26 11:41:46 +0300
committerMartin Pärtel <martin.partel@gmail.com>2019-06-26 11:41:46 +0300
commit74427b94fcf53b3a3c4c87b26051a55c69aac093 (patch)
treed126cc92a676178d293e3a1b87f600c866f367bd /src/misc.c
parentacca303e4b603614afb51552d38da6de9213be29 (diff)
downloadbindfs-74427b94fcf53b3a3c4c87b26051a55c69aac093.tar.gz
Resolve symlinks in readdir() so correct attributes are returned.
Fixes #76
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/misc.c b/src/misc.c
index eae81f0..dafebed 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -188,10 +188,16 @@ void grow_memory_block(struct memory_block *a, int amount)
a->size += amount;
if (a->size >= a->capacity) {
new_cap = a->capacity;
- if (new_cap == 0) {
- new_cap = 8;
- } else {
- new_cap *= 2;
+ while (new_cap < a->size) {
+ if (new_cap == 0) {
+ new_cap = 8;
+ } else {
+ 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;