From 0ac5e3f0bef13c8b2d5f8f947100567aa4b13685 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 3 May 2016 21:03:13 +0200 Subject: vector: catch overflows of the alloc counter Better fail than go into an endless loop... --- src/vector.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') 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; -- cgit v1.2.3