mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-03-31 15:01:01 +00:00
Don't forget to set the _alloc in vector resize, also set _alloc back in _append if mem_a had failed
This commit is contained in:
parent
bbdba9b8d7
commit
5adc3fd9c1
1 changed files with 4 additions and 0 deletions
4
gmqcc.h
4
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; \
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue