From cea7fa6ac0ae91feaaec6f479594d5d1f7610b76 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Wed, 18 Dec 2024 18:58:27 +0100 Subject: [PATCH] Suppress warnings reported by CodeQL --- src/libscrobbler2.c | 2 +- src/main.c | 32 ++++++++++++-------------------- src/notify.c | 6 ++++-- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/libscrobbler2.c b/src/libscrobbler2.c index 96b7662..109fe3d 100644 --- a/src/libscrobbler2.c +++ b/src/libscrobbler2.c @@ -455,7 +455,7 @@ scrobbler_status_t scrobbler_authentication(scrobbler_session_t *sbs, token_hex[32] = '\0'; /* perform user authorization (callback function) */ - sprintf(get_url, "%s?api_key=%s&token=%s", + snprintf(get_url, sizeof(get_url), "%s?api_key=%s&token=%s", sbs->auth_url, api_key_hex, token_hex); if (callback(get_url) != 0) { sb_curl_cleanup(curl, &response); diff --git a/src/main.c b/src/main.c index 7852a84..109a12f 100644 --- a/src/main.c +++ b/src/main.c @@ -180,25 +180,6 @@ static void cmusfm_initialization(void) { printf("Error: unable to write file: %s\n", cmusfm_config_file); } -/* Spawn server process of cmusfm by simply forking ourself and exec with - * special "server" argument. */ -static void cmusfm_spawn_server_process(const char *cmusfm) { - - pid_t pid; - - if ((pid = fork()) == -1) { - perror("ERROR: Fork server"); - exit(EXIT_FAILURE); - } - - if (pid == 0) { - execlp(cmusfm, cmusfm, "server", NULL); - perror("ERROR: Exec server"); - exit(EXIT_FAILURE); - } - -} - int main(int argc, char *argv[]) { struct cmtrack_info *tinfo; @@ -237,8 +218,19 @@ int main(int argc, char *argv[]) { } if (cmusfm_server_check() == 0) { - cmusfm_spawn_server_process(argv[0]); + + pid_t pid; + if ((pid = fork()) == -1) { + perror("ERROR: Fork server"); + return EXIT_FAILURE; + } + + if (pid == 0) + return cmusfm_server_start(); + + /* wait for the server to start */ sleep(1); + } if (cmusfm_server_send_track(tinfo) != 0) { diff --git a/src/notify.c b/src/notify.c index 7642f5d..4a426ef 100644 --- a/src/notify.c +++ b/src/notify.c @@ -8,6 +8,8 @@ #include #include + +#include #include #include "debug.h" @@ -68,6 +70,8 @@ void cmusfm_notify_show(const scrobbler_trackinfo_t *sb_tinf, const char *icon) else cmus_notify = notify_notification_new(track, body, icon); + free(body); + if (!notify_notification_show(cmus_notify, &error)) { debug("Desktop notify error: %s", error->message); g_error_free(error); @@ -77,8 +81,6 @@ void cmusfm_notify_show(const scrobbler_trackinfo_t *sb_tinf, const char *icon) cmusfm_notify_free(); } - if (body != NULL) - free(body); } /* Initialize notification system. */