[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen/common: Use const char * for string literals


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 14 Jul 2023 11:59:02 +0100
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>, "Nicola Vetrini" <nicola.vetrini@xxxxxxxxxxx>
  • Delivery-date: Fri, 14 Jul 2023 10:59:35 +0000
  • Ironport-data: A9a23:swkbS6DYawrdeRVW/8rjw5YqxClBgxIJ4kV8jS/XYbTApD9x3jIBm zFOWmuPbP6PNGTyKNEkPt/g9R8BvsPWzoJnQQY4rX1jcSlH+JHPbTi7wuUcHAvJd5GeExg3h yk6QoOdRCzhZiaE/n9BCpC48T8nk/nOHuGmYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbCRMsspvlDs15K6p4GxB4gRnDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoKvn3bEmp1T4E8K0YIwpsAoPWhh6 /wjGTVXZy2/ldCKmaiaRbw57igjBJGD0II3v3hhyXfSDOo8QICFSKLPjTNa9G5u3IYUR6+YP pdHL2M1N3wsYDUWUrsTILs4kP2lmT/UdDpApUjOjaE2/3LS3Ep6172F3N/9I4XXGJwKwxfCz o7A123AQU4ILICc8GCq7nC0o+/lkD7XRatHQdVU8dY12QbOlwT/EiY+RVa95PW0lEO6c9ZeM FAPvDojq7Ao806mRcW7WAe3yFamlBMBX9tbE8Uh9RqAjKHT5m6xHXMYRzRMbNgnss4eRjEw0 FKN2dTzClRHr7m9WX+bsLCOoluaOzURLGIETT8JS00C+daLiJs0hB/VUtElGqe6iNTvEBn63 j+RoS4xwb4UiKYj0aSw+lTOxSyhuoLISA8d7BjYRW+j4UVyY4vNWmCzwQGFt7Aadt/fFwTf+ iFewKBy8dziE7nRsnOxScoTHIqY4qyMDQHOs2I2BbguomHFF2GYQWxA3N1vDB43YpdfI2e5O BC7VRB5v8EKYibzBUNjS8foUplxk/C9fTjwfqqMBueidKSdY+NuEMtGQUeLl17gn0E3+U3UE cfKKJ38ZZr25EkO8dZXewv++eVxrszG7TmPLa0XNjz+uVZkWFabSK0eLHyFZf0j4aWPrW39q ogPZpHVkE0ADLOjMkE7FLL/y3hQdhDX4riv+6RqmhOreFI6SAnN9deMqV/eR2CVt/sMzbqZl p1MckRZ1ED+lRX6xfaiMxhehEfUdc8n9xoTZHV8VWtELlB/Oe5DGo9DLcpoFVTmncQ/pcNJo w4tJ5/YXKkQFmyeolzwr/DV9eRfSfhivirWVwLNXdT1V8cIq9DhkjM8QjbSyQ==
  • Ironport-hdrordr: A9a23:Q1L68K4gvkLjQbwxBgPXwAzXdLJyesId70hD6qkQc3Fom62j5q WTdZEgvyMc5wx/ZJhNo7690cq7MBHhHPxOgbX5VI3KNGXbUQOTR72KhrGSoAEIdReeygZcv5 0QCZSXCrfLfCVHZRCR2njFLz4iquP3j5xBnY3lvhNQpZkBUdAZ0+9+YDzrdXFedU19KrcSMo GT3cZDryrIQwVtUizqbkN1OdQqvrfw5evbXSI=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxxxxx>
---
CC: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Julien Grall <julien@xxxxxxx>
CC: Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>
CC: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
---
 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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.