Linux bluetooth development
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Subject: [BlueZ 2/3] mesh: Fix str{r,}chr usage
Date: Mon, 11 May 2026 13:35:06 +0200	[thread overview]
Message-ID: <20260511113511.1217887-2-hadess@hadess.net> (raw)
In-Reply-To: <20260511113511.1217887-1-hadess@hadess.net>

Fix the code manipulating "const char *" return values from
json_object_to_json_string_ext() to modify it for printing, we're
not allowed to do that.

tools/mesh/mesh-db.c: In function ‘mesh_db_finish_export’:
tools/mesh/mesh-db.c:2598:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
 2598 |         pos = strrchr(hdr, '}');
      |             ^
tools/mesh/mesh-db.c:2604:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
 2604 |         pos = strrchr(hdr, '"');
      |             ^
tools/mesh/mesh-db.c:2613:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
 2613 |         pos = strchr(str, '{');
      |             ^
---
 tools/mesh/mesh-db.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/tools/mesh/mesh-db.c b/tools/mesh/mesh-db.c
index fb9c436d1d06..7bb8ab53ecbb 100644
--- a/tools/mesh/mesh-db.c
+++ b/tools/mesh/mesh-db.c
@@ -2547,7 +2547,9 @@ void *mesh_db_prepare_export(void)
 bool mesh_db_finish_export(bool is_error, void *expt_cfg, const char *fname)
 {
 	FILE *outfile = NULL;
-	const char *str, *hdr;
+	const char *str_s, *hdr_s;
+	char *str = NULL;
+	char *hdr = NULL;
 	json_object *jhdr = NULL;
 	bool result = false;
 	char *pos;
@@ -2581,15 +2583,18 @@ bool mesh_db_finish_export(bool is_error, void *expt_cfg, const char *fname)
 	if (!add_string(jhdr, "version", schema_version))
 		goto done;
 
-	hdr = json_object_to_json_string_ext(jhdr, JSON_C_TO_STRING_PRETTY |
+	hdr_s = json_object_to_json_string_ext(jhdr, JSON_C_TO_STRING_PRETTY |
 						JSON_C_TO_STRING_NOSLASHESCAPE);
 
-	str = json_object_to_json_string_ext(expt_cfg, JSON_C_TO_STRING_PRETTY |
+	str_s = json_object_to_json_string_ext(expt_cfg, JSON_C_TO_STRING_PRETTY |
 						JSON_C_TO_STRING_NOSLASHESCAPE);
 
-	if (!hdr || !str)
+	if (!hdr_s || !str_s)
 		goto done;
 
+	hdr = strdup(hdr_s);
+	str = strdup(str_s);
+
 	/*
 	 * Write two strings to the output while stripping closing "}" from the
 	 * header string and opening "{" from the config object.
@@ -2624,6 +2629,10 @@ bool mesh_db_finish_export(bool is_error, void *expt_cfg, const char *fname)
 	result = true;
 
 done:
+	if (hdr != NULL)
+		free(hdr);
+	if (str != NULL)
+		free(str);
 	if (outfile)
 		fclose(outfile);
 
-- 
2.54.0


  reply	other threads:[~2026-05-11 11:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 11:35 [BlueZ 1/3] mesh: Remove unused but set variable Bastien Nocera
2026-05-11 11:35 ` Bastien Nocera [this message]
2026-05-11 11:35 ` [BlueZ 3/3] mesh: Fix const qualifier dropping when using strchr() Bastien Nocera
2026-05-11 14:27 ` [BlueZ,1/3] mesh: Remove unused but set variable bluez.test.bot
2026-05-12 19:20 ` [BlueZ 1/3] " patchwork-bot+bluetooth

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=20260511113511.1217887-2-hadess@hadess.net \
    --to=hadess@hadess.net \
    --cc=linux-bluetooth@vger.kernel.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