mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2024-12-28 04:23:40 +01:00
fix a severe bug in vector extension logic
This commit is contained in:
parent
87d6d4eea4
commit
cd4e3969bd
3 changed files with 7 additions and 5 deletions
|
@ -28,6 +28,7 @@ jlabel *jlabel_create(char const *text, void *parent)
|
|||
l->color = C_BLACK;
|
||||
l->font = NULL;
|
||||
|
||||
l->wrap_mode = J_WRAP_NONE;
|
||||
l->text = text;
|
||||
l->owns_text = false;
|
||||
|
||||
|
|
|
@ -24,21 +24,22 @@ bool vec_add(vec_t *v, size_t n)
|
|||
/* Allocate either size/2 new elements or 4 elements */
|
||||
size_t ext = max(v->size / 2, 4);
|
||||
/* Make sure that no more than 255 free elements will remain */
|
||||
if(v->size + v->free + ext > n + 255)
|
||||
ext = (n + 255) - (v->size + v->free);
|
||||
if(v->free + ext > n + 255)
|
||||
ext = (n + 255) - v->free;
|
||||
|
||||
size_t newsize = v->size + v->free + ext;
|
||||
void *newdata = realloc(v->data, newsize * v->elsize);
|
||||
if(!newdata) return false;
|
||||
|
||||
v->data = newdata;
|
||||
v->free = newsize - n;
|
||||
v->free = newsize - v->size - n;
|
||||
v->size += n;
|
||||
}
|
||||
else {
|
||||
v->free -= n;
|
||||
v->size += n;
|
||||
}
|
||||
|
||||
v->size += n;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue