Compilation: Add -Wextra to compile arguments + Fix minor resulting warnings

This commit is contained in:
Mario Hüttel 2019-11-12 18:14:07 +01:00
parent d8f6981fe6
commit 40a7e5a650
2 changed files with 9 additions and 10 deletions

View File

@ -6,7 +6,7 @@ pkg_search_module(GLIB REQUIRED glib-2.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0) pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(CAIRO REQUIRED cairo) pkg_check_modules(CAIRO REQUIRED cairo)
add_compile_options(-Wall -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter)
add_subdirectory(resources) add_subdirectory(resources)
add_subdirectory(doxygen) add_subdirectory(doxygen)

View File

@ -106,13 +106,13 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc
char_array = (const char *)g_bytes_get_data(data, &byte_count); char_array = (const char *)g_bytes_get_data(data, &byte_count);
if (!char_array || !byte_count) if (!char_array || !byte_count)
goto ret_unref; goto ret_unref_data;
/* Get maximum lenght of color palette, assuming all entries are valid */ /* Get maximum lenght of color palette, assuming all entries are valid */
lines = count_non_empty_lines_in_array(char_array, byte_count); lines = count_non_empty_lines_in_array(char_array, byte_count);
if (lines <= 0) if (lines <= 0)
goto ret_unref; goto ret_unref_data;
palette->color_array = (GdkRGBA *)malloc(sizeof(GdkRGBA) * (unsigned int)lines); palette->color_array = (GdkRGBA *)malloc(sizeof(GdkRGBA) * (unsigned int)lines);
@ -128,18 +128,17 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc
color_idx = 0; color_idx = 0;
/* interate over lines and match */ /* interate over lines and match */
for (idx = 0 ; idx < byte_count; idx++) { for (idx = 0 ; (unsigned int)idx < byte_count; idx++) {
/* Fillup line. */ /* Fillup line. */
line[line_idx] = char_array[idx]; line[line_idx] = char_array[idx];
/* If end of line/string is reached, process */ /* If end of line/string is reached, process */
if (line[line_idx] == '\n' || line[line_idx] == '\0') { if (line[line_idx] == '\n' || line[line_idx] == '\0') {
line[line_idx] = '\0'; line[line_idx] = '\0';
/* Match the line */ /* Match the line */
g_regex_match(regex, line, 0, &mi); g_regex_match(regex, line, 0, &mi);
if (g_match_info_matches(mi) && color_idx < lines) { if (g_match_info_matches(mi) && color_idx < (unsigned int)lines) {
match = g_match_info_fetch_named(mi, "red"); match = g_match_info_fetch_named(mi, "red");
palette->color_array[color_idx].red = palette->color_array[color_idx].red =
(double)g_ascii_strtoll(match, NULL, 16) / 255.0; (double)g_ascii_strtoll(match, NULL, 16) / 255.0;
@ -169,10 +168,10 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc
continue; continue;
} }
/* increment line index. If end is reached write all bytes to the line end /* increment line index. If end is reached write all bytes to the line end.
* line is longer than required for parsing. This ensures, that everything works as expected * Line is longer than required for parsing. This ensures, that everything works as expected
*/ */
line_idx += (line_idx < sizeof(line)-1 ? 1 : 0); line_idx += ((unsigned int)line_idx < sizeof(line)-1 ? 1 : 0);
} }
/* Data read; Shrink array in case of invalid lines */ /* Data read; Shrink array in case of invalid lines */
@ -180,7 +179,7 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc
palette->color_array_length = color_idx; palette->color_array_length = color_idx;
g_regex_unref(regex); g_regex_unref(regex);
ret_unref: ret_unref_data:
g_bytes_unref(data); g_bytes_unref(data);
return 0; return 0;