Valgrind + gcc -pedantic fixes

This commit is contained in:
Aaron Gutierrez
2020-06-12 18:38:03 -07:00
parent cddaf13050
commit 711e9a4042
4 changed files with 11 additions and 7 deletions

View File

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

View File

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

4
ncac.c
View File

@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <term.h>
#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);

View File

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