From: Thomas Huth <thuth@redhat.com>
To: kvm@vger.kernel.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>,
"Drew Jones" <drjones@redhat.com>,
"David Hildenbrand" <david@redhat.com>
Subject: [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings"
Date: Wed, 28 Jun 2017 14:04:17 +0200 [thread overview]
Message-ID: <1498651457-19688-1-git-send-email-thuth@redhat.com> (raw)
So we make sure that we do not accidentially write to constant
strings. Also add some missing "const" qualifiers in the code to
avoid that we get compiler warnings now.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
This patch supersedes my previous patch "Declare the prefix string
variable in va_report() as const"
Makefile | 2 +-
lib/report.c | 6 +++---
x86/msr.c | 4 ++--
x86/pmu.c | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index 933b9f0..e79cf93 100644
--- a/Makefile
+++ b/Makefile
@@ -51,7 +51,7 @@ cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
CFLAGS += -g
-CFLAGS += $(autodepend-flags) -Wall -Werror
+CFLAGS += $(autodepend-flags) -Wall -Wwrite-strings -Werror
frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "")
fnostack_protector := $(call cc-option, -fno-stack-protector, "")
diff --git a/lib/report.c b/lib/report.c
index b002d21..5da27ab 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -81,9 +81,9 @@ void report_prefix_pop(void)
static void va_report(const char *msg_fmt,
bool pass, bool xfail, bool skip, va_list va)
{
- char *prefix = skip ? "SKIP"
- : xfail ? (pass ? "XPASS" : "XFAIL")
- : (pass ? "PASS" : "FAIL");
+ const char *prefix = skip ? "SKIP"
+ : xfail ? (pass ? "XPASS" : "XFAIL")
+ : (pass ? "PASS" : "FAIL");
spin_lock(&lock);
diff --git a/x86/msr.c b/x86/msr.c
index 91351a3..ffc24b1 100644
--- a/x86/msr.c
+++ b/x86/msr.c
@@ -6,7 +6,7 @@
struct msr_info {
int index;
- char *name;
+ const char *name;
struct tc {
int valid;
unsigned long long value;
@@ -78,7 +78,7 @@ static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l
{
unsigned long long r = 0;
int index;
- char *sptr;
+ const char *sptr;
if ((index = find_msr_info(msr_index)) != -1) {
sptr = msr_info[index].name;
} else {
diff --git a/x86/pmu.c b/x86/pmu.c
index c689800..a0238dc 100644
--- a/x86/pmu.c
+++ b/x86/pmu.c
@@ -73,7 +73,7 @@ union cpuid10_edx {
} edx;
struct pmu_event {
- char *name;
+ const char *name;
uint32_t unit_sel;
int min;
int max;
--
1.8.3.1
next reply other threads:[~2017-06-28 12:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-28 12:04 Thomas Huth [this message]
2017-06-28 17:27 ` [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings" David Hildenbrand
2017-06-28 20:10 ` Thomas Huth
2017-06-28 20:41 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1498651457-19688-1-git-send-email-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=david@redhat.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox