GNOME Bugzilla – Bug 794732
Fix various compiler warnings
Last modified: 2018-03-28 10:53:38 UTC
SSIA. The first attachment is kind of unrelated, but it solves an issue reported here: https://gitlab.gnome.org/GNOME/gtk/issues/136 The other attachments are related to building GLib as a sub-project when building GTK on our continuous integration pipeline, and make it impossible to build GLib with `--werror` enabled.
Created attachment 370203 [details] [review] Do not use g_autofree The g_auto macros are available only with GCC-compatible compilers on Unix, but having __attribute__((cleanup)) is not part of our toolchain requirements, so we shouldn't use it — even if we are building on Unix-compatible systems.
Created attachment 370204 [details] [review] Ignore GCC memory overflow warnings when testing overflows We know we are overflowing the maximum allocation: it's what we're testing for.
Created attachment 370205 [details] [review] Initialize variables before using them Avoid a compiler warning when using the average, minimum, and maximum elapsed variables without initializing them.
Created attachment 370206 [details] [review] Initialize boolean variable There can be branches where the `interesting` variable isn't initialized.
Created attachment 370207 [details] [review] Initialize variable The `mount_monitor` variable is only set if the boolean `with_mount_monitor` variable is set to TRUE, but the compiler does not know that, so it'll warn when calling `g_clear_object()` even if the clearing operation is gated with the same boolean. Initializing with NULL does not cost us anything, and eliminates a conditional branch.
Review of attachment 370203 [details] [review]: ++
Review of attachment 370204 [details] [review]: ++
Review of attachment 370205 [details] [review]: ++
Review of attachment 370206 [details] [review]: I’d slightly prefer to add an `else` branch on the main `if`, which is where the missing initialisation is, and explicitly initialise it there. Then if someone adds a new branch without initialising it there, they will get the warning again, rather than a default value which might not be correct for the branch they’ve added.
Review of attachment 370207 [details] [review]: ++
Created attachment 370215 [details] [review] Initialize boolean variable There can be branches where the `interesting` variable isn't initialized.
Review of attachment 370215 [details] [review]: ++
Attachment 370203 [details] pushed as 07731ff - Do not use g_autofree Attachment 370204 [details] pushed as 327c379 - Ignore GCC memory overflow warnings when testing overflows Attachment 370205 [details] pushed as 94d4e8b - Initialize variables before using them Attachment 370207 [details] pushed as ac42183 - Initialize variable Attachment 370215 [details] pushed as dd8d33d - Initialize boolean variable