All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings"
@ 2017-06-28 12:04 Thomas Huth
  2017-06-28 17:27 ` David Hildenbrand
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Huth @ 2017-06-28 12:04 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Drew Jones, David Hildenbrand

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings"
  2017-06-28 12:04 [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings" Thomas Huth
@ 2017-06-28 17:27 ` David Hildenbrand
  2017-06-28 20:10   ` Thomas Huth
  0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2017-06-28 17:27 UTC (permalink / raw)
  To: Thomas Huth, kvm; +Cc: Paolo Bonzini, Radim Krčmář, Drew Jones

On 28.06.2017 14:04, Thomas Huth wrote:
> So we make sure that we do not accidentially write to constant

"accidentally" (I wouldn't know if Thunderbird wouldn't tell me ;) )

> 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


I assume this option has been around for quite some while, so no
reasonable gcc will spit fire.

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 

Thanks,

David

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings"
  2017-06-28 17:27 ` David Hildenbrand
@ 2017-06-28 20:10   ` Thomas Huth
  2017-06-28 20:41     ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Huth @ 2017-06-28 20:10 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Paolo Bonzini, Radim Krčmář, Drew Jones

On 28.06.2017 19:27, David Hildenbrand wrote:
> On 28.06.2017 14:04, Thomas Huth wrote:
>> So we make sure that we do not accidentially write to constant
> 
> "accidentally" (I wouldn't know if Thunderbird wouldn't tell me ;) )

Oh, ok. Paolo, Radim, could you please fix it when picking up the patch?

>> 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
> 
> 
> I assume this option has been around for quite some while, so no
> reasonable gcc will spit fire.

A very quick search revealed that it is at least 14 years old and GCC
4.4 already contained it. Likely even earlier versions. I think we do
not really support older versions anymore, so that should be ok.

> Reviewed-by: David Hildenbrand <david@redhat.com>

Thanks!

 Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings"
  2017-06-28 20:10   ` Thomas Huth
@ 2017-06-28 20:41     ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2017-06-28 20:41 UTC (permalink / raw)
  To: Thomas Huth, David Hildenbrand, kvm
  Cc: Radim Krčmář, Drew Jones



On 28/06/2017 22:10, Thomas Huth wrote:
> On 28.06.2017 19:27, David Hildenbrand wrote:
>> On 28.06.2017 14:04, Thomas Huth wrote:
>>> So we make sure that we do not accidentially write to constant
>>
>> "accidentally" (I wouldn't know if Thunderbird wouldn't tell me ;) )
> 
> Oh, ok. Paolo, Radim, could you please fix it when picking up the patch?

Sure.

>> I assume this option has been around for quite some while, so no
>> reasonable gcc will spit fire.
> 
> A very quick search revealed that it is at least 14 years old and GCC
> 4.4 already contained it. Likely even earlier versions. I think we do
> not really support older versions anymore, so that should be ok.

Yes, I think I've used it in GCC 2.x or so. :)

Paolo

>> Reviewed-by: David Hildenbrand <david@redhat.com>
> 
> Thanks!
> 
>  Thomas
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-06-28 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-28 12:04 [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings" Thomas Huth
2017-06-28 17:27 ` David Hildenbrand
2017-06-28 20:10   ` Thomas Huth
2017-06-28 20:41     ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.