diff options
author | Jacob Garber <jgarber1@ualberta.ca> | 2019-07-25 19:12:31 -0600 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2019-10-04 14:35:20 +0000 |
commit | 4a84ec273a487c27f91bd3df70cbdf8894af70e1 (patch) | |
tree | faee09346d0a195ac778befa68a87c5f669cfe22 | |
parent | de77ad4678cb33ca0b58edf89fab8113eb304bcd (diff) | |
download | flashrom-4a84ec273a487c27f91bd3df70cbdf8894af70e1.tar.gz flashrom-4a84ec273a487c27f91bd3df70cbdf8894af70e1.tar.bz2 flashrom-4a84ec273a487c27f91bd3df70cbdf8894af70e1.zip |
tree: Enable -Wwrite-strings
When compiling, this warning gives string literals the type const char[]
to help catch accidental modification (which is undefined behaviour).
There currently aren't any instances of this in flashrom, so let's
enable this warning to keep it that way. This requires adding const
qualifiers to the declarations of several variables that work with
string literals.
Change-Id: I62d9bc194938a0c9a0e4cdff7ced8ea2e14cc1bc
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/34577
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: David Hendricks <david.hendricks@gmail.com>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | buspirate_spi.c | 2 | ||||
-rw-r--r-- | cli_classic.c | 2 | ||||
-rw-r--r-- | dmi.c | 2 | ||||
-rw-r--r-- | meson.build | 3 | ||||
-rw-r--r-- | pony_spi.c | 2 | ||||
-rw-r--r-- | util/ich_descriptors_tool/ich_descriptors_tool.c | 2 |
7 files changed, 8 insertions, 7 deletions
@@ -30,7 +30,7 @@ INSTALL = install DIFF = diff PREFIX ?= /usr/local MANDIR ?= $(PREFIX)/share/man -CFLAGS ?= -Os -Wall -Wshadow -Wmissing-prototypes +CFLAGS ?= -Os -Wall -Wshadow -Wmissing-prototypes -Wwrite-strings EXPORTDIR ?= . RANLIB ?= ranlib PKG_CONFIG ?= pkg-config diff --git a/buspirate_spi.c b/buspirate_spi.c index 08cd04cf..826bd841 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -113,7 +113,7 @@ static int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, return 0; } -static int buspirate_wait_for_string(unsigned char *buf, char *key) +static int buspirate_wait_for_string(unsigned char *buf, const char *key) { unsigned int keylen = strlen(key); int ret; diff --git a/cli_classic.c b/cli_classic.c index d23298e9..4844d1dc 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -79,7 +79,7 @@ static void cli_classic_abort_usage(void) exit(1); } -static int check_filename(char *filename, char *type) +static int check_filename(char *filename, const char *type) { if (!filename || (filename[0] == '\0')) { fprintf(stderr, "Error: No %s file specified.\n", type); @@ -69,7 +69,7 @@ static struct { static const struct { uint8_t type; uint8_t is_laptop; - char *name; + const char *name; } dmi_chassis_types[] = { {0x01, 2, "Other"}, {0x02, 2, "Unknown"}, diff --git a/meson.build b/meson.build index e1b6c166..d778d716 100644 --- a/meson.build +++ b/meson.build @@ -11,8 +11,9 @@ lt_revision = '0' lt_age = '0' lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision) -# hide some warnings +# hide/enable some warnings warning_flags = [ + '-Wwrite-strings', '-Wno-unused-parameter', '-Wno-sign-compare', '-Wno-address-of-packed-member', @@ -115,7 +115,7 @@ int pony_spi_init(void) int i, data_out; char *arg = NULL; enum pony_type type = TYPE_SI_PROG; - char *name; + const char *name; int have_device = 0; int have_prog = 0; diff --git a/util/ich_descriptors_tool/ich_descriptors_tool.c b/util/ich_descriptors_tool/ich_descriptors_tool.c index 2db0f62f..6f13749b 100644 --- a/util/ich_descriptors_tool/ich_descriptors_tool.c +++ b/util/ich_descriptors_tool/ich_descriptors_tool.c @@ -111,7 +111,7 @@ static void dump_files(const char *name, const uint32_t *buf, unsigned int len, printf("\n"); } -static void usage(char *argv[], char *error) +static void usage(char *argv[], const char *error) { if (error != NULL) { fprintf(stderr, "%s\n", error); |