tools/xl: Use const whenever we point to literal strings
authorJulien Grall <jgrall@amazon.com>
Wed, 5 May 2021 17:43:06 +0000 (18:43 +0100)
committerJulien Grall <jgrall@amazon.com>
Wed, 5 May 2021 17:43:06 +0000 (18:43 +0100)
literal strings are not meant to be modified. So we should use const
char * rather than char * when we want to store a pointer to them.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
tools/xl/xl.h
tools/xl/xl_console.c
tools/xl/xl_utils.c
tools/xl/xl_utils.h

index e5a106dfbc8239c199d645aaf95bf7b06c07c994..7e23f301925d8e6f379d364f2a2a9e1408620cde 100644 (file)
 #include <xentoollog.h>
 
 struct cmd_spec {
-    char *cmd_name;
+    const char *cmd_name;
     int (*cmd_impl)(int argc, char **argv);
     int can_dryrun;
     int modifies;
-    char *cmd_desc;
-    char *cmd_usage;
-    char *cmd_option;
+    const char *cmd_desc;
+    const char *cmd_usage;
+    const char *cmd_option;
 };
 
 struct domain_create {
index 4e65d738673387066184e5894a4dbb1406de71f8..b27f9e013697321fe8bbeaaa27d0a2de27454e4e 100644 (file)
@@ -27,7 +27,7 @@ int main_console(int argc, char **argv)
     uint32_t domid;
     int opt = 0, num = 0;
     libxl_console_type type = 0;
-    char *console_names = "pv, serial, vuart";
+    const char *console_names = "pv, serial, vuart";
 
     SWITCH_FOREACH_OPT(opt, "n:t:", NULL, "console", 1) {
     case 't':
index 4503ac7ea03c51ceb6064283b6b4ba55f3b76e0b..17489d182954f04da5ff2a5ecad43c44a8abab38 100644 (file)
@@ -27,7 +27,7 @@
 #include "xl.h"
 #include "xl_utils.h"
 
-void dolog(const char *file, int line, const char *func, char *fmt, ...)
+void dolog(const char *file, int line, const char *func, const char *fmt, ...)
 {
     va_list ap;
     char *s = NULL;
@@ -248,7 +248,7 @@ void print_bitmap(uint8_t *map, int maplen, FILE *stream)
     }
 }
 
-int do_daemonize(char *name, const char *pidfile)
+int do_daemonize(const char *name, const char *pidfile)
 {
     char *fullname;
     pid_t child1;
index d98b419f10751a610f863aec97c5e0e26147845b..0c337ede954b45b6aeb439847f6189d2596423c2 100644 (file)
@@ -123,7 +123,7 @@ int def_getopt(int argc, char * const argv[],
                const struct option *longopts,
                const char* helpstr, int reqargs);
 
-void dolog(const char *file, int line, const char *func, char *fmt, ...)
+void dolog(const char *file, int line, const char *func, const char *fmt, ...)
        __attribute__((format(printf,4,5)));
 
 void xvasprintf(char **strp, const char *fmt, va_list ap)
@@ -143,7 +143,7 @@ uint32_t find_domain(const char *p) __attribute__((warn_unused_result));
 
 void print_bitmap(uint8_t *map, int maplen, FILE *stream);
 
-int do_daemonize(char *name, const char *pidfile);
+int do_daemonize(const char *name, const char *pidfile);
 #endif /* XL_UTILS_H */
 
 /*