xen/common: Use const char * for string literals
PATCH 1/1 xen/common: Use const char * for string literals
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.
---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
--- xen/common/gunzip.c | 2 +- xen/common/ioreq.c | 3 ++- xen/common/libelf/libelf-dominfo.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-)
xen/common/gunzip.c +1 -1
@@ -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); }
xen/common/ioreq.c +2 -1
@@ -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 ) {
xen/common/libelf/libelf-dominfo.c +1 -1
@@ -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 },
Signature · 1 line
2.30.2
Hi Andrew,
Quoted 5 lines · Andrew Cooper
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.
Quoted 8 lines
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 <[email protected]>
Cheers,
Signature · 1 line
Julien Grall