Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Thu, 16 Nov 2023 09:55:22 UTC Commit: 73658f185b0398b2ec8610d6060f84033906001d https://github.com/geany/geany/commit/73658f185b0398b2ec8610d6060f8403390600...
Log Message: ----------- "Fix" passing const arguments to spawn functions
`char**` doesn't coerce to `const char**` or any variant thereof, so APIs expecting a `const char *const *` (like execv-style functions) usually just use `char**` as it's usually effectively *more* convenient for a caller.
However, this means that if we want to pass const data, we need a cast (that is safe, as we know the API contract).
If making the compiler treat string literals as const (using e.g. GCC's -Wwrite-strings), building an argument list composed of literals still need to be const, so make it so and add a cast to the API call.
Modified Paths: -------------- src/build.c src/printing.c
Modified: src/build.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -771,7 +771,7 @@ static gchar *build_replace_placeholder(const GeanyDocument *doc, const gchar *s static void build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir) { GError *error = NULL; - gchar *argv[] = { "/bin/sh", "-c", NULL, NULL }; + const gchar *argv[] = { "/bin/sh", "-c", NULL, NULL }; gchar *working_dir; gchar *utf8_working_dir; gchar *cmd_string; @@ -813,7 +813,7 @@ static void build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *d build_info.file_type_id = (doc == NULL) ? GEANY_FILETYPES_NONE : doc->file_type->id; build_info.message_count = 0;
- if (!spawn_with_callbacks(working_dir, cmd, argv, NULL, 0, NULL, NULL, build_iofunc, + if (!spawn_with_callbacks(working_dir, cmd, (gchar **) argv, NULL, 0, NULL, NULL, build_iofunc, GINT_TO_POINTER(0), 0, build_iofunc, GINT_TO_POINTER(1), 0, build_exit_cb, NULL, &build_info.pid, &error)) {
Modified: src/printing.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -602,9 +602,9 @@ static void print_external(GeanyDocument *doc) /* /bin/sh -c emulates the system() call and makes complex commands possible * but only on non-win32 systems due to the lack of win32's shell capabilities */ #ifdef G_OS_UNIX - gchar *argv[] = { "/bin/sh", "-c", cmdline, NULL }; + const gchar *argv[] = { "/bin/sh", "-c", cmdline, NULL };
- if (!spawn_async(NULL, NULL, argv, NULL, NULL, &error)) + if (!spawn_async(NULL, NULL, (gchar **) argv, NULL, NULL, &error)) #else if (!spawn_async(NULL, cmdline, NULL, NULL, NULL, &error)) #endif
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).