From 33c490a1d71b4e81936226598d29ada99179a6bd Mon Sep 17 00:00:00 2001 From: jcorporation Date: Tue, 22 Jan 2019 00:20:04 +0000 Subject: [PATCH] Feat: add valingrid build Fix: first errors reported by valingrid --- CMakeLists.txt | 16 ++++++++++------ src/global.c | 3 ++- src/mpd_client.c | 15 +++++++++++++-- src/mympd_api.c | 3 ++- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 664ea5a..0f37e3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,13 +31,17 @@ include_directories(${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} ${LIBMPDCLIENT_I include(CheckCSourceCompiles) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -O2 -Wall -fstack-protector -D_FORTIFY_SOURCE=2 -pie -fPIE -DMG_ENABLE_SSL ") +#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -O1 -Wall -fstack-protector -D_FORTIFY_SOURCE=2 -pie -fPIE -DMG_ENABLE_SSL") -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -fsanitize=address \ - -fsanitize=undefined -fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound \ - -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=bounds-strict \ - -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow \ - -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fsanitize=vptr -static-libasan") +#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -fsanitize=address \ +# -fsanitize=undefined -fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound \ +# -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=bounds-strict \ +# -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow \ +# -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fsanitize=vptr -static-libasan") + +#for use with valgrind, disable above 2 set commands and enable the following set commands +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -DMG_ENABLE_SSL") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb") #compiler flags for mympd src file(GLOB MYMPD_SRC_FILES "src/*.c") diff --git a/src/global.c b/src/global.c index dc19730..dd98a0e 100644 --- a/src/global.c +++ b/src/global.c @@ -35,7 +35,7 @@ bool state_file_read(t_config *config, const char *name, char *value) { char cfg_file[400]; - char *line; + char *line = NULL; size_t n = 0; ssize_t read; @@ -51,6 +51,7 @@ bool state_file_read(t_config *config, const char *name, char *value) { snprintf(value, 400, "%s", line); LOG_DEBUG() fprintf(stderr, "DEBUG: State %s: %s\n", name, value); fclose(fp); + free(line); if (read > 0) return true; else diff --git a/src/mpd_client.c b/src/mpd_client.c index d6868c5..fcd38d2 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -174,13 +174,23 @@ void *mpd_client_loop(void *arg_config) { t_mpd_state mpd_state; mpd_state.conn_state = MPD_DISCONNECTED; mpd_state.timeout = 3000; - mpd_state.last_update_sticker_song_id = -1; + mpd_state.song_id = -1; + mpd_state.next_song_id = -1; mpd_state.last_song_id = -1; + mpd_state.queue_version = 0; + mpd_state.queue_length = 0; + mpd_state.last_update_sticker_song_id = -1; mpd_state.last_last_played_id = -1; + mpd_state.feat_sticker = false; + mpd_state.feat_playlists = false; + mpd_state.feat_tags = false; mpd_state.feat_library = false; + mpd_state.feat_advsearch = false; + mpd_state.feat_smartpls = false; mpd_state.jukeboxMode = JUKEBOX_OFF; mpd_state.jukeboxPlaylist = strdup("Database"); mpd_state.jukeboxQueueLength = 1; + mpd_state.autoPlay = false; list_init(&mpd_state.mpd_tags); list_init(&mpd_state.mympd_tags); list_init(&mpd_state.mympd_searchtags); @@ -2889,7 +2899,7 @@ static bool mpd_client_smartpls_update_newest(t_config *config, t_mpd_state *mpd static int mpd_client_read_last_played(t_config *config, t_mpd_state *mpd_state) { char cfgfile[400]; - char *line; + char *line = NULL; char *data; char *crap; size_t n = 0; @@ -2914,5 +2924,6 @@ static int mpd_client_read_last_played(t_config *config, t_mpd_state *mpd_state) } } fclose(fp); + free(line); return mpd_state->last_played.length;; } diff --git a/src/mympd_api.c b/src/mympd_api.c index ca34e5b..c9f35a5 100644 --- a/src/mympd_api.c +++ b/src/mympd_api.c @@ -278,7 +278,7 @@ static bool mympd_api_read_syscmds(t_config *config, t_mympd_state *mympd_state) static int mympd_api_syscmd(t_config *config, t_mympd_state *mympd_state, char *buffer, const char *cmd) { int len; char filename[400]; - char *line; + char *line = NULL; char *crap; size_t n = 0; ssize_t read; @@ -314,6 +314,7 @@ static int mympd_api_syscmd(t_config *config, t_mympd_state *mympd_state, char * len = snprintf(buffer, MAX_SIZE, "{\"type\": \"error\", \"data\": \"Can't execute cmd %s.\"}", cmd); printf("ERROR: Can't execute syscmd \"%s\"\n", cmd); } + free(line); CHECK_RETURN_LEN(); }