summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-05-03 21:03:13 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-05-03 21:03:13 +0200
commit0ac5e3f0bef13c8b2d5f8f947100567aa4b13685 (patch)
tree399e5140b91eb08f048abb4d84a771ea52cfa5f0
parent1709b7ddc6f0856be42640524f4e7fbff08035ac (diff)
downloadfastd-0ac5e3f0bef13c8b2d5f8f947100567aa4b13685.tar
fastd-0ac5e3f0bef13c8b2d5f8f947100567aa4b13685.zip
vector: catch overflows of the alloc counter
Better fail than go into an endless loop...
-rw-r--r--src/vector.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/vector.c b/src/vector.c
index aeeeebb..8cfecd4 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -57,8 +57,13 @@ void _fastd_vector_resize(fastd_vector_desc_t *desc, void **data, size_t n, size
n = n*3/2;
}
- while (alloc < n)
+ while (alloc < n) {
alloc <<= 1;
+ if (!alloc) {
+ errno = EOVERFLOW;
+ exit_errno("memory allocation error");
+ }
+ }
if (alloc != desc->allocated) {
desc->allocated = alloc;