diff mbox series

[2/2] target/m68k: Remove sprintf() calls

Message ID 20240411213933.36548-3-philmd@linaro.org
State New
Headers show
Series m68k: Remove sprintf() calls due to macOS deprecation | expand

Commit Message

Philippe Mathieu-Daudé April 11, 2024, 9:39 p.m. UTC
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(-)

Comments

Richard Henderson April 11, 2024, 9:58 p.m. UTC | #1
On 4/11/24 14:39, Philippe Mathieu-Daudé wrote:
> 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(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

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");