fixing mem-vector resize function

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-23 13:21:14 +02:00
parent 52a1b9469c
commit fe2f9d79c5

View file

@ -686,15 +686,15 @@ 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) \ bool GMQCC_WARN Tself##_##mem##_append(Tself *s, Twhat *p, size_t c) \
{ \ { \
Twhat *reall; \ Twhat *reall; \
if (s->mem##_count+c >= s->mem##_alloc) { \ if (s->mem##_count+c > s->mem##_alloc) { \
if (!s->mem##_alloc) { \ if (!s->mem##_alloc) { \
s->mem##_alloc = c < 16 ? 16 : c; \ s->mem##_alloc = c < 16 ? 16 : c; \
s->mem = (Twhat*)mem_a(sizeof(Twhat) * s->mem##_alloc); \
} else { \ } else { \
s->mem##_alloc *= 2; \ s->mem##_alloc *= 2; \
if (s->mem##_count+c >= s->mem##_alloc) { \ if (s->mem##_count+c >= s->mem##_alloc) { \
s->mem##_alloc = s->mem##_count+c; \ s->mem##_alloc = s->mem##_count+c; \
} \ } \
} \
reall = (Twhat*)mem_a(sizeof(Twhat) * s->mem##_alloc); \ reall = (Twhat*)mem_a(sizeof(Twhat) * s->mem##_alloc); \
if (!reall) { \ if (!reall) { \
return false; \ return false; \
@ -703,6 +703,7 @@ bool GMQCC_WARN Tself##_##mem##_append(Tself *s, Twhat *p, size_t c) \
mem_d(s->mem); \ mem_d(s->mem); \
s->mem = reall; \ s->mem = reall; \
} \ } \
} \
memcpy(&s->mem[s->mem##_count], p, c*sizeof(*p)); \ memcpy(&s->mem[s->mem##_count], p, c*sizeof(*p)); \
s->mem##_count += c; \ s->mem##_count += c; \
return true; \ return true; \