mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2024-12-28 20:43: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
|
@ -31,7 +31,7 @@
|
||||||
an integer or a pointer (essentially).
|
an integer or a pointer (essentially).
|
||||||
|
|
||||||
void draw_value(int x, int y, uint32_t *value) {
|
void draw_value(int x, int y, uint32_t *value) {
|
||||||
dprint(x, y, "%08X", *value);
|
dprint(x, y, "%08X", *value);
|
||||||
}
|
}
|
||||||
uint32_t my_value;
|
uint32_t my_value;
|
||||||
jpainted *widget = jpainted_create(draw_value, &my_value, 30, 8, parent);
|
jpainted *widget = jpainted_create(draw_value, &my_value, 30, 8, parent);
|
||||||
|
|
|
@ -28,6 +28,7 @@ jlabel *jlabel_create(char const *text, void *parent)
|
||||||
l->color = C_BLACK;
|
l->color = C_BLACK;
|
||||||
l->font = NULL;
|
l->font = NULL;
|
||||||
|
|
||||||
|
l->wrap_mode = J_WRAP_NONE;
|
||||||
l->text = text;
|
l->text = text;
|
||||||
l->owns_text = false;
|
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 */
|
/* Allocate either size/2 new elements or 4 elements */
|
||||||
size_t ext = max(v->size / 2, 4);
|
size_t ext = max(v->size / 2, 4);
|
||||||
/* Make sure that no more than 255 free elements will remain */
|
/* Make sure that no more than 255 free elements will remain */
|
||||||
if(v->size + v->free + ext > n + 255)
|
if(v->free + ext > n + 255)
|
||||||
ext = (n + 255) - (v->size + v->free);
|
ext = (n + 255) - v->free;
|
||||||
|
|
||||||
size_t newsize = v->size + v->free + ext;
|
size_t newsize = v->size + v->free + ext;
|
||||||
void *newdata = realloc(v->data, newsize * v->elsize);
|
void *newdata = realloc(v->data, newsize * v->elsize);
|
||||||
if(!newdata) return false;
|
if(!newdata) return false;
|
||||||
|
|
||||||
v->data = newdata;
|
v->data = newdata;
|
||||||
v->free = newsize - n;
|
v->free = newsize - v->size - n;
|
||||||
|
v->size += n;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
v->free -= n;
|
v->free -= n;
|
||||||
|
v->size += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
v->size += n;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue