]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wireguard-tools: const correctness
authorKyle Evans <kevans@FreeBSD.org>
Wed, 10 Mar 2021 14:43:56 +0000 (08:43 -0600)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 11 Mar 2021 00:35:18 +0000 (17:35 -0700)
Fixes much of the noise from a FreeBSD WARNS=6 build of wg(8)

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
src/config.c
src/config.h
src/genkey.c
src/pubkey.c
src/set.c
src/setconf.c
src/show.c
src/showconf.c
src/subcommands.h
src/wg.c

index e0b4b7ce1dfacc1180fdebe834ba083d0bcc015c..211e8872251c3af47e443f8a239bbec08cd30bc6 100644 (file)
@@ -561,7 +561,7 @@ static char *strip_spaces(const char *in)
        return out;
 }
 
-struct wgdevice *config_read_cmd(char *argv[], int argc)
+struct wgdevice *config_read_cmd(const char *argv[], int argc)
 {
        struct wgdevice *device = calloc(1, sizeof(*device));
        struct wgpeer *peer = NULL;
index 8bbe23639d1ecb4368576eaa8818dafb5abbeb0f..c52b9ea6b6aa05bd5092915da82df3a550fc55e2 100644 (file)
@@ -19,7 +19,7 @@ struct config_ctx {
        bool is_peer_section, is_device_section;
 };
 
-struct wgdevice *config_read_cmd(char *argv[], int argc);
+struct wgdevice *config_read_cmd(const char *argv[], int argc);
 bool config_read_init(struct config_ctx *ctx, bool append);
 bool config_read_line(struct config_ctx *ctx, const char *line);
 struct wgdevice *config_read_finish(struct config_ctx *ctx);
index ef7770bd8d41708184a03668e11e971f49a1b17f..759a89d0defd24c249c9cb1c8db21ffddf71c649 100644 (file)
@@ -72,7 +72,7 @@ static inline bool __attribute__((__warn_unused_result__)) get_random_bytes(uint
 }
 #endif
 
-int genkey_main(int argc, char *argv[])
+int genkey_main(int argc, const char *argv[])
 {
        uint8_t key[WG_KEY_LEN];
        char base64[WG_KEY_LEN_BASE64];
index b4478dca4d4751d0a5a39e89035fa448af28db62..b55c1fed958e127ecdcaf332f152100bbf05c517 100644 (file)
@@ -11,7 +11,7 @@
 #include "subcommands.h"
 #include "ctype.h"
 
-int pubkey_main(int argc, char *argv[])
+int pubkey_main(int argc, const char *argv[])
 {
        uint8_t key[WG_KEY_LEN] __attribute__((aligned(sizeof(uintptr_t))));
        char base64[WG_KEY_LEN_BASE64];
index 0a98f7b36683201546e5c94c70896a9cc2d60551..6f0e0cff1a2081223b6cc4947fb377fb2cd54b3d 100644 (file)
--- a/src/set.c
+++ b/src/set.c
@@ -12,7 +12,7 @@
 #include "ipc.h"
 #include "subcommands.h"
 
-int set_main(int argc, char *argv[])
+int set_main(int argc, const char *argv[])
 {
        struct wgdevice *device = NULL;
        int ret = 1;
index 89b30230556453a0c4c81abc0f2afc23b2588f13..bfd0a3a9c07ae438f77aa2a8d2cf9c1e16c18e97 100644 (file)
@@ -98,7 +98,7 @@ static bool sync_conf(struct wgdevice *file)
        return true;
 }
 
-int setconf_main(int argc, char *argv[])
+int setconf_main(int argc, const char *argv[])
 {
        struct wgdevice *device = NULL;
        struct config_ctx ctx;
index e772339c06cb687510abed2c82f5c778ba36b691..761858b346c3c48b68e7a76ebde2248dfe657ee9 100644 (file)
@@ -75,14 +75,14 @@ static char *key(const uint8_t key[static WG_KEY_LEN])
        return base64;
 }
 
-static char *maybe_key(const uint8_t maybe_key[static WG_KEY_LEN], bool have_it)
+static const char *maybe_key(const uint8_t maybe_key[static WG_KEY_LEN], bool have_it)
 {
        if (!have_it)
                return "(none)";
        return key(maybe_key);
 }
 
-static char *masked_key(const uint8_t masked_key[static WG_KEY_LEN])
+static const char *masked_key(const uint8_t masked_key[static WG_KEY_LEN])
 {
        const char *var = getenv("WG_HIDE_KEYS");
 
@@ -376,7 +376,7 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
        return true;
 }
 
-int show_main(int argc, char *argv[])
+int show_main(int argc, const char *argv[])
 {
        int ret = 0;
 
index 6e6a4a5a472615b4ffbdd557567f956845cdefc4..64f8b6eeb8e68347965079fad6d209a2a1bcea88 100644 (file)
@@ -18,7 +18,7 @@
 #include "ipc.h"
 #include "subcommands.h"
 
-int showconf_main(int argc, char *argv[])
+int showconf_main(int argc, const char *argv[])
 {
        char base64[WG_KEY_LEN_BASE64];
        char ip[INET6_ADDRSTRLEN];
index 68e9334995f6f98854411755cb80fdcd95d0bb92..7c4ed88d1ba8c1ab9f25c85a7f4022661971f284 100644 (file)
@@ -7,11 +7,11 @@
 #define SUBCOMMANDS_H
 
 extern const char *PROG_NAME;
-int show_main(int argc, char *argv[]);
-int showconf_main(int argc, char *argv[]);
-int set_main(int argc, char *argv[]);
-int setconf_main(int argc, char *argv[]);
-int genkey_main(int argc, char *argv[]);
-int pubkey_main(int argc, char *argv[]);
+int show_main(int argc, const char *argv[]);
+int showconf_main(int argc, const char *argv[]);
+int set_main(int argc, const char *argv[]);
+int setconf_main(int argc, const char *argv[]);
+int genkey_main(int argc, const char *argv[]);
+int pubkey_main(int argc, const char *argv[]);
 
 #endif
index b9952ebda843f8f0d2baecaac512b218c331406e..aed70b6a2d3fdda9c6908487435f57992d954905 100644 (file)
--- a/src/wg.c
+++ b/src/wg.c
@@ -14,7 +14,7 @@ const char *PROG_NAME;
 
 static const struct {
        const char *subcommand;
-       int (*function)(int, char**);
+       int (*function)(int, const char**);
        const char *description;
 } subcommands[] = {
        { "show", show_main, "Shows the current configuration and device information" },
@@ -37,7 +37,7 @@ static void show_usage(FILE *file)
        fprintf(file, "You may pass `--help' to any of these subcommands to view usage.\n");
 }
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
        PROG_NAME = argv[0];
 
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
        }
 
        if (argc == 1) {
-               static char *new_argv[] = { "show", NULL };
+               static const char *new_argv[] = { "show", NULL };
                return show_main(1, new_argv);
        }