diff --git a/source/helper.c b/source/helper.c index b2ddf860..a8abc2e3 100644 --- a/source/helper.c +++ b/source/helper.c @@ -1319,40 +1319,40 @@ void rofi_output_formatted_line(const char *format, const char *string, int selected_line, const char *filter) { for (int i = 0; format && format[i]; i++) { if (format[i] == 'i') { - fprintf(stdout, "%d", selected_line); + (void)fprintf(stdout, "%d", selected_line); } else if (format[i] == 'd') { - fprintf(stdout, "%d", (selected_line + 1)); + (void)fprintf(stdout, "%d", (selected_line + 1)); } else if (format[i] == 's') { - fputs(string, stdout); + (void)fputs(string, stdout); } else if (format[i] == 'p') { char *esc = NULL; pango_parse_markup(string, -1, 0, NULL, &esc, NULL, NULL); if (esc) { - fputs(esc, stdout); + (void)fputs(esc, stdout); g_free(esc); } else { - fputs("invalid string", stdout); + (void)fputs("invalid string", stdout); } } else if (format[i] == 'q') { char *quote = g_shell_quote(string); - fputs(quote, stdout); + (void)fputs(quote, stdout); g_free(quote); } else if (format[i] == 'f') { if (filter) { - fputs(filter, stdout); + (void)fputs(filter, stdout); } } else if (format[i] == 'F') { if (filter) { char *quote = g_shell_quote(filter); - fputs(quote, stdout); + (void)fputs(quote, stdout); g_free(quote); } } else { - fputc(format[i], stdout); + (void)fputc(format[i], stdout); } } - fputc('\n', stdout); - fflush(stdout); + (void)fputc('\n', stdout); + (void)fflush(stdout); } static gboolean helper_eval_cb2(const GMatchInfo *info, GString *res, diff --git a/source/history.c b/source/history.c index 94608572..ef38f2d6 100644 --- a/source/history.c +++ b/source/history.c @@ -73,7 +73,7 @@ static void __history_write_element_list(FILE *fd, _element **list, // Write out entries. for (unsigned int iter = 0; iter < length; iter++) { - fprintf(fd, "%ld %s\n", list[iter]->index - min_value, list[iter]->name); + (void)fprintf(fd, "%ld %s\n", list[iter]->index - min_value, list[iter]->name); } } diff --git a/source/mode.c b/source/mode.c index 64d3994b..66edeb87 100644 --- a/source/mode.c +++ b/source/mode.c @@ -123,9 +123,10 @@ char *mode_get_completion(const Mode *mode, unsigned int selected_line) { if (mode->_get_completion != NULL) { return mode->_get_completion(mode, selected_line); } - int state; + int state = 0; g_assert(mode->_get_display_value != NULL); - return mode->_get_display_value(mode, selected_line, &state, NULL, TRUE); + char *retv = mode->_get_display_value(mode, selected_line, &state, NULL, TRUE); + return retv; } ModeMode mode_result(Mode *mode, int menu_retv, char **input, @@ -203,10 +204,11 @@ const char *mode_get_display_name(const Mode *mode) { } void mode_set_config(Mode *mode) { - snprintf(mode->cfg_name_key, 128, "display-%s", mode->name); - config_parser_add_option(xrm_String, mode->cfg_name_key, - (void **)&(mode->display_name), - "The display name of this browser"); + if (snprintf(mode->cfg_name_key, 128, "display-%s", mode->name) > 0 ){ + config_parser_add_option(xrm_String, mode->cfg_name_key, + (void **)&(mode->display_name), + "The display name of this browser"); + } } char *mode_preprocess_input(Mode *mode, const char *input) { diff --git a/source/modes/combi.c b/source/modes/combi.c index 25b6ce85..a8b6e06f 100644 --- a/source/modes/combi.c +++ b/source/modes/combi.c @@ -254,8 +254,9 @@ static char *combi_mgrv(const Mode *sw, unsigned int selected_line, int *state, wid, P_COLOR, pd->switchers[i].mode->name, TRUE); if (p != NULL) { PangoAttribute *pa = pango_attr_foreground_new( - p->value.color.red * 65535, p->value.color.green * 65535, - p->value.color.blue * 65535); + (guint16)(p->value.color.red * UINT16_MAX), + (guint16)(p->value.color.green * UINT16_MAX), + (guint16)(p->value.color.blue * UINT16_MAX)); pa->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING; pa->end_index = strlen(dname); *attr_list = g_list_append(*attr_list, pa); diff --git a/source/modes/dmenu.c b/source/modes/dmenu.c index fd55af21..2f7c0d4c 100644 --- a/source/modes/dmenu.c +++ b/source/modes/dmenu.c @@ -753,7 +753,7 @@ static void dmenu_finish(DmenuModePrivateData *pd, RofiViewState *state, } if (pd->fd_file != NULL) { if (pd->fd_file != stdin) { - fclose(pd->fd_file); + (void)fclose(pd->fd_file); } } if (retv == FALSE) { diff --git a/source/modes/drun.c b/source/modes/drun.c index f384304b..06ce7544 100644 --- a/source/modes/drun.c +++ b/source/modes/drun.c @@ -953,17 +953,25 @@ static gint drun_int_sort_list(gconstpointer a, gconstpointer b, /** Version of the DRUN cache file format. */ #define CACHE_VERSION 3 -static void drun_write_str(FILE *fd, const char *str) { +static int drun_write_str(FILE *fd, const char *str) { size_t l = (str == NULL ? 0 : strlen(str)); - fwrite(&l, sizeof(l), 1, fd); + if(fwrite(&l, sizeof(l), 1, fd)<=0){ + return 1; + } // Only write string if it is not NULL or empty. if (l > 0) { // Also writeout terminating '\0' - fwrite(str, 1, l + 1, fd); + if ( fwrite(str, 1, l + 1, fd) <= 0 ){ + return 1; + } } + return 0; } -static void drun_write_integer(FILE *fd, int32_t val) { - fwrite(&val, sizeof(val), 1, fd); +static int drun_write_integer(FILE *fd, int32_t val) { + if ( fwrite(&val, sizeof(val), 1, fd) <= 0 ){ + return 1; + } + return 0; } static gboolean drun_read_integer(FILE *fd, int32_t *type) { if (fread(type, sizeof(int32_t), 1, fd) != 1) { @@ -993,9 +1001,13 @@ static gboolean drun_read_string(FILE *fd, char **str) { } static void drun_write_strv(FILE *fd, char **str) { guint vl = (str == NULL ? 0 : g_strv_length(str)); - fwrite(&vl, sizeof(vl), 1, fd); + if ( fwrite(&vl, sizeof(vl), 1, fd) <= 0 ){ + return; + } for (guint index = 0; index < vl; index++) { - drun_write_str(fd, str[index]); + if ( drun_write_str(fd, str[index])){ + return ; + } } } static gboolean drun_read_stringv(FILE *fd, char ***str) { @@ -1029,9 +1041,17 @@ static void write_cache(DRunModePrivateData *pd, const char *cache_file) { return; } uint8_t version = CACHE_VERSION; - fwrite(&version, sizeof(version), 1, fd); + if ( fwrite(&version, sizeof(version), 1, fd) <= 0 ){ + g_warning("Failed to write to drun cache file."); + (void)(void)fclose(fd); + return; + } - fwrite(&(pd->cmd_list_length), sizeof(pd->cmd_list_length), 1, fd); + if ( fwrite(&(pd->cmd_list_length), sizeof(pd->cmd_list_length), 1, fd) <= 0){ + g_warning("Failed to write to drun cache file."); + (void)(void)fclose(fd); + return; + } for (unsigned int index = 0; index < pd->cmd_list_length; index++) { DRunModeEntry *entry = &(pd->entry_list[index]); @@ -1053,7 +1073,7 @@ static void write_cache(DRunModePrivateData *pd, const char *cache_file) { drun_write_integer(fd, (int32_t)entry->type); } - fclose(fd); + (void)(void)fclose(fd); TICK_N("DRUN Write CACHE: end"); } @@ -1080,21 +1100,21 @@ static gboolean drun_read_cache(DRunModePrivateData *pd, uint8_t version = 0; if (fread(&version, sizeof(version), 1, fd) != 1) { - fclose(fd); + (void)fclose(fd); g_warning("Cache corrupt, ignoring."); TICK_N("DRUN Read CACHE: stop"); return TRUE; } if (version != CACHE_VERSION) { - fclose(fd); + (void)fclose(fd); g_warning("Cache file wrong version, ignoring."); TICK_N("DRUN Read CACHE: stop"); return TRUE; } if (fread(&(pd->cmd_list_length), sizeof(pd->cmd_list_length), 1, fd) != 1) { - fclose(fd); + (void)fclose(fd); g_warning("Cache corrupt, ignoring."); TICK_N("DRUN Read CACHE: stop"); return TRUE; @@ -1171,7 +1191,7 @@ static gboolean drun_read_cache(DRunModePrivateData *pd, entry->type = type; } - fclose(fd); + (void)fclose(fd); if (error) { for (size_t i = 0; i < pd->cmd_list_length; i++) { drun_entry_clear(&(pd->entry_list[i])); diff --git a/source/modes/script.c b/source/modes/script.c index 36bbb757..18826fb2 100644 --- a/source/modes/script.c +++ b/source/modes/script.c @@ -636,7 +636,7 @@ Mode *script_mode_parse_setup(const char *str) { return sw; } - fprintf( + (void)fprintf( stderr, "The script command '%s' has %u options, but needs 2: :