diff --git a/Makefile b/Makefile index 83f0962..741ec62 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,12 @@ CFLAGS += -DSCI_NAME="\"$(NAME)\"" CFLAGS += -DSCI_DESCRIPTION="\"$(DESCRIPTION)\"" CFLAGS += -D_POSIX_C_SOURCE=2 CFLAGS += -D_GNU_SOURCE -CFLAGS += -Wall -Werror -std=c11 -g +CFLAGS += -Wall -Werror -std=c11 CFLAGS += -Iinclude CFLAGS += -lpthread -luuid +CFLAGS += -fsanitize=address +CFLAGS += -fsanitize=undefined +CFLAGS += -g .PHONY: all clean dist install diff --git a/TODO.md b/TODO.md index d4a5a66..2dbb1af 100644 --- a/TODO.md +++ b/TODO.md @@ -20,6 +20,7 @@ - [ ] Port this document to gitea issue tracking - [x] enable PATH-able programs and argv in the command section - [ ] custom environment variable passing. Something like `-e MY_TOKEN` ala docker-style + - [x] address sanitizers please. - [ ] Ninth things ninth, fix bugs, see below - [ ] Tenth things tenth, write manpages, choose license - [ ] Eleventh things Eleventh, polish diff --git a/include/strlist.h b/include/strlist.h index 2298ecd..95f29d9 100644 --- a/include/strlist.h +++ b/include/strlist.h @@ -48,4 +48,11 @@ void remove_strlist_node(strlist_node* node); // This function is not threadsafe. void clear_strlist(strlist_node* root); +// Convert a strlist to an array of strings. +// Note that this copies the strlist, you still have to free it. +// The array itself is NULL terminated, enabling you to iterate to the end. +// The array should be free'd, as well as each of the entries. +// Returns NULL if the provided strlist is empty. +char** strlist_to_array(strlist_node* root); + #endif diff --git a/src/executor.c b/src/executor.c index 08fe358..88324a8 100644 --- a/src/executor.c +++ b/src/executor.c @@ -24,7 +24,10 @@ void set_logdir(const char* logdir) { char* create_pipeline_id() { uuid_t uuid; uuid_generate(uuid); - char* pipeline_id = malloc(32); + // example uuid + // 662ddee9-ee7c-4d13-8999-a2604c6d12d6 + // it's 36 characters (+null) + char* pipeline_id = malloc(sizeof(char) * 37); uuid_unparse_lower(uuid, pipeline_id); return pipeline_id; } @@ -99,4 +102,5 @@ end: free(url); free(trigger); free(id); + free(data); } diff --git a/src/notify.c b/src/notify.c index 753ea7a..93291a3 100644 --- a/src/notify.c +++ b/src/notify.c @@ -18,6 +18,7 @@ #include "notify.h" #include "util.h" #include "log.h" +#include #define EV_SIZE sizeof(struct inotify_event) #define BUF_LEN EV_SIZE * 32 @@ -39,13 +40,13 @@ void listen_for_changes(const pipeline_conf* config, notify_callback callback) { assert(r != -1); for(int i = 0; i < r; ) { struct inotify_event* e = (struct inotify_event*)&buffer[i]; - pipeline_event ev; - ev.event = e; - ev.name = config->name; - ev.url = config->url; - ev.trigger = config->trigger; - ev.command = config->command; - callback(&ev); + pipeline_event* ev = malloc(sizeof(pipeline_event)); + ev->event = e; + ev->name = config->name; + ev->url = config->url; + ev->trigger = config->trigger; + ev->command = config->command; + callback(ev); i += EV_SIZE + e->len; } ASSERT_SYSCALL_SUCCESS(close(fd)); diff --git a/src/strlist.c b/src/strlist.c index 6fe70e3..be27000 100644 --- a/src/strlist.c +++ b/src/strlist.c @@ -53,10 +53,38 @@ void remove_strlist_node(strlist_node* node) { void clear_strlist(strlist_node* root) { strlist_node* cursor = root; while(cursor != NULL) { - cursor = cursor->next; - if(cursor->str) + if(cursor->str != NULL) free(cursor->str); - cursor->str = NULL; - free(cursor->previous); + strlist_node* prev = cursor; + cursor = cursor->next; + free(prev); } } + +size_t strlist_length(strlist_node* root) { + size_t result = 0; + strlist_node* cursor = root; + while(cursor != NULL) { + result++; + cursor = cursor->next; + } + return result; +} + +char** strlist_to_array(strlist_node* root) { + size_t len = strlist_length(root); + if(len <= 0) + return NULL; + char** result = malloc(sizeof(char*) * (len + 1)); + memset(result, len+1, (size_t)NULL); + strlist_node* cursor = root; + for(int i = 0; i < len; i++) { + if(cursor == NULL) + break; + if(cursor->str == NULL) + continue; + result[i] = strdup(cursor->str); + cursor = cursor->next; + } + return result; +}