Commit c9539d27 authored by minus's avatar minus

Heap-allocate siso_watch instances

…so that the pointer returned by siso_add_name and siso_get remains
valid after new watches have been added.
parent 9cfd481d
......@@ -51,8 +51,8 @@ uint32_t siso_watch_get_first_or_default(struct siso_watch *w, uint32_t default_
struct siso_watch *siso_add_name(struct siso_watch_list *wl, const char* name) {
wl->len++;
wl->items = realloc(wl->items,
sizeof(struct siso_watch) * wl->len);
struct siso_watch *item = &wl->items[wl->len - 1];
sizeof(struct siso_watch *) * wl->len);
struct siso_watch *item = wl->items[wl->len - 1] = calloc(1, sizeof(struct siso_watch));
item->name = strdup(name);
item->target = -1;
item->mute = true;
......@@ -66,9 +66,9 @@ struct siso_watch *siso_add_name(struct siso_watch_list *wl, const char* name) {
struct siso_watch *siso_get(struct siso_watch_list *wl, const char *name) {
for (size_t i = 0; i < wl->len; i++) {
int offset = strlen(name) - strlen(wl->items[i].name);
if (strcmp(wl->items[i].name, name + offset) == 0) {
return &wl->items[i];
int offset = strlen(name) - strlen(wl->items[i]->name);
if (strcmp(wl->items[i]->name, name + offset) == 0) {
return wl->items[i];
}
}
return NULL;
......@@ -76,6 +76,6 @@ struct siso_watch *siso_get(struct siso_watch_list *wl, const char *name) {
void siso_remove_index(struct siso_watch_list *wl, uint32_t pa_index) {
for (size_t i = 0; i < wl->len; i++) {
siso_watch_remove_index(&wl->items[i], pa_index);
siso_watch_remove_index(wl->items[i], pa_index);
}
}
......@@ -27,7 +27,7 @@ struct siso_watch {
struct siso_watch_list {
size_t len;
struct siso_watch *items;
struct siso_watch **items;
};
void siso_watch_remove_index(struct siso_watch *w, uint32_t pa_index);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment