From 4cd28b23f07f2361f611125e35c61bdcf245da1b Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Mon, 14 Aug 2023 23:07:37 +0100 Subject: [PATCH] Adjustments and annotations as per splint and flawfinder reports. --- src/include/pv.h | 4 ++-- src/main/main.c | 9 ++------- src/main/options.c | 2 +- src/main/remote.c | 15 +++++++++++++++ src/pv/state.c | 4 ++-- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/include/pv.h b/src/include/pv.h index ec1b415..5f175a0 100644 --- a/src/include/pv.h +++ b/src/include/pv.h @@ -115,8 +115,8 @@ extern void pv_state_size_set(pvstate_t, unsigned long long); extern void pv_state_interval_set(pvstate_t, double); extern void pv_state_width_set(pvstate_t, unsigned int); extern void pv_state_height_set(pvstate_t, unsigned int); -extern void pv_state_name_set(pvstate_t, const char *); -extern void pv_state_format_string_set(pvstate_t, const char *); +extern void pv_state_name_set(pvstate_t, /*@null@*/ const char *); +extern void pv_state_format_string_set(pvstate_t, /*@null@*/ const char *); extern void pv_state_watch_pid_set(pvstate_t, unsigned int); extern void pv_state_watch_fd_set(pvstate_t, int); extern void pv_state_average_rate_window_set(pvstate_t, unsigned int); diff --git a/src/main/main.c b/src/main/main.c index 6b05047..4dfdc31 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -216,13 +216,8 @@ int main(int argc, char **argv) pv_state_target_buffer_size_set(state, opts->buffer_size); pv_state_no_splice_set(state, opts->no_splice); pv_state_size_set(state, opts->size); - - if (NULL != opts->name) - pv_state_name_set(state, opts->name); - - if (NULL != opts->format) - pv_state_format_string_set(state, opts->format); - + pv_state_name_set(state, opts->name); + pv_state_format_string_set(state, opts->format); pv_state_watch_pid_set(state, opts->watch_pid); pv_state_watch_fd_set(state, opts->watch_fd); pv_state_average_rate_window_set(state, opts->average_rate_window); diff --git a/src/main/options.c b/src/main/options.c index 53a7494..2b75593 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -130,7 +130,7 @@ bool opts_add_file(opts_t opts, const char *filename) * aren't copied anywhere, just the pointers are copied, so make sure the * command line data isn't overwritten or argv[1] free()d or whatever. */ - /*@null@ *//*@only@ */ + /*@null@ *//*@only@ */ opts_t opts_parse(unsigned int argc, char **argv) { #ifdef HAVE_GETOPT_LONG diff --git a/src/main/remote.c b/src/main/remote.c index df90995..1d751a7 100644 --- a/src/main/remote.c +++ b/src/main/remote.c @@ -64,7 +64,9 @@ static key_t remote__genkey(void) uid_t uid; key_t key; + /*@-type@ *//* splint doesn't like uid_t */ uid = geteuid(); + /*@+type@ */ key = ftok("/tmp", (int) 'P') | uid; @@ -79,7 +81,9 @@ static key_t remote__genkey(void) static int remote__msgget(void) { /* Catch SIGSYS in case msgget() raises it, so we get ENOSYS */ + /*@-unrecog@ *//* splint doesn't see SIGSYS */ (void) signal(SIGSYS, SIG_IGN); + /*@+unrecog@ */ return msgget(remote__genkey(), IPC_CREAT | 0600); } @@ -177,7 +181,9 @@ int pv_remote_set(opts_t opts) memset(&tv, 0, sizeof(tv)); tv.tv_sec = 0; tv.tv_usec = 10000; + /*@-nullpass@ *//* splint: NULL is OK with select() */ (void) select(0, NULL, NULL, NULL, &tv); + /*@+nullpass@ */ timeout -= 10000; /* @@ -212,8 +218,15 @@ int pv_remote_set(opts_t opts) } } + /*@-mustfreefresh@ */ + /* + * splint note: the gettext calls made by _() cause memory leak + * warnings, but in this case it's unavoidable, and mitigated by the + * fact we only translate each string once. + */ fprintf(stderr, "%s: %u: %s\n", opts->program_name, opts->remote, _("message not received")); return 1; + /*@+mustfreefresh @ */ } @@ -239,9 +252,11 @@ void pv_remote_check(pvstate_t state) /* * If our queue had been deleted, re-create it. */ + /*@-unrecog@ *//* splint doesn't see ENOMSG */ if (errno != EAGAIN && errno != ENOMSG) { remote__msgid = remote__msgget(); } + /*@+unrecog@ */ } if (got < 1) return; diff --git a/src/pv/state.c b/src/pv/state.c index 76adefe..4a5b758 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -241,12 +241,12 @@ void pv_state_height_set(pvstate_t state, unsigned int val) state->height = val; }; -void pv_state_name_set(pvstate_t state, const char *val) +void pv_state_name_set(pvstate_t state, /*@null@ */ const char *val) { state->name = val; }; -void pv_state_format_string_set(pvstate_t state, const char *val) +void pv_state_format_string_set(pvstate_t state, /*@null@ */ const char *val) { state->format_string = val; };