summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2023-03-20 11:20:10 +0000
committerSimon McVittie <smcv@collabora.com>2023-03-20 12:19:15 +0000
commit0e3e646839bbf5c03d8c190edc68affc279556d0 (patch)
treef7e3cf89ef52c98ebc8de00bee1bac5fc0f9c143
parent43085c0e2a3ccfe9e3735b034a5d6a9fc6f5c7b4 (diff)
downloadflatpak-0e3e646839bbf5c03d8c190edc68affc279556d0.tar.gz
run: Make it clearer that rest_argv_start is not used uninitialized
rest_argv_start is initialized whenever rest_argc != 0, so the previous code was in fact safe; but this wasn't obvious to either a human reader or the compiler, and some gcc versions warn here. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--app/flatpak-builtins-run.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/app/flatpak-builtins-run.c b/app/flatpak-builtins-run.c
index 69975e21..4948e0b9 100644
--- a/app/flatpak-builtins-run.c
+++ b/app/flatpak-builtins-run.c
@@ -101,7 +101,7 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
g_autoptr(FlatpakDecomposed) runtime_ref = NULL;
const char *pref;
int i;
- int rest_argv_start, rest_argc;
+ int rest_argv_start = 0, rest_argc = 0;
g_autoptr(FlatpakContext) arg_context = NULL;
g_autofree char *id = NULL;
g_autofree char *arch = NULL;
@@ -114,7 +114,6 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
context = g_option_context_new (_("APP [ARGUMENT…] - Run an app"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
- rest_argc = 0;
for (i = 1; i < argc; i++)
{
/* The non-option is the command, take it out of the arguments */
@@ -155,6 +154,8 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
if (rest_argc == 0)
return usage_error (context, _("APP must be specified"), error);
+ /* If we get here, then rest_argv_start must have been set >= 1 */
+ g_assert (rest_argv_start > 0);
pref = argv[rest_argv_start];
if (!flatpak_split_partial_ref_arg (pref, FLATPAK_KINDS_APP | FLATPAK_KINDS_RUNTIME,