Skip to content

Commit

Permalink
Constify arrays of program arguments
Browse files Browse the repository at this point in the history
These are passed to non-const-correct APIs which still need a cast, but
at least we can declare the array in a way that reduces mistakes.

Signed-off-by: Simon McVittie <[email protected]>
  • Loading branch information
smcv authored and GeorgesStavracas committed Aug 22, 2024
1 parent 1aeb381 commit 5964b13
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions revokefs/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ main (int argc, char *argv[])
socket_0 = g_strdup_printf ("--socket=%d", sockets[0]);
socket_1 = g_strdup_printf ("--socket=%d", sockets[1]);

char *backend_argv[] =
const char * const backend_argv[] =
{
"./revokefs-fuse",
"--backend",
Expand All @@ -42,7 +42,7 @@ main (int argc, char *argv[])
/* Don't inherit fuse socket in backend */
fcntl (sockets[1], F_SETFD, FD_CLOEXEC);
if (!g_spawn_async (NULL,
backend_argv,
(char **) backend_argv,
NULL,
G_SPAWN_LEAVE_DESCRIPTORS_OPEN,
NULL, NULL,
Expand All @@ -53,7 +53,7 @@ main (int argc, char *argv[])
}
close (sockets[0]); /* Close backend side now so it doesn't get into the fuse child */

char *fuse_argv[] =
const char * const fuse_argv[] =
{
"./revokefs-fuse",
socket_1,
Expand All @@ -63,7 +63,7 @@ main (int argc, char *argv[])
};

if (!g_spawn_async (NULL,
fuse_argv,
(char **) fuse_argv,
NULL,
G_SPAWN_LEAVE_DESCRIPTORS_OPEN,
NULL, NULL,
Expand Down
5 changes: 3 additions & 2 deletions session-helper/flatpak-session-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ start_p11_kit_server (const char *flatpak_dir)
g_autoptr(GError) local_error = NULL;
g_auto(GStrv) stdout_lines = NULL;
int i;
char *p11_argv[] = {
const char * const p11_argv[] = {
"p11-kit", "server",
/* We explicitly request --sh here, because we then fail on earlier versions that doesn't support
* this flag. This is good, because those earlier versions did not properly daemonize and caused
Expand All @@ -713,7 +713,8 @@ start_p11_kit_server (const char *flatpak_dir)
g_info ("starting p11-kit server");

if (!g_spawn_sync (NULL,
p11_argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
(char **) p11_argv, NULL,
G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL,
&p11_kit_stdout, NULL,
&exit_status, &local_error))
Expand Down
4 changes: 2 additions & 2 deletions tests/can-use-fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ check_fuse (void)
{
g_autofree gchar *fusermount = NULL;
g_autofree gchar *path = NULL;
char *argv[] = { "flatpak-fuse-test", NULL };
struct fuse_args args = FUSE_ARGS_INIT (G_N_ELEMENTS (argv) - 1, argv);
static const char * const argv[] = { "flatpak-fuse-test", NULL };
struct fuse_args args = FUSE_ARGS_INIT (G_N_ELEMENTS (argv) - 1, (char **) argv);
g_autoptr(GError) error = NULL;
#if FUSE_USE_VERSION >= 31
struct fuse *fuse = NULL;
Expand Down

0 comments on commit 5964b13

Please sign in to comment.