From: Wolfgang (Blub) Bumiller Date: Tue, 9 Oct 2012 18:56:54 +0000 (+0200) Subject: Don't forget to set the _alloc in vector resize, also set _alloc back in _append... X-Git-Tag: 0.1-rc1~23 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5adc3fd9c1a1992d51af3479287ba8b82dc50e1d;p=xonotic%2Fgmqcc.git Don't forget to set the _alloc in vector resize, also set _alloc back in _append if mem_a had failed --- 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; \ }