Skip to contentSkip to conversation

Declare the prefix string variable in va_report() as const

PATCH In review Thomas Huth 4 participants 5 messages Jun 27, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Declare the prefix string variable in va_report() as const

This way, the code can be compiled with "-Wwrite-strings", too.

---
Not sure whether we want to enable "-Wwrite-strings" globally (since strings in kvm-unit-test are theoretically writable if the test is running without MMU), so I only fixed the code here, without adding it to the Makefile. But if we agree that it is a good idea I can respin the patch and add it to the Makefile, too.

 lib/report.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/report.c +3 -3
index b002d21..c0a701f 100644
@@ -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);
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 9 lines · Thomas Huth

This way, the code can be compiled with "-Wwrite-strings", too.

---
Not sure whether we want to enable "-Wwrite-strings" globally (since strings in kvm-unit-test are theoretically writable if the test is running without MMU), so I only fixed the code here, without adding it to the Makefile. But if we agree that it is a good idea I can respin the patch and add it to the Makefile, too.

Make sense to me. I'd vote for adding it as long as all targets can be compiled without any problems.

Quoted 9 lines
 lib/report.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/report.c +0 -0
index b002d21..c0a701f 100644

lib/report.c void report_prefix_pop(void) · line 86

Quoted 9 lines
lib/report.c +3 -3
@@ -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");

Hmm, think I liked the old indentation better. (":" directly below the matching "?")

Quoted 4 lines
lib/report.c +0 -0
 	spin_lock(&lock);
 
 
Signature · 3 lines
Thanks,

David
#2 lore raw
Quoted 27 lines · David Hildenbrand
Quoted 9 lines · Thomas Huth

This way, the code can be compiled with "-Wwrite-strings", too.

---
Not sure whether we want to enable "-Wwrite-strings" globally (since strings in kvm-unit-test are theoretically writable if the test is running without MMU), so I only fixed the code here, without adding it to the Makefile. But if we agree that it is a good idea I can respin the patch and add it to the Makefile, too.

Make sense to me. I'd vote for adding it as long as all targets can be compiled without any problems.

Quoted 13 lines
 lib/report.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/report.c +0 -1
index b002d21..c0a701f 100644
@@ -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"
Quoted 8 lines

lib/report.c void report_prefix_pop(void) · line 86

Quoted 5 lines
lib/report.c +3 -2
-	                    : xfail ? (pass ? "XPASS" : "XFAIL")
-	                            : (pass ? "PASS"  : "FAIL");
+	const char *prefix = skip ? "SKIP"
+				  : xfail ? (pass ? "XPASS" : "XFAIL")
+				  : (pass ? "PASS"  : "FAIL");

Hmm, think I liked the old indentation better. (":" directly below the matching "?")

Oh, right, thanks! That apparently happens when sending patches too early in the morning ;-)
I'll wait for some more comments about whether to include "-Wwrite-strings" or not, then I'll respin this patch.

Thomas

#3 lore raw
Quoted 37 lines · Thomas Huth
Quoted 27 lines · David Hildenbrand
Quoted 9 lines · Thomas Huth

This way, the code can be compiled with "-Wwrite-strings", too.

---
Not sure whether we want to enable "-Wwrite-strings" globally (since strings in kvm-unit-test are theoretically writable if the test is running without MMU), so I only fixed the code here, without adding it to the Makefile. But if we agree that it is a good idea I can respin the patch and add it to the Makefile, too.

Make sense to me. I'd vote for adding it as long as all targets can be compiled without any problems.

Quoted 13 lines
 lib/report.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/report.c +0 -1
index b002d21..c0a701f 100644
@@ -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"
Quoted 8 lines

lib/report.c void report_prefix_pop(void) · line 86

Quoted 5 lines
lib/report.c +3 -2
-	                    : xfail ? (pass ? "XPASS" : "XFAIL")
-	                            : (pass ? "PASS"  : "FAIL");
+	const char *prefix = skip ? "SKIP"
+				  : xfail ? (pass ? "XPASS" : "XFAIL")
+				  : (pass ? "PASS"  : "FAIL");

Hmm, think I liked the old indentation better. (":" directly below the matching "?")

Quoted 4 lines

Oh, right, thanks! That apparently happens when sending patches too early in the morning ;-)
I'll wait for some more comments about whether to include "-Wwrite-strings" or not, then I'll respin this patch.

I vote turn it on globally, and then if a unit test is introduced where it needs to be off, then that's the beauty of having it fine grained, that unit test can modify its make target accordingly to remove it.

Thanks,
drew

maintainer
#4 lore raw
In reply to Thomas Huth
Quoted 4 lines · Thomas Huth

Oh, right, thanks! That apparently happens when sending patches too early in the morning ;-)
I'll wait for some more comments about whether to include "-Wwrite-strings" or not, then I'll respin this patch.

Yes, please do.

Paolo