From 5adc3fd9c1a1992d51af3479287ba8b82dc50e1d Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Tue, 9 Oct 2012 20:56:54 +0200 Subject: [PATCH] Don't forget to set the _alloc in vector resize, also set _alloc back in _append if mem_a had failed --- gmqcc.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gmqcc.h b/gmqcc.h index 5e34c94..42a5fc6 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -692,17 +692,20 @@ bool GMQCC_WARN Tself##_##mem##_find(Tself *self, Twhat obj, size_t *idx) \ bool GMQCC_WARN Tself##_##mem##_append(Tself *s, Twhat *p, size_t c) \ { \ Twhat *reall; \ + size_t oldalloc; \ if (s->mem##_count+c > s->mem##_alloc) { \ if (!s->mem##_alloc) { \ s->mem##_alloc = c < 16 ? 16 : c; \ s->mem = (Twhat*)mem_a(sizeof(Twhat) * s->mem##_alloc); \ } else { \ + oldalloc = s->mem##_alloc; \ s->mem##_alloc *= 2; \ if (s->mem##_count+c >= s->mem##_alloc) { \ s->mem##_alloc = s->mem##_count+c; \ } \ reall = (Twhat*)mem_a(sizeof(Twhat) * s->mem##_alloc); \ if (!reall) { \ + s->mem##_alloc = oldalloc; \ return false; \ } \ memcpy(reall, s->mem, sizeof(Twhat) * s->mem##_count); \ @@ -736,6 +739,7 @@ bool GMQCC_WARN Tself##_##mem##_resize(Tself *s, size_t c) \ memcpy(reall, s->mem, sizeof(Twhat) * c); \ mem_d(s->mem); \ s->mem = reall; \ + s->mem##_alloc = c; \ } \ return true; \ } -- 2.39.2