All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Laurent Vivier" <laurent@vivier.eu>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 2/2] target/m68k: Remove sprintf() calls
Date: Thu, 11 Apr 2024 23:39:33 +0200	[thread overview]
Message-ID: <20240411213933.36548-3-philmd@linaro.org> (raw)
In-Reply-To: <20240411213933.36548-1-philmd@linaro.org>

sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
resulting in painful developper experience.

Since they are very few register names, use const arrays instead
of trying to be clever generating the names. This silences:

  [2/8] Compiling C object libqemu-m68k-softmmu.fa.p/target_m68k_translate.c.o
  target/m68k/translate.c:92:9: warning: 'sprintf' is deprecated:
    This function is provided for compatibility reasons only.
    Due to security concerns inherent in the design of sprintf(3),
    it is highly recommended that you use snprintf(3) instead.
    [-Wdeprecated-declarations]
        sprintf(p, "D%d", i);
        ^
        sprintf(p, "A%d", i);
        ^
        sprintf(p, "ACC%d", i);
        ^

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/m68k/translate.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/target/m68k/translate.c b/target/m68k/translate.c
index 8a194f2f21..d0561c18fe 100644
--- a/target/m68k/translate.c
+++ b/target/m68k/translate.c
@@ -48,7 +48,6 @@
 static TCGv_i32 cpu_halted;
 static TCGv_i32 cpu_exception_index;
 
-static char cpu_reg_names[2 * 8 * 3 + 5 * 4];
 static TCGv cpu_dregs[8];
 static TCGv cpu_aregs[8];
 static TCGv_i64 cpu_macc[4];
@@ -66,7 +65,15 @@ static TCGv store_dummy;
 
 void m68k_tcg_init(void)
 {
-    char *p;
+    static const char dreg_names[8][3] = {
+        "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7"
+    };
+    static const char areg_names[8][3] = {
+        "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7"
+    };
+    static const char macc_names[4][5] = {
+        "ACC0", "ACC1", "ACC2", "ACC3"
+    };
     int i;
 
 #define DEFO32(name, offset) \
@@ -87,22 +94,18 @@ void m68k_tcg_init(void)
                                                  offsetof(CPUState, exception_index),
                                                  "EXCEPTION");
 
-    p = cpu_reg_names;
     for (i = 0; i < 8; i++) {
-        sprintf(p, "D%d", i);
         cpu_dregs[i] = tcg_global_mem_new(tcg_env,
-                                          offsetof(CPUM68KState, dregs[i]), p);
-        p += 3;
-        sprintf(p, "A%d", i);
+                                          offsetof(CPUM68KState, dregs[i]),
+                                          dreg_names[i]);
         cpu_aregs[i] = tcg_global_mem_new(tcg_env,
-                                          offsetof(CPUM68KState, aregs[i]), p);
-        p += 3;
+                                          offsetof(CPUM68KState, aregs[i]),
+                                          areg_names[i]);
     }
     for (i = 0; i < 4; i++) {
-        sprintf(p, "ACC%d", i);
         cpu_macc[i] = tcg_global_mem_new_i64(tcg_env,
-                                         offsetof(CPUM68KState, macc[i]), p);
-        p += 5;
+                                         offsetof(CPUM68KState, macc[i]),
+                                         macc_names[i]);
     }
 
     NULL_QREG = tcg_global_mem_new(tcg_env, -4, "NULL");
-- 
2.41.0



  parent reply	other threads:[~2024-04-11 21:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11 21:39 [PATCH 0/2] m68k: Remove sprintf() calls due to macOS deprecation Philippe Mathieu-Daudé
2024-04-11 21:39 ` [PATCH 1/2] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
2024-04-11 21:57   ` Richard Henderson
2024-04-11 21:39 ` Philippe Mathieu-Daudé [this message]
2024-04-11 21:58   ` [PATCH 2/2] target/m68k: Remove sprintf() calls Richard Henderson

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=20240411213933.36548-3-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.