Skip to content

Commit

Permalink
Import ostree's compiler warnings, fix up callers
Browse files Browse the repository at this point in the history
In ostree I maintain what I consider a "baseline" set of compiler
warnings that should *always* be fatal for a modern C project.

I noticed while working on a previous patch that a `-Werror=format`
warning wasn't fatal.

There are a few that are really, really important like
`-Werror=missing-prototypes`. I also take some like `-Werror=misleading-indentation`
which already caught some bugs.  See also https://lwn.net/Articles/678019/
  • Loading branch information
cgwalters authored and alexlarsson committed Mar 27, 2017
1 parent 64fd2c2 commit 2618a19
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ libtool
ltmain.sh
m4/*.m4
!m4/glibtests.m4
!m4/attributes.m4
missing
stamp-h1
config.h.in
Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ AM_CPPFLAGS = \
-I$(builddir)/lib \
$(NULL)

AM_CFLAGS = $(WARN_CFLAGS)

if WITH_SYSTEM_BWRAP
AM_CPPFLAGS += -DHELPER=\"$(BWRAP)\"
else
Expand Down
18 changes: 9 additions & 9 deletions common/flatpak-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ flatpak_get_user_base_dir_location (void)
return g_object_ref ((GFile *)file);
}

GFile *
static GFile *
flatpak_get_user_cache_dir_location (void)
{
g_autoptr(GFile) base_dir = NULL;
Expand All @@ -585,7 +585,7 @@ flatpak_get_user_cache_dir_location (void)
return g_file_get_child (base_dir, "system-cache");
}

GFile *
static GFile *
flatpak_ensure_user_cache_dir_location (GError **error)
{
g_autoptr(GFile) cache_dir = NULL;
Expand All @@ -603,7 +603,7 @@ flatpak_ensure_user_cache_dir_location (GError **error)
return g_steal_pointer (&cache_dir);
}

GFile *
static GFile *
flatpak_ensure_oci_summary_cache_dir_location (GError **error)
{
g_autoptr(GFile) cache_dir = NULL;
Expand Down Expand Up @@ -658,7 +658,7 @@ flatpak_dir_get_system_helper (FlatpakDir *self)
return NULL;
}

gboolean
static gboolean
flatpak_dir_use_system_helper (FlatpakDir *self,
const char *installing_from_remote)
{
Expand Down Expand Up @@ -2921,7 +2921,7 @@ flatpak_dir_set_active (FlatpakDir *self,
return ret;
}

gboolean
static gboolean
flatpak_dir_run_triggers (FlatpakDir *self,
GCancellable *cancellable,
GError **error)
Expand Down Expand Up @@ -3349,7 +3349,7 @@ rewrite_export_dir (const char *app,
return ret;
}

gboolean
static gboolean
flatpak_rewrite_export_dir (const char *app,
const char *branch,
const char *arch,
Expand Down Expand Up @@ -3467,7 +3467,7 @@ export_dir (int source_parent_fd,
return ret;
}

gboolean
static gboolean
flatpak_export_dir (GFile *source,
GFile *destination,
const char *symlink_prefix,
Expand Down Expand Up @@ -6146,7 +6146,7 @@ find_matching_ref (GHashTable *refs,
parts[3]));
}

flatpak_fail (error, err->str);
flatpak_fail (error, "%s", err->str);
return NULL;
}

Expand Down Expand Up @@ -6606,7 +6606,7 @@ flatpak_dir_remote_has_deploys (FlatpakDir *self,
return FALSE;
}

gint
static gint
cmp_remote (gconstpointer a,
gconstpointer b,
gpointer user_data)
Expand Down
8 changes: 4 additions & 4 deletions common/flatpak-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ flatpak_context_set_system_bus_policy (FlatpakContext *context,
g_hash_table_insert (context->system_bus_policy, g_strdup (name), GINT_TO_POINTER (policy));
}

void
static void
flatpak_context_apply_generic_policy (FlatpakContext *context,
const char *key,
const char *value)
Expand Down Expand Up @@ -2075,7 +2075,7 @@ create_proxy_socket (char *template)
return g_steal_pointer (&proxy_socket);
}

gboolean
static gboolean
flatpak_run_add_system_dbus_args (FlatpakContext *context,
char ***envp_p,
GPtrArray *argv_array,
Expand Down Expand Up @@ -2127,7 +2127,7 @@ flatpak_run_add_system_dbus_args (FlatpakContext *context,
return FALSE;
}

gboolean
static gboolean
flatpak_run_add_session_dbus_args (GPtrArray *argv_array,
char ***envp_p,
GPtrArray *dbus_proxy_argv,
Expand Down Expand Up @@ -3487,7 +3487,7 @@ add_document_portal_args (GPtrArray *argv_array,
}
}

gchar *
static gchar *
join_args (GPtrArray *argv_array, gsize *len_out)
{
gchar *string;
Expand Down
13 changes: 10 additions & 3 deletions common/flatpak-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ flatpak_path_match_prefix (const char *pattern,
return NULL; /* Should not be reached */
}

const char *
static const char *
flatpak_get_kernel_arch (void)
{
static struct utsname buf;
Expand Down Expand Up @@ -858,7 +858,7 @@ flatpak_kinds_from_bools (gboolean app, gboolean runtime)
return kinds;
}

gboolean
static gboolean
_flatpak_split_partial_ref_arg (const char *partial_ref,
gboolean validate,
FlatpakKinds default_kinds,
Expand Down Expand Up @@ -4695,9 +4695,13 @@ flatpak_yes_no_prompt (const char *prompt, ...)
va_list var_args;
gchar *s;


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
va_start (var_args, prompt);
s = g_strdup_vprintf (prompt, var_args);
va_end (var_args);
#pragma GCC diagnostic pop

while (TRUE)
{
Expand Down Expand Up @@ -5098,9 +5102,12 @@ flatpak_complete_word (FlatpakCompletion *completion,

g_return_if_fail (format != NULL);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
va_start (args, format);
string = g_strdup_vprintf (format, args);
va_end (args);
#pragma GCC diagnostic pop

if (!g_str_has_prefix (string, completion->cur))
return;
Expand Down Expand Up @@ -5144,7 +5151,7 @@ flatpak_complete_ref (FlatpakCompletion *completion,
}
}

int
static int
find_current_element (const char *str)
{
int count = 0;
Expand Down
6 changes: 3 additions & 3 deletions common/flatpak-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ gboolean flatpak_allocate_tmpdir (int tmpdir_dfd,
GError **error);


gboolean flatpak_yes_no_prompt (const char *prompt, ...);
long flatpak_number_prompt (int min, int max, const char *prompt, ...);
gboolean flatpak_yes_no_prompt (const char *prompt, ...) G_GNUC_PRINTF(1, 2);
long flatpak_number_prompt (int min, int max, const char *prompt, ...) G_GNUC_PRINTF(3, 4);

typedef void (*FlatpakLoadUriProgress) (guint64 downloaded_bytes,
gpointer user_data);
Expand Down Expand Up @@ -621,7 +621,7 @@ FlatpakCompletion *flatpak_completion_new (const char *arg_line,
const char *arg_cur);
void flatpak_complete_word (FlatpakCompletion *completion,
char *format,
...);
...) G_GNUC_PRINTF(2,3);
void flatpak_complete_ref (FlatpakCompletion *completion,
OstreeRepo *repo);
void flatpak_complete_partial_ref (FlatpakCompletion *completion,
Expand Down
26 changes: 20 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,26 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$PACKAGE", [gettext domain])
AM_SILENT_RULES([yes])
AM_MAINTAINER_MODE([enable])

if test "x$GCC" = "xyes"; then
case " $CFLAGS " in
*[[\ \ ]]-Wall[[\ \ ]]*) ;;
*) CFLAGS="$CFLAGS -Wall" ;;
esac
fi
dnl This list is shared with https://github.com/ostreedev/ostree
CC_CHECK_FLAGS_APPEND([WARN_CFLAGS], [CFLAGS], [\
-pipe \
-Wall \
-Werror=empty-body \
-Werror=strict-prototypes \
-Werror=missing-prototypes \
-Werror=implicit-function-declaration \
"-Werror=format=2 -Werror=format-security -Werror=format-nonliteral" \
-Werror=pointer-arith -Werror=init-self \
-Werror=missing-declarations \
-Werror=return-type \
-Werror=overflow \
-Werror=int-conversion \
-Werror=parenthesis \
-Werror=incompatible-pointer-types \
-Werror=misleading-indentation \
-Werror=missing-include-dirs -Werror=aggregate-return \
])
AC_SUBST(WARN_CFLAGS)

AX_VALGRIND_CHECK

Expand Down
1 change: 1 addition & 0 deletions lib/flatpak-installed-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "flatpak-utils.h"
#include "flatpak-installed-ref.h"
#include "flatpak-installed-ref-private.h"
#include "flatpak-enum-types.h"

/**
Expand Down
1 change: 1 addition & 0 deletions lib/flatpak-related-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "flatpak-utils.h"
#include "flatpak-related-ref.h"
#include "flatpak-related-ref-private.h"
#include "flatpak-enum-types.h"

/**
Expand Down

0 comments on commit 2618a19

Please sign in to comment.