[PATCH 1/4] smatch: use const pointers for strchr() and strstr() results

Arka Mondal <[email protected]>
Newsgroups org.kernel.vger.smatch
Message-ID <[email protected]>
glibc-2.43 returns a const pointer from strchr() and strstr() when the
string is const.  Nothing writes through these so declare them const.
In get_arg_from_ret_string() it needed a second variable.

Signed-off-by: Arka Mondal <[email protected]>
---
 check_unwind.c          |  2 +-
 smatch_db.c             |  2 +-
 smatch_function_hooks.c | 17 +++++++++--------
 smatch_kernel.c         |  2 +-
 smatch_param_key.c      |  2 +-
 5 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/check_unwind.c b/check_unwind.c
index dcede91f..ef6f8897 100644
--- a/check_unwind.c
+++ b/check_unwind.c
@@ -170,7 +170,7 @@ static void mark_partial_matches_as_undefined(const char *key)
 {
 	struct sm_state *sm;
 	int start_pos, state_len, key_len;
-	char *p;
+	const char *p;
 
 	while ((p = strchr(key, '-'))) {
 		if (p[1] != '>')
diff --git a/smatch_db.c b/smatch_db.c
index 2d6989c7..b3ba25be 100644
--- a/smatch_db.c
+++ b/smatch_db.c
@@ -1854,7 +1854,7 @@ static bool handle_forced_split(const char *return_ranges, struct expression *ex
 	struct range_list *rl;
 	static bool recurse;
 	char buf[64];
-	char *math;
+	const char *math;
 	sval_t sval;
 	bool undo;
 	int i;
diff --git a/smatch_function_hooks.c b/smatch_function_hooks.c
index 9782015f..7299eac4 100644
--- a/smatch_function_hooks.c
+++ b/smatch_function_hooks.c
@@ -855,20 +855,21 @@ static struct expression *get_arg_from_ret_string(struct expression *call, const
 {
 	struct expression *arg, *tmp;
 	char *str;
+	const char *p;
 	char buf[64];
 	int param;
 
-	str = strchr(ret_string, '[');
-	if (!str)
+	p = strchr(ret_string, '[');
+	if (!p)
 		return NULL;
-	str++;
-	if (strncmp(str, "== ", 3) == 0)
-		str += 3;
+	p++;
+	if (strncmp(p, "== ", 3) == 0)
+		p += 3;
 
-	if (str[0] != '$' || !isdigit(str[1]))
+	if (p[0] != '$' || !isdigit(p[1]))
 		return NULL;
 
-	param = atoi(str + 1);
+	param = atoi(p + 1);
 	arg = get_argument_from_call_expr(call->args, param);
 	if (!arg)
 		return NULL;
@@ -881,7 +882,7 @@ static struct expression *get_arg_from_ret_string(struct expression *call, const
 		arg = tmp;
 	}
 
-	snprintf(buf, sizeof(buf), "$%s", str + 2);
+	snprintf(buf, sizeof(buf), "$%s", p + 2);
 	str = strchr(buf, ']');
 	if (!str)
 		return NULL;
diff --git a/smatch_kernel.c b/smatch_kernel.c
index c78ef440..b5d169a1 100644
--- a/smatch_kernel.c
+++ b/smatch_kernel.c
@@ -573,7 +573,7 @@ static void match_kernel_param(struct symbol *sym)
 
 bool is_ignored_kernel_data(const char *name)
 {
-	char *p;
+	const char *p;
 
 	if (option_project != PROJ_KERNEL)
 		return false;
diff --git a/smatch_param_key.c b/smatch_param_key.c
index bafd499b..d1356e6e 100644
--- a/smatch_param_key.c
+++ b/smatch_param_key.c
@@ -273,7 +273,7 @@ struct expression *map_netdev_priv_to_simpler_expr_key(struct expression *expr,
 	struct expression *priv;
 	char buf[64];
 	int diff;
-	char *p;
+	const char *p;
 
 	priv = get_netdev_priv(expr);
 	if (!priv)
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.