xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien@xen.org>
To: xen-devel@lists.xenproject.org
Cc: julien@xen.org, Julien Grall <jgrall@amazon.com>,
	Ian Jackson <iwj@xenproject.org>, Wei Liu <wl@xen.org>
Subject: [PATCH 06/14] tools/libs: stat: Use const whenever we point to literal strings
Date: Mon,  5 Apr 2021 16:57:05 +0100	[thread overview]
Message-ID: <20210405155713.29754-7-julien@xen.org> (raw)
In-Reply-To: <20210405155713.29754-1-julien@xen.org>

From: Julien Grall <jgrall@amazon.com>

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>
---
 tools/libs/stat/xenstat_linux.c |  4 ++--
 tools/libs/stat/xenstat_qmp.c   | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index c00b26d4d898..875a0617ade8 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -66,7 +66,7 @@ static const char PROCNETDEV_HEADER[] =
 
 /* We need to get the name of the bridge interface for use with bonding interfaces */
 /* Use excludeName parameter to avoid adding bridges we don't care about, eg. virbr0 */
-static void getBridge(char *excludeName, char *result, size_t resultLen)
+static void getBridge(const char *excludeName, char *result, size_t resultLen)
 {
 	struct dirent *de;
 	DIR *d;
@@ -113,7 +113,7 @@ static int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes,
 	int num = 19;
 
 	/* Regular exception to parse all the information from /proc/net/dev line */
-	char *regex = "([^:]*):([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)"
+	const char *regex = "([^:]*):([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)"
 			"[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*"
 			"([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)";
 
diff --git a/tools/libs/stat/xenstat_qmp.c b/tools/libs/stat/xenstat_qmp.c
index 0c5748ba68b3..2205a041313b 100644
--- a/tools/libs/stat/xenstat_qmp.c
+++ b/tools/libs/stat/xenstat_qmp.c
@@ -38,7 +38,7 @@
 
 #include <yajl/yajl_tree.h>
 
-static unsigned char *qmp_query(int, char *);
+static unsigned char *qmp_query(int, const char *);
 
 enum query_blockstats {
     QMP_STATS_RETURN  = 0,
@@ -80,7 +80,7 @@ enum query_block {
 static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd)
 {
 	char *tmp, *file = NULL;
-	char *query_block_cmd = "{ \"execute\": \"query-block\" }";
+	const char *query_block_cmd = "{ \"execute\": \"query-block\" }";
 	static const char *const qblock[] = {
 		[ QMP_BLOCK_RETURN  ] = "return",
 		[ QMP_BLOCK_DEVICE  ] = "device",
@@ -264,7 +264,7 @@ done:
 }
 
 /* Write a command via the QMP. Returns number of bytes written */
-static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
+static size_t qmp_write(int qfd, const char *cmd, size_t cmd_len)
 {
 	size_t pos = 0;
 	ssize_t res;
@@ -317,7 +317,7 @@ static int qmp_read(int qfd, unsigned char **qstats)
 }
 
 /* With the given cmd, query QMP for requested data. Returns allocated buffer containing data or NULL */
-static unsigned char *qmp_query(int qfd, char *cmd)
+static unsigned char *qmp_query(int qfd, const char *cmd)
 {
 	unsigned char *qstats = NULL;
 	int n;
@@ -385,8 +385,8 @@ static int qmp_connect(char *path)
 */
 static void read_attributes_qdisk_dom(xenstat_node *node, domid_t domain)
 {
-	char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }";
-	char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" }";
+	const char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }";
+	const char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" }";
 	unsigned char *qmp_stats, *val;
 	char path[80];
 	int qfd;
-- 
2.17.1



  parent reply	other threads:[~2021-04-05 15:57 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-05 15:56 [PATCH 00/14] Use const whether we point to literal strings (take 1) Julien Grall
2021-04-05 15:57 ` [PATCH 01/14] xen: Constify the second parameter of rangeset_new() Julien Grall
2021-04-06  7:57   ` Jan Beulich
2021-04-06 18:03     ` Julien Grall
2021-04-05 15:57 ` [PATCH 02/14] xen/sched: Constify name and opt_name in struct scheduler Julien Grall
2021-04-06  8:07   ` Jan Beulich
2021-04-06 18:24     ` Julien Grall
2021-04-07  8:22       ` Jan Beulich
2021-04-07  9:06         ` Julien Grall
2021-04-06 14:19   ` George Dunlap
2021-04-05 15:57 ` [PATCH 03/14] xen/x86: shadow: The return type of sh_audit_flags() should be const Julien Grall
2021-04-06  7:24   ` Roger Pau Monné
2021-04-06 18:26     ` Julien Grall
2021-04-06 14:00   ` Tim Deegan
2021-04-05 15:57 ` [PATCH 04/14] xen/char: console: Use const whenever we point to literal strings Julien Grall
2021-04-06  8:10   ` Jan Beulich
2021-04-06 18:27     ` Julien Grall
2021-04-05 15:57 ` [PATCH 05/14] tools/libs: guest: " Julien Grall
2021-05-11 14:58   ` Anthony PERARD
2021-05-18 13:33     ` Julien Grall
2021-04-05 15:57 ` Julien Grall [this message]
2021-05-11 15:03   ` [PATCH 06/14] tools/libs: stat: " Anthony PERARD
2021-04-05 15:57 ` [PATCH 07/14] tools/xl: " Julien Grall
2021-04-27 16:04   ` Anthony PERARD
2021-04-27 16:28     ` Julien Grall
2021-04-27 17:03       ` Anthony PERARD
2021-04-05 15:57 ` [PATCH 08/14] tools/firmware: hvmloader: Use const in __bug() and __assert_failed() Julien Grall
2021-04-06  7:29   ` Roger Pau Monné
2021-04-06 19:02     ` Julien Grall
2021-04-05 15:57 ` [PATCH 09/14] tools/console: Use const whenever we point to literal strings Julien Grall
2021-05-11 15:18   ` Anthony PERARD
2021-05-18 13:48     ` Julien Grall
2021-04-05 15:57 ` [PATCH 10/14] tools/kdd: " Julien Grall
2021-04-06 14:03   ` Tim Deegan
2021-04-05 15:57 ` [PATCH 11/14] tools/misc: " Julien Grall
2021-05-11 15:37   ` Anthony PERARD
2021-04-05 15:57 ` [PATCH 12/14] tools/top: The string parameter in set_prompt() and set_delay() should be const Julien Grall
2021-05-11 15:46   ` Anthony PERARD
2021-04-05 15:57 ` [PATCH 13/14] tools/xenmon: xenbaked: Mark const the field text in stat_map_t Julien Grall
2021-05-11 16:08   ` Anthony PERARD
2021-04-05 15:57 ` [PATCH 14/14] tools/xentrace: Use const whenever we point to literal strings Julien Grall
2021-04-06 14:15   ` George Dunlap
2021-04-05 17:01 ` [PATCH 00/14] Use const whether we point to literal strings (take 1) Elliott Mitchell
2021-04-06 17:55   ` Julien Grall
2021-04-06  7:50 ` Jan Beulich
2021-04-06 19:08 ` Julien Grall
2021-05-10 17:49 ` PING " Julien Grall
2021-05-17 18:41   ` Wei Liu
2021-05-18 14:02     ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210405155713.29754-7-julien@xen.org \
    --to=julien@xen.org \
    --cc=iwj@xenproject.org \
    --cc=jgrall@amazon.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).