Browse Source

fix a severe bug in vector extension logic

master
Lephenixnoir 1 month ago
parent
commit
cd4e3969bd
Signed by: Lephenixnoir GPG Key ID: 1BBA026E13FC0495
3 changed files with 7 additions and 5 deletions
  1. +1
    -1
      include/justui/jpainted.h
  2. +1
    -0
      src/jlabel.c
  3. +5
    -4
      src/vec.c

+ 1
- 1
include/justui/jpainted.h View File

@ -31,7 +31,7 @@
an integer or a pointer (essentially).
void draw_value(int x, int y, uint32_t *value) {
dprint(x, y, "%08X", *value);
dprint(x, y, "%08X", *value);
}
uint32_t my_value;
jpainted *widget = jpainted_create(draw_value, &my_value, 30, 8, parent);


+ 1
- 0
src/jlabel.c View File

@ -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;


+ 5
- 4
src/vec.c View File

@ -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…
Cancel
Save