For pre-ANSI-C compatibility reasons, string literals have a mutable type, but
it is undefined behaviour to mutate them.
Swap char *'s to const char *'s for variables which hold string literals.
This fixes several violations of MISRA Rule 7.4:
A string literal shall not be assigned to an object unless the object's type
is "pointer to const-qualified char".
No functional change.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: George Dunlap <George.Dunlap@eu.citrix.com>
CC: Jan Beulich <JBeulich@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Wei Liu <wl@xen.org>
CC: Julien Grall <julien@xen.org>
CC: Roberto Bagnara <roberto.bagnara@bugseng.com>
CC: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
xen/common/gunzip.c | 2 +-
xen/common/ioreq.c | 3 ++-
xen/common/libelf/libelf-dominfo.c | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/xen/common/gunzip.c b/xen/common/gunzip.c
index b810499be2b6..2c6eae167d54 100644
--- a/xen/common/gunzip.c
+++ b/xen/common/gunzip.c
@@ -52,7 +52,7 @@ typedef unsigned long ulg;
static long __initdata bytes_out;
static void flush_window(void);
-static __init void error(char *x)
+static __init void error(const char *x)
{
panic("%s\n", x);
}
diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c
index ecb8f545e1c4..7cb717f7a2a4 100644
--- a/xen/common/ioreq.c
+++ b/xen/common/ioreq.c
@@ -501,7 +501,8 @@ static int ioreq_server_alloc_rangesets(struct ioreq_server *s,
for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
{
- char *name, *type;
+ const char *type;
+ char *name;
switch ( i )
{
diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c
index fcaee2f7bcff..a13a5e4db603 100644
--- a/xen/common/libelf/libelf-dominfo.c
+++ b/xen/common/libelf/libelf-dominfo.c
@@ -100,7 +100,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
{
/* *INDENT-OFF* */
static const struct {
- char *name;
+ const char *name;
bool str;
} note_desc[] = {
[XEN_ELFNOTE_ENTRY] = { "ENTRY", 0},
--
2.30.2