From 711e9a4042ca869b7b54a48cf929b049906b223e Mon Sep 17 00:00:00 2001 From: Aaron Gutierrez Date: Fri, 12 Jun 2020 18:38:03 -0700 Subject: [PATCH] Valgrind + gcc -pedantic fixes --- Makefile | 4 ++-- asana/asana.c | 8 +++++--- ncac.c | 4 +++- ui/base.c | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 12256cd..cb59aa2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS=--std=c18 -O2 -Wall -Wextra -pedantic +CFLAGS=--std=c11 -O2 -Wall -Wextra -pedantic LDLIBS=-lncurses -lcurl .phony: clean @@ -10,7 +10,7 @@ objects := $(patsubst %.c,%.o,$(srcs)) ncac: $(objects) tags: $(srcs) $(hdrs) - ctags -w -t $^ + ctags -w $^ clean: rm -f **/*.o ncac diff --git a/asana/asana.c b/asana/asana.c index 6b86a50..a28650d 100644 --- a/asana/asana.c +++ b/asana/asana.c @@ -108,7 +108,7 @@ void asana_extract_task(cJSON *json, Task *task) { cJSON *notes = cJSON_GetObjectItemCaseSensitive(json, "notes"); if (cJSON_IsString(notes)) { - task->notes = malloc(sizeof(char)*strlen(notes->valuestring)); + task->notes = malloc(sizeof(char)*(strlen(notes->valuestring)+1)); strcpy(task->notes, notes->valuestring); } else { task->notes = NULL; @@ -139,7 +139,7 @@ void asana_extract_project(cJSON *json, Project *project) { void asana_extract_resource(cJSON *json, Resource *resource) { cJSON *gid = cJSON_GetObjectItemCaseSensitive(json, "gid"); if (cJSON_IsString(gid)) { - resource->gid = malloc(sizeof(char)*strlen(gid->valuestring)); + resource->gid = malloc(sizeof(char)*(strlen(gid->valuestring)+1)); strcpy(resource->gid, gid->valuestring); fprintf(stderr, "Extracted resource ID %s\n", resource->gid); } else { @@ -148,7 +148,7 @@ void asana_extract_resource(cJSON *json, Resource *resource) { cJSON *name = cJSON_GetObjectItemCaseSensitive(json, "name"); if (cJSON_IsString(name)) { - resource->name = malloc(sizeof(char)*strlen(name->valuestring)); + resource->name = malloc(sizeof(char)*(strlen(name->valuestring)+1)); strcpy(resource->name, name->valuestring); } else { resource->name = NULL; @@ -193,6 +193,7 @@ asana_err user_task_list_gid(char *workspace_gid, char *gid) { strcpy(gid, task_list.gid); ret = ASANA_ERR_OK; } + asana_free_resource((Resource *)&task_list); } else { fprintf(stderr, "Error fetching user_task_list: %d\n", task_list_resp->status); } @@ -301,4 +302,5 @@ size_t asana_resource_size(Resource *resource) { fprintf(stderr, "asana_resource_size: Unknown resource type %d\n", resource->type); + return 0; } diff --git a/ncac.c b/ncac.c index a5f82d1..18dd30a 100644 --- a/ncac.c +++ b/ncac.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "asana/asana.h" @@ -80,7 +81,8 @@ int main(/*int argc, char **argv*/) { return 0; } -static void finish(/*int sig*/) { +static void finish(int sig) { + (void)sig; endwin(); asana_cleanup(); exit(0); diff --git a/ui/base.c b/ui/base.c index 304e770..e5151a3 100644 --- a/ui/base.c +++ b/ui/base.c @@ -27,7 +27,7 @@ void draw_status_line(ui_state *state) { } void draw_text(const char *text, ui_state *state) { - if (!text || strnlen(text, 1) == 0) return; + if (!text || text[0] == '\0') return; mvaddch(state->curs_y, state->curs_x, *text); ++text;