qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation
@ 2024-04-11 10:43 Philippe Mathieu-Daudé
  2024-04-11 10:43 ` [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
                   ` (8 more replies)
  0 siblings, 9 replies; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm,
	Philippe =?unknown-8bit?q?Mathieu-Daud=C3=A9?=

Continuation of:
https://lore.kernel.org/qemu-devel/20240411101550.99392-1-philmd@linaro.org/

*** BLURB HERE ***

Philippe Mathieu-Daudé (9):
  disas/m68k: Replace sprintf() by snprintf()
  disas/microblaze: Replace sprintf() by snprintf()
  disas/riscv: Replace sprintf() by snprintf()
  linux-user/flatload: Replace sprintf() by snprintf()
  hw/misc/imx: Replace sprintf() by snprintf()
  hw/net/rocker: Replace sprintf() by snprintf()
  hw/riscv/virt: Replace sprintf() by snprintf()
  target/arm: Replace sprintf() by snprintf()
  target/i386: Replace sprintf() by snprintf()

 disas/m68k.c           |  2 +-
 disas/microblaze.c     | 25 ++++++++++++++++---------
 disas/riscv.c          | 10 +++++-----
 hw/misc/imx25_ccm.c    |  2 +-
 hw/misc/imx31_ccm.c    |  2 +-
 hw/misc/imx6_ccm.c     |  4 ++--
 hw/misc/imx6_src.c     |  2 +-
 hw/misc/imx6ul_ccm.c   |  4 ++--
 hw/misc/imx7_src.c     |  2 +-
 hw/net/imx_fec.c       |  2 +-
 hw/net/rocker/rocker.c | 24 ++++++++++++------------
 hw/riscv/virt.c        |  5 +++--
 hw/ssi/imx_spi.c       |  2 +-
 linux-user/flatload.c  |  2 +-
 target/arm/cpu64.c     |  4 ++--
 target/i386/kvm/kvm.c  |  3 ++-
 16 files changed, 52 insertions(+), 43 deletions(-)

-- 
2.41.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 12:01   ` Peter Maydell
  2024-04-11 21:01   ` Richard Henderson
  2024-04-11 10:43 ` [PATCH 2/9] disas/microblaze: " Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  8 siblings, 2 replies; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé, Laurent Vivier

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 disas/m68k.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/disas/m68k.c b/disas/m68k.c
index 1f16e295ab..800b4145ac 100644
--- a/disas/m68k.c
+++ b/disas/m68k.c
@@ -1000,7 +1000,7 @@ print_indexed (int basereg,
 
   /* Generate the text for the index register.
      Where this will be output is not yet determined.  */
-  sprintf (buf, "%s:%c%s",
+  snprintf(buf, sizeof(buf), "%s:%c%s",
 	   reg_names[(word >> 12) & 0xf],
 	   (word & 0x800) ? 'l' : 'w',
 	   scales[(word >> 9) & 3]);
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 2/9] disas/microblaze: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
  2024-04-11 10:43 ` [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 12:56   ` Edgar E. Iglesias
  2024-04-11 21:03   ` Richard Henderson
  2024-04-11 10:43 ` [PATCH 3/9] disas/riscv: " Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  8 siblings, 2 replies; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé,
	Edgar E. Iglesias

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 disas/microblaze.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/disas/microblaze.c b/disas/microblaze.c
index 0b89b9c4fa..49a4c0fd40 100644
--- a/disas/microblaze.c
+++ b/disas/microblaze.c
@@ -600,7 +600,8 @@ static char *
 get_field (long instr, long mask, unsigned short low)
 {
   char tmpstr[25];
-  sprintf(tmpstr, "%s%d", register_prefix, (int)((instr & mask) >> low));
+  snprintf(tmpstr, sizeof(tmpstr), "%s%d", register_prefix,
+           (int)((instr & mask) >> low));
   return(strdup(tmpstr));
 }
 
@@ -608,7 +609,8 @@ static char *
 get_field_imm (long instr)
 {
   char tmpstr[25];
-  sprintf(tmpstr, "%d", (short)((instr & IMM_MASK) >> IMM_LOW));
+  snprintf(tmpstr, sizeof(tmpstr), "%d",
+           (short)((instr & IMM_MASK) >> IMM_LOW));
   return(strdup(tmpstr));
 }
 
@@ -616,7 +618,8 @@ static char *
 get_field_imm5 (long instr)
 {
   char tmpstr[25];
-  sprintf(tmpstr, "%d", (short)((instr & IMM5_MASK) >> IMM_LOW));
+  snprintf(tmpstr, sizeof(tmpstr), "%d",
+           (short)((instr & IMM5_MASK) >> IMM_LOW));
   return(strdup(tmpstr));
 }
 
@@ -624,7 +627,8 @@ static char *
 get_field_rfsl (long instr)
 {
   char tmpstr[25];
-  sprintf(tmpstr, "%s%d", fsl_register_prefix, (short)((instr & RFSL_MASK) >> IMM_LOW));
+  snprintf(tmpstr, sizeof(tmpstr), "%s%d", fsl_register_prefix,
+           (short)((instr & RFSL_MASK) >> IMM_LOW));
   return(strdup(tmpstr));
 }
 
@@ -632,7 +636,8 @@ static char *
 get_field_imm15 (long instr)
 {
   char tmpstr[25];
-  sprintf(tmpstr, "%d", (short)((instr & IMM15_MASK) >> IMM_LOW));
+  snprintf(tmpstr, sizeof(tmpstr), "%d",
+           (short)((instr & IMM15_MASK) >> IMM_LOW));
   return(strdup(tmpstr));
 }
 
@@ -641,7 +646,8 @@ static char *
 get_field_unsigned_imm (long instr)
 {
   char tmpstr[25];
-  sprintf(tmpstr, "%d", (int)((instr & IMM_MASK) >> IMM_LOW));
+  snprintf(tmpstr, sizeof(tmpstr), "%d",
+           (int)((instr & IMM_MASK) >> IMM_LOW));
   return(strdup(tmpstr));
 }
 #endif
@@ -653,7 +659,8 @@ get_field_unsigned_imm (long instr)
   {
   char tmpstr[25];
   
-  sprintf(tmpstr, "%s%s", register_prefix, (((instr & IMM_MASK) >> IMM_LOW) & REG_MSR_MASK) == 0 ? "pc" : "msr");
+  snprintf(tmpstr, sizeof(tmpstr), "%s%s", register_prefix,
+          (((instr & IMM_MASK) >> IMM_LOW) & REG_MSR_MASK) == 0 ? "pc" : "msr");
   
   return(strdup(tmpstr));
   }
@@ -709,7 +716,7 @@ get_field_special(long instr, const struct op_code_struct *op)
    default :
      {
        if ( ((((instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask) & 0xE000) == REG_PVR_MASK) {
-	  sprintf(tmpstr, "%s%u", pvr_register_prefix,
+          snprintf(tmpstr, sizeof(tmpstr), "%s%u", pvr_register_prefix,
                  (unsigned short)(((instr & IMM_MASK) >> IMM_LOW) ^
                                   op->immval_mask) ^ REG_PVR_MASK);
 	 return(strdup(tmpstr));
@@ -720,7 +727,7 @@ get_field_special(long instr, const struct op_code_struct *op)
      break;
    }
    
-   sprintf(tmpstr, "%s%s", register_prefix, spr);
+   snprintf(tmpstr, sizeof(tmpstr), "%s%s", register_prefix, spr);
    return(strdup(tmpstr));
 }
 
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 3/9] disas/riscv: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
  2024-04-11 10:43 ` [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
  2024-04-11 10:43 ` [PATCH 2/9] disas/microblaze: " Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 12:00   ` Peter Maydell
  2024-04-11 21:12   ` Richard Henderson
  2024-04-11 10:43 ` [PATCH 4/9] linux-user/flatload: " Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  8 siblings, 2 replies; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé, Palmer Dabbelt,
	Alistair Francis

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 disas/riscv.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/disas/riscv.c b/disas/riscv.c
index e236c8b5b7..fec09e9922 100644
--- a/disas/riscv.c
+++ b/disas/riscv.c
@@ -4966,7 +4966,7 @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)
         case 'v': {
             char nbuf[32] = {0};
             const int sew = 1 << (((dec->vzimm >> 3) & 0b111) + 3);
-            sprintf(nbuf, "%d", sew);
+            snprintf(nbuf, sizeof(nbuf), "%d", sew);
             const int lmul = dec->vzimm & 0b11;
             const int flmul = (dec->vzimm >> 2) & 1;
             const char *vta = (dec->vzimm >> 6) & 1 ? "ta" : "tu";
@@ -4977,18 +4977,18 @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)
             if (flmul) {
                 switch (lmul) {
                 case 3:
-                    sprintf(nbuf, "f2");
+                    snprintf(nbuf, sizeof(nbuf), "f2");
                     break;
                 case 2:
-                    sprintf(nbuf, "f4");
+                    snprintf(nbuf, sizeof(nbuf), "f4");
                     break;
                 case 1:
-                    sprintf(nbuf, "f8");
+                    snprintf(nbuf, sizeof(nbuf), "f8");
                 break;
                 }
                 append(buf, nbuf, buflen);
             } else {
-                sprintf(nbuf, "%d", 1 << lmul);
+                snprintf(nbuf, sizeof(nbuf), "%d", 1 << lmul);
                 append(buf, nbuf, buflen);
             }
             append(buf, ",", buflen);
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 4/9] linux-user/flatload: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2024-04-11 10:43 ` [PATCH 3/9] disas/riscv: " Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 11:40   ` Peter Maydell
  2024-04-11 10:43 ` [PATCH 5/9] hw/misc/imx: " Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé, Laurent Vivier

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 linux-user/flatload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/flatload.c b/linux-user/flatload.c
index 5b62aa0a2b..b0f04af4b6 100644
--- a/linux-user/flatload.c
+++ b/linux-user/flatload.c
@@ -692,7 +692,7 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
 	char buf[16];
 
 	/* Create the file name */
-	sprintf(buf, "/lib/lib%d.so", id);
+    snprintf(buf, sizeofbuf), "/lib/lib%d.so", id);
 
 	/* Open the file up */
 	bprm.filename = buf;
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 5/9] hw/misc/imx: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2024-04-11 10:43 ` [PATCH 4/9] linux-user/flatload: " Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 10:46   ` Peter Maydell
  2024-04-11 10:43 ` [PATCH 6/9] hw/net/rocker: " Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé, Peter Maydell,
	Jean-Christophe Dubois, Andrey Smirnov, Jason Wang,
	Alistair Francis

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/misc/imx25_ccm.c  | 2 +-
 hw/misc/imx31_ccm.c  | 2 +-
 hw/misc/imx6_ccm.c   | 4 ++--
 hw/misc/imx6_src.c   | 2 +-
 hw/misc/imx6ul_ccm.c | 4 ++--
 hw/misc/imx7_src.c   | 2 +-
 hw/net/imx_fec.c     | 2 +-
 hw/ssi/imx_spi.c     | 2 +-
 8 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/misc/imx25_ccm.c b/hw/misc/imx25_ccm.c
index d888966014..faa726a86a 100644
--- a/hw/misc/imx25_ccm.c
+++ b/hw/misc/imx25_ccm.c
@@ -91,7 +91,7 @@ static const char *imx25_ccm_reg_name(uint32_t reg)
     case IMX25_CCM_LPIMR1_REG:
         return "lpimr1";
     default:
-        sprintf(unknown, "[%u ?]", reg);
+        snprintf(unknown, sizeof(unknown), "[%u ?]", reg);
         return unknown;
     }
 }
diff --git a/hw/misc/imx31_ccm.c b/hw/misc/imx31_ccm.c
index a9059bb1f7..125d4fceeb 100644
--- a/hw/misc/imx31_ccm.c
+++ b/hw/misc/imx31_ccm.c
@@ -89,7 +89,7 @@ static const char *imx31_ccm_reg_name(uint32_t reg)
     case IMX31_CCM_PDR2_REG:
         return "PDR2";
     default:
-        sprintf(unknown, "[%u ?]", reg);
+        snprintf(unknown, sizeof(unknown), "[%u ?]", reg);
         return unknown;
     }
 }
diff --git a/hw/misc/imx6_ccm.c b/hw/misc/imx6_ccm.c
index 56489d8b57..b1def7f05b 100644
--- a/hw/misc/imx6_ccm.c
+++ b/hw/misc/imx6_ccm.c
@@ -85,7 +85,7 @@ static const char *imx6_ccm_reg_name(uint32_t reg)
     case CCM_CMEOR:
         return "CMEOR";
     default:
-        sprintf(unknown, "%u ?", reg);
+        snprintf(unknown, sizeof(unknown), "%u ?", reg);
         return unknown;
     }
 }
@@ -224,7 +224,7 @@ static const char *imx6_analog_reg_name(uint32_t reg)
     case USB_ANALOG_DIGPROG:
         return "USB_ANALOG_DIGPROG";
     default:
-        sprintf(unknown, "%u ?", reg);
+        snprintf(unknown, sizeof(unknown), "%u ?", reg);
         return unknown;
     }
 }
diff --git a/hw/misc/imx6_src.c b/hw/misc/imx6_src.c
index 0c6003559f..3766bdf561 100644
--- a/hw/misc/imx6_src.c
+++ b/hw/misc/imx6_src.c
@@ -68,7 +68,7 @@ static const char *imx6_src_reg_name(uint32_t reg)
     case SRC_GPR10:
         return "SRC_GPR10";
     default:
-        sprintf(unknown, "%u ?", reg);
+        snprintf(unknown, sizeof(unknown), "%u ?", reg);
         return unknown;
     }
 }
diff --git a/hw/misc/imx6ul_ccm.c b/hw/misc/imx6ul_ccm.c
index bbc0be9921..0ac49ea34b 100644
--- a/hw/misc/imx6ul_ccm.c
+++ b/hw/misc/imx6ul_ccm.c
@@ -143,7 +143,7 @@ static const char *imx6ul_ccm_reg_name(uint32_t reg)
     case CCM_CMEOR:
         return "CMEOR";
     default:
-        sprintf(unknown, "%u ?", reg);
+        snprintf(unknown, sizeof(unknown), "%u ?", reg);
         return unknown;
     }
 }
@@ -274,7 +274,7 @@ static const char *imx6ul_analog_reg_name(uint32_t reg)
     case USB_ANALOG_DIGPROG:
         return "USB_ANALOG_DIGPROG";
     default:
-        sprintf(unknown, "%u ?", reg);
+        snprintf(unknown, sizeof(unknown), "%u ?", reg);
         return unknown;
     }
 }
diff --git a/hw/misc/imx7_src.c b/hw/misc/imx7_src.c
index b3725ff6e7..d19f0450d4 100644
--- a/hw/misc/imx7_src.c
+++ b/hw/misc/imx7_src.c
@@ -75,7 +75,7 @@ static const char *imx7_src_reg_name(uint32_t reg)
     case SRC_GPR10:
         return "SRC_GPR10";
     default:
-        sprintf(unknown, "%u ?", reg);
+        snprintf(unknown, sizeof(unknown), "%u ?", reg);
         return unknown;
     }
 }
diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
index cee84af7ba..8c91d20d44 100644
--- a/hw/net/imx_fec.c
+++ b/hw/net/imx_fec.c
@@ -41,7 +41,7 @@
 static const char *imx_default_reg_name(IMXFECState *s, uint32_t index)
 {
     static char tmp[20];
-    sprintf(tmp, "index %d", index);
+    snprintf(tmp, sizeof(tmp), "index %d", index);
     return tmp;
 }
 
diff --git a/hw/ssi/imx_spi.c b/hw/ssi/imx_spi.c
index d8a7583ff3..12d897d306 100644
--- a/hw/ssi/imx_spi.c
+++ b/hw/ssi/imx_spi.c
@@ -53,7 +53,7 @@ static const char *imx_spi_reg_name(uint32_t reg)
     case ECSPI_MSGDATA:
         return  "ECSPI_MSGDATA";
     default:
-        sprintf(unknown, "%u ?", reg);
+        snprintf(unknown, sizeof(unknown), "%u ?", reg);
         return unknown;
     }
 }
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 6/9] hw/net/rocker: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2024-04-11 10:43 ` [PATCH 5/9] hw/misc/imx: " Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 11:30   ` Peter Maydell
  2024-04-11 10:43 ` [PATCH 7/9] hw/riscv/virt: " Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé, Jiri Pirko,
	Jason Wang

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/net/rocker/rocker.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
index 7ea8eb6ba5..03ac7a7ae9 100644
--- a/hw/net/rocker/rocker.c
+++ b/hw/net/rocker/rocker.c
@@ -915,40 +915,40 @@ static const char *rocker_reg_name(void *opaque, hwaddr addr)
 
         switch (index) {
         case 0:
-            sprintf(ring_name, "cmd");
+            snprintf(ring_name, sizeof(ring_name), "cmd");
             break;
         case 1:
-            sprintf(ring_name, "event");
+            snprintf(ring_name, sizeof(ring_name), "event");
             break;
         default:
-            sprintf(ring_name, "%s-%d", index % 2 ? "rx" : "tx",
-                    (index - 2) / 2);
+            snprintf(ring_name, sizeof(ring_name), "%s-%d",
+                     index % 2 ? "rx" : "tx", (index - 2) / 2);
         }
 
         switch (offset) {
         case ROCKER_DMA_DESC_ADDR_OFFSET:
-            sprintf(buf, "Ring[%s] ADDR", ring_name);
+            snprintf(buf, sizeofbuf), "Ring[%s] ADDR", ring_name);
             return buf;
         case ROCKER_DMA_DESC_ADDR_OFFSET+4:
-            sprintf(buf, "Ring[%s] ADDR+4", ring_name);
+            snprintf(buf, sizeofbuf), "Ring[%s] ADDR+4", ring_name);
             return buf;
         case ROCKER_DMA_DESC_SIZE_OFFSET:
-            sprintf(buf, "Ring[%s] SIZE", ring_name);
+            snprintf(buf, sizeofbuf), "Ring[%s] SIZE", ring_name);
             return buf;
         case ROCKER_DMA_DESC_HEAD_OFFSET:
-            sprintf(buf, "Ring[%s] HEAD", ring_name);
+            snprintf(buf, sizeofbuf), "Ring[%s] HEAD", ring_name);
             return buf;
         case ROCKER_DMA_DESC_TAIL_OFFSET:
-            sprintf(buf, "Ring[%s] TAIL", ring_name);
+            snprintf(buf, sizeofbuf), "Ring[%s] TAIL", ring_name);
             return buf;
         case ROCKER_DMA_DESC_CTRL_OFFSET:
-            sprintf(buf, "Ring[%s] CTRL", ring_name);
+            snprintf(buf, sizeofbuf), "Ring[%s] CTRL", ring_name);
             return buf;
         case ROCKER_DMA_DESC_CREDITS_OFFSET:
-            sprintf(buf, "Ring[%s] CREDITS", ring_name);
+            snprintf(buf, sizeofbuf), "Ring[%s] CREDITS", ring_name);
             return buf;
         default:
-            sprintf(buf, "Ring[%s] ???", ring_name);
+            snprintf(buf, sizeofbuf), "Ring[%s] ???", ring_name);
             return buf;
         }
     } else {
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 7/9] hw/riscv/virt: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2024-04-11 10:43 ` [PATCH 6/9] hw/net/rocker: " Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 21:29   ` Richard Henderson
  2024-04-11 10:43 ` [PATCH 8/9] target/arm: " Philippe Mathieu-Daudé
  2024-04-11 10:43 ` [PATCH 9/9] target/i386: " Philippe Mathieu-Daudé
  8 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé, Palmer Dabbelt,
	Alistair Francis, Bin Meng, Weiwei Li, Daniel Henrique Barboza,
	Liu Zhiwei

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/riscv/virt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index d171e74f7b..b3fede1207 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -1619,7 +1619,7 @@ static char *virt_get_aia_guests(Object *obj, Error **errp)
     RISCVVirtState *s = RISCV_VIRT_MACHINE(obj);
     char val[32];
 
-    sprintf(val, "%d", s->aia_guests);
+    snprintf(val, sizeof(val), "%d", s->aia_guests);
     return g_strdup(val);
 }
 
@@ -1785,7 +1785,8 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
     object_class_property_add_str(oc, "aia-guests",
                                   virt_get_aia_guests,
                                   virt_set_aia_guests);
-    sprintf(str, "Set number of guest MMIO pages for AIA IMSIC. Valid value "
+    snprintf(str, sizeof(str),
+                 "Set number of guest MMIO pages for AIA IMSIC. Valid value "
                  "should be between 0 and %d.", VIRT_IRQCHIP_MAX_GUESTS);
     object_class_property_set_description(oc, "aia-guests", str);
     object_class_property_add(oc, "acpi", "OnOffAuto",
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 8/9] target/arm: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2024-04-11 10:43 ` [PATCH 7/9] hw/riscv/virt: " Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 11:32   ` Peter Maydell
  2024-04-11 21:29   ` Richard Henderson
  2024-04-11 10:43 ` [PATCH 9/9] target/i386: " Philippe Mathieu-Daudé
  8 siblings, 2 replies; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé, Peter Maydell

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/cpu64.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 985b1efe16..f0f4fe6714 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -433,7 +433,7 @@ void aarch64_add_sve_properties(Object *obj)
 
     for (vq = 1; vq <= ARM_MAX_VQ; ++vq) {
         char name[8];
-        sprintf(name, "sve%d", vq * 128);
+        snprintf(name, sizeof(name), "sve%d", vq * 128);
         object_property_add(obj, name, "bool", cpu_arm_get_vq,
                             cpu_arm_set_vq, NULL, &cpu->sve_vq);
     }
@@ -458,7 +458,7 @@ void aarch64_add_sme_properties(Object *obj)
 
     for (vq = 1; vq <= ARM_MAX_VQ; vq <<= 1) {
         char name[8];
-        sprintf(name, "sme%d", vq * 128);
+        snprintf(name, sizeof(name), "sme%d", vq * 128);
         object_property_add(obj, name, "bool", cpu_arm_get_vq,
                             cpu_arm_set_vq, NULL, &cpu->sme_vq);
     }
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 9/9] target/i386: Replace sprintf() by snprintf()
  2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2024-04-11 10:43 ` [PATCH 8/9] target/arm: " Philippe Mathieu-Daudé
@ 2024-04-11 10:43 ` Philippe Mathieu-Daudé
  2024-04-11 11:59   ` Peter Maydell
  2024-04-11 21:46   ` Richard Henderson
  8 siblings, 2 replies; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 10:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, qemu-arm, Philippe Mathieu-Daudé, Paolo Bonzini,
	Marcelo Tosatti, kvm

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/kvm/kvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index e68cbe9293..a46d1426bf 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -5335,7 +5335,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
     case KVM_EXIT_NOTIFY:
         ctx_invalid = !!(run->notify.flags & KVM_NOTIFY_CONTEXT_INVALID);
         state = KVM_STATE(current_accel());
-        sprintf(str, "Encounter a notify exit with %svalid context in"
+        snprintf(str, sizeof(str),
+                     "Encounter a notify exit with %svalid context in"
                      " guest. There can be possible misbehaves in guest."
                      " Please have a look.", ctx_invalid ? "in" : "");
         if (ctx_invalid ||
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 5/9] hw/misc/imx: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 5/9] hw/misc/imx: " Philippe Mathieu-Daudé
@ 2024-04-11 10:46   ` Peter Maydell
  0 siblings, 0 replies; 25+ messages in thread
From: Peter Maydell @ 2024-04-11 10:46 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-riscv, qemu-arm, Jean-Christophe Dubois,
	Andrey Smirnov, Jason Wang, Alistair Francis

On Thu, 11 Apr 2024 at 11:44, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/misc/imx25_ccm.c  | 2 +-
>  hw/misc/imx31_ccm.c  | 2 +-
>  hw/misc/imx6_ccm.c   | 4 ++--
>  hw/misc/imx6_src.c   | 2 +-
>  hw/misc/imx6ul_ccm.c | 4 ++--
>  hw/misc/imx7_src.c   | 2 +-
>  hw/net/imx_fec.c     | 2 +-
>  hw/ssi/imx_spi.c     | 2 +-
>  8 files changed, 10 insertions(+), 10 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/9] hw/net/rocker: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 6/9] hw/net/rocker: " Philippe Mathieu-Daudé
@ 2024-04-11 11:30   ` Peter Maydell
  2024-04-11 21:22     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 25+ messages in thread
From: Peter Maydell @ 2024-04-11 11:30 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-riscv, qemu-arm, Jiri Pirko, Jason Wang

On Thu, 11 Apr 2024 at 11:47, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.

("developer")

> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/net/rocker/rocker.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)

>          switch (offset) {
>          case ROCKER_DMA_DESC_ADDR_OFFSET:
> -            sprintf(buf, "Ring[%s] ADDR", ring_name);
> +            snprintf(buf, sizeofbuf), "Ring[%s] ADDR", ring_name);

Something seems to have gone wrong here. Shouldn't this have
failed to compile ?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 8/9] target/arm: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 8/9] target/arm: " Philippe Mathieu-Daudé
@ 2024-04-11 11:32   ` Peter Maydell
  2024-04-11 21:29   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Peter Maydell @ 2024-04-11 11:32 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-devel, qemu-riscv, qemu-arm

On Thu, 11 Apr 2024 at 11:44, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/arm/cpu64.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
> index 985b1efe16..f0f4fe6714 100644
> --- a/target/arm/cpu64.c
> +++ b/target/arm/cpu64.c
> @@ -433,7 +433,7 @@ void aarch64_add_sve_properties(Object *obj)
>
>      for (vq = 1; vq <= ARM_MAX_VQ; ++vq) {
>          char name[8];
> -        sprintf(name, "sve%d", vq * 128);
> +        snprintf(name, sizeof(name), "sve%d", vq * 128);
>          object_property_add(obj, name, "bool", cpu_arm_get_vq,
>                              cpu_arm_set_vq, NULL, &cpu->sve_vq);
>      }
> @@ -458,7 +458,7 @@ void aarch64_add_sme_properties(Object *obj)
>
>      for (vq = 1; vq <= ARM_MAX_VQ; vq <<= 1) {
>          char name[8];
> -        sprintf(name, "sme%d", vq * 128);
> +        snprintf(name, sizeof(name), "sme%d", vq * 128);
>          object_property_add(obj, name, "bool", cpu_arm_get_vq,
>                              cpu_arm_set_vq, NULL, &cpu->sme_vq);
>      }

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 4/9] linux-user/flatload: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 4/9] linux-user/flatload: " Philippe Mathieu-Daudé
@ 2024-04-11 11:40   ` Peter Maydell
  0 siblings, 0 replies; 25+ messages in thread
From: Peter Maydell @ 2024-04-11 11:40 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-riscv, qemu-arm, Laurent Vivier

On Thu, 11 Apr 2024 at 11:44, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  linux-user/flatload.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/linux-user/flatload.c b/linux-user/flatload.c
> index 5b62aa0a2b..b0f04af4b6 100644
> --- a/linux-user/flatload.c
> +++ b/linux-user/flatload.c
> @@ -692,7 +692,7 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
>         char buf[16];
>
>         /* Create the file name */
> -       sprintf(buf, "/lib/lib%d.so", id);
> +    snprintf(buf, sizeofbuf), "/lib/lib%d.so", id);

Indentation has gone wrong, and another missing '('.

Looking at that, I notice that this function is actually
dead code -- it's in code that is only compiled and called
if CONFIG_BINFMT_SHARED_FLAT is defined, and if you try to
define that you will hit the "#error needs checking" in the
calc_reloc() function. It seems to have been like this since
the flatload support was added in 2006.

So I think we should remove the dead code -- I'll send a patch.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 9/9] target/i386: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 9/9] target/i386: " Philippe Mathieu-Daudé
@ 2024-04-11 11:59   ` Peter Maydell
  2024-04-11 21:46   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Peter Maydell @ 2024-04-11 11:59 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-riscv, qemu-arm, Paolo Bonzini, Marcelo Tosatti,
	kvm

On Thu, 11 Apr 2024 at 11:44, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/i386/kvm/kvm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index e68cbe9293..a46d1426bf 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -5335,7 +5335,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
>      case KVM_EXIT_NOTIFY:
>          ctx_invalid = !!(run->notify.flags & KVM_NOTIFY_CONTEXT_INVALID);
>          state = KVM_STATE(current_accel());
> -        sprintf(str, "Encounter a notify exit with %svalid context in"
> +        snprintf(str, sizeof(str),
> +                     "Encounter a notify exit with %svalid context in"
>                       " guest. There can be possible misbehaves in guest."
>                       " Please have a look.", ctx_invalid ? "in" : "");
>          if (ctx_invalid ||
> --

This is a case where I think we would be better off with
g_strdup_printf():

 * the buffer declaration is a long way away from its use
 * the string is long and it's not trivial to confirm that
   it will fit in the buffer
 * it's quite plausible somebody will come along later to
   clean up the wording of the error message and not notice
   they need to enlarge the buffer
 * it's only for printing a warning, so it's not going to
   be in a hot codepath

thanks
-- PMM


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 3/9] disas/riscv: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 3/9] disas/riscv: " Philippe Mathieu-Daudé
@ 2024-04-11 12:00   ` Peter Maydell
  2024-04-11 21:12   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Peter Maydell @ 2024-04-11 12:00 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-riscv, qemu-arm, Palmer Dabbelt,
	Alistair Francis

On Thu, 11 Apr 2024 at 11:44, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
@ 2024-04-11 12:01   ` Peter Maydell
  2024-04-11 21:01   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Peter Maydell @ 2024-04-11 12:01 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-riscv, qemu-arm, Laurent Vivier

On Thu, 11 Apr 2024 at 11:44, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  disas/m68k.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 2/9] disas/microblaze: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 2/9] disas/microblaze: " Philippe Mathieu-Daudé
@ 2024-04-11 12:56   ` Edgar E. Iglesias
  2024-04-11 21:03   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Edgar E. Iglesias @ 2024-04-11 12:56 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-devel, qemu-riscv, qemu-arm

On Thu, Apr 11, 2024 at 12:43 PM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com>


> ---
>  disas/microblaze.c | 25 ++++++++++++++++---------
>  1 file changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/disas/microblaze.c b/disas/microblaze.c
> index 0b89b9c4fa..49a4c0fd40 100644
> --- a/disas/microblaze.c
> +++ b/disas/microblaze.c
> @@ -600,7 +600,8 @@ static char *
>  get_field (long instr, long mask, unsigned short low)
>  {
>    char tmpstr[25];
> -  sprintf(tmpstr, "%s%d", register_prefix, (int)((instr & mask) >> low));
> +  snprintf(tmpstr, sizeof(tmpstr), "%s%d", register_prefix,
> +           (int)((instr & mask) >> low));
>    return(strdup(tmpstr));
>  }
>
> @@ -608,7 +609,8 @@ static char *
>  get_field_imm (long instr)
>  {
>    char tmpstr[25];
> -  sprintf(tmpstr, "%d", (short)((instr & IMM_MASK) >> IMM_LOW));
> +  snprintf(tmpstr, sizeof(tmpstr), "%d",
> +           (short)((instr & IMM_MASK) >> IMM_LOW));
>    return(strdup(tmpstr));
>  }
>
> @@ -616,7 +618,8 @@ static char *
>  get_field_imm5 (long instr)
>  {
>    char tmpstr[25];
> -  sprintf(tmpstr, "%d", (short)((instr & IMM5_MASK) >> IMM_LOW));
> +  snprintf(tmpstr, sizeof(tmpstr), "%d",
> +           (short)((instr & IMM5_MASK) >> IMM_LOW));
>    return(strdup(tmpstr));
>  }
>
> @@ -624,7 +627,8 @@ static char *
>  get_field_rfsl (long instr)
>  {
>    char tmpstr[25];
> -  sprintf(tmpstr, "%s%d", fsl_register_prefix, (short)((instr & RFSL_MASK) >> IMM_LOW));
> +  snprintf(tmpstr, sizeof(tmpstr), "%s%d", fsl_register_prefix,
> +           (short)((instr & RFSL_MASK) >> IMM_LOW));
>    return(strdup(tmpstr));
>  }
>
> @@ -632,7 +636,8 @@ static char *
>  get_field_imm15 (long instr)
>  {
>    char tmpstr[25];
> -  sprintf(tmpstr, "%d", (short)((instr & IMM15_MASK) >> IMM_LOW));
> +  snprintf(tmpstr, sizeof(tmpstr), "%d",
> +           (short)((instr & IMM15_MASK) >> IMM_LOW));
>    return(strdup(tmpstr));
>  }
>
> @@ -641,7 +646,8 @@ static char *
>  get_field_unsigned_imm (long instr)
>  {
>    char tmpstr[25];
> -  sprintf(tmpstr, "%d", (int)((instr & IMM_MASK) >> IMM_LOW));
> +  snprintf(tmpstr, sizeof(tmpstr), "%d",
> +           (int)((instr & IMM_MASK) >> IMM_LOW));
>    return(strdup(tmpstr));
>  }
>  #endif
> @@ -653,7 +659,8 @@ get_field_unsigned_imm (long instr)
>    {
>    char tmpstr[25];
>
> -  sprintf(tmpstr, "%s%s", register_prefix, (((instr & IMM_MASK) >> IMM_LOW) & REG_MSR_MASK) == 0 ? "pc" : "msr");
> +  snprintf(tmpstr, sizeof(tmpstr), "%s%s", register_prefix,
> +          (((instr & IMM_MASK) >> IMM_LOW) & REG_MSR_MASK) == 0 ? "pc" : "msr");
>
>    return(strdup(tmpstr));
>    }
> @@ -709,7 +716,7 @@ get_field_special(long instr, const struct op_code_struct *op)
>     default :
>       {
>         if ( ((((instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask) & 0xE000) == REG_PVR_MASK) {
> -         sprintf(tmpstr, "%s%u", pvr_register_prefix,
> +          snprintf(tmpstr, sizeof(tmpstr), "%s%u", pvr_register_prefix,
>                   (unsigned short)(((instr & IMM_MASK) >> IMM_LOW) ^
>                                    op->immval_mask) ^ REG_PVR_MASK);
>          return(strdup(tmpstr));
> @@ -720,7 +727,7 @@ get_field_special(long instr, const struct op_code_struct *op)
>       break;
>     }
>
> -   sprintf(tmpstr, "%s%s", register_prefix, spr);
> +   snprintf(tmpstr, sizeof(tmpstr), "%s%s", register_prefix, spr);
>     return(strdup(tmpstr));
>  }
>
> --
> 2.41.0
>


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
  2024-04-11 12:01   ` Peter Maydell
@ 2024-04-11 21:01   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2024-04-11 21:01 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-riscv, qemu-arm, Laurent Vivier

On 4/11/24 03:43, Philippe Mathieu-Daudé wrote:
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   disas/m68k.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

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

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 2/9] disas/microblaze: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 2/9] disas/microblaze: " Philippe Mathieu-Daudé
  2024-04-11 12:56   ` Edgar E. Iglesias
@ 2024-04-11 21:03   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2024-04-11 21:03 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-riscv, qemu-arm, Edgar E. Iglesias

On 4/11/24 03:43, Philippe Mathieu-Daudé wrote:
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   disas/microblaze.c | 25 ++++++++++++++++---------
>   1 file changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/disas/microblaze.c b/disas/microblaze.c
> index 0b89b9c4fa..49a4c0fd40 100644
> --- a/disas/microblaze.c
> +++ b/disas/microblaze.c
> @@ -600,7 +600,8 @@ static char *
>   get_field (long instr, long mask, unsigned short low)
>   {
>     char tmpstr[25];
> -  sprintf(tmpstr, "%s%d", register_prefix, (int)((instr & mask) >> low));
> +  snprintf(tmpstr, sizeof(tmpstr), "%s%d", register_prefix,
> +           (int)((instr & mask) >> low));
>     return(strdup(tmpstr));

Any s*printf followed by allocation should use g_strdup_printf to do it in one step.


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 3/9] disas/riscv: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 3/9] disas/riscv: " Philippe Mathieu-Daudé
  2024-04-11 12:00   ` Peter Maydell
@ 2024-04-11 21:12   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2024-04-11 21:12 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-riscv, qemu-arm, Palmer Dabbelt, Alistair Francis

On 4/11/24 03:43, Philippe Mathieu-Daudé wrote:
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   disas/riscv.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)

Ug.  Repeated strlen+strncat?
All of format_inst should be rewritten, probably using GString.


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/9] hw/net/rocker: Replace sprintf() by snprintf()
  2024-04-11 11:30   ` Peter Maydell
@ 2024-04-11 21:22     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 21:22 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, qemu-riscv, qemu-arm, Jiri Pirko, Jason Wang

On 11/4/24 13:30, Peter Maydell wrote:
> On Thu, 11 Apr 2024 at 11:47, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
>> resulting in painful developper experience. Use snprintf() instead.
> 
> ("developer")
> 
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   hw/net/rocker/rocker.c | 24 ++++++++++++------------
>>   1 file changed, 12 insertions(+), 12 deletions(-)
> 
>>           switch (offset) {
>>           case ROCKER_DMA_DESC_ADDR_OFFSET:
>> -            sprintf(buf, "Ring[%s] ADDR", ring_name);
>> +            snprintf(buf, sizeofbuf), "Ring[%s] ADDR", ring_name);
> 
> Something seems to have gone wrong here. Shouldn't this have
> failed to compile ?

This code is guarded by DEBUG_ROCKER, which is why I didn't noticed :)

Indeed when enabling:

../../hw/net/rocker/rocker.c:930:65: error: extraneous ')' before ';'
             snprintf(buf, sizeofbuf), "Ring[%s] ADDR", ring_name);
                                                                 ^


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 7/9] hw/riscv/virt: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 7/9] hw/riscv/virt: " Philippe Mathieu-Daudé
@ 2024-04-11 21:29   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2024-04-11 21:29 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-riscv, qemu-arm, Palmer Dabbelt, Alistair Francis, Bin Meng,
	Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei

On 4/11/24 03:43, Philippe Mathieu-Daudé wrote:
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/riscv/virt.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index d171e74f7b..b3fede1207 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -1619,7 +1619,7 @@ static char *virt_get_aia_guests(Object *obj, Error **errp)
>       RISCVVirtState *s = RISCV_VIRT_MACHINE(obj);
>       char val[32];
>   
> -    sprintf(val, "%d", s->aia_guests);
> +    snprintf(val, sizeof(val), "%d", s->aia_guests);
>       return g_strdup(val);
>   }

g_strdup_printf.

> @@ -1785,7 +1785,8 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
>       object_class_property_add_str(oc, "aia-guests",
>                                     virt_get_aia_guests,
>                                     virt_set_aia_guests);
> -    sprintf(str, "Set number of guest MMIO pages for AIA IMSIC. Valid value "
> +    snprintf(str, sizeof(str),
> +                 "Set number of guest MMIO pages for AIA IMSIC. Valid value "
>                    "should be between 0 and %d.", VIRT_IRQCHIP_MAX_GUESTS);
>       object_class_property_set_description(oc, "aia-guests", str);
>       object_class_property_add(oc, "acpi", "OnOffAuto",

Ok.


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 8/9] target/arm: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 8/9] target/arm: " Philippe Mathieu-Daudé
  2024-04-11 11:32   ` Peter Maydell
@ 2024-04-11 21:29   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2024-04-11 21:29 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-riscv, qemu-arm, Peter Maydell

On 4/11/24 03:43, Philippe Mathieu-Daudé wrote:
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   target/arm/cpu64.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

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

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 9/9] target/i386: Replace sprintf() by snprintf()
  2024-04-11 10:43 ` [PATCH 9/9] target/i386: " Philippe Mathieu-Daudé
  2024-04-11 11:59   ` Peter Maydell
@ 2024-04-11 21:46   ` Richard Henderson
  1 sibling, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2024-04-11 21:46 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-riscv, qemu-arm, Paolo Bonzini, Marcelo Tosatti, kvm

On 4/11/24 03:43, Philippe Mathieu-Daudé wrote:
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/i386/kvm/kvm.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index e68cbe9293..a46d1426bf 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -5335,7 +5335,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
>       case KVM_EXIT_NOTIFY:
>           ctx_invalid = !!(run->notify.flags & KVM_NOTIFY_CONTEXT_INVALID);
>           state = KVM_STATE(current_accel());
> -        sprintf(str, "Encounter a notify exit with %svalid context in"
> +        snprintf(str, sizeof(str),
> +                     "Encounter a notify exit with %svalid context in"
>                        " guest. There can be possible misbehaves in guest."
>                        " Please have a look.", ctx_invalid ? "in" : "");
>           if (ctx_invalid ||

In the larger context,

>         if (ctx_invalid ||
>             state->notify_vmexit == NOTIFY_VMEXIT_OPTION_INTERNAL_ERROR) {
>             warn_report("KVM internal error: %s", str);
>             ret = -1;
>         } else {
>             warn_report_once("KVM: %s", str);
>             ret = 0;
>         }

so there's really no need to sprintf into a buffer at all -- just pass it all to 
warn_report_*.

The English text could use some improvement as well.  :-)


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2024-04-11 21:46 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-11 10:43 [PATCH 0/9] misc: Replace sprintf() by snprintf() due to macOS deprecation Philippe Mathieu-Daudé
2024-04-11 10:43 ` [PATCH 1/9] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
2024-04-11 12:01   ` Peter Maydell
2024-04-11 21:01   ` Richard Henderson
2024-04-11 10:43 ` [PATCH 2/9] disas/microblaze: " Philippe Mathieu-Daudé
2024-04-11 12:56   ` Edgar E. Iglesias
2024-04-11 21:03   ` Richard Henderson
2024-04-11 10:43 ` [PATCH 3/9] disas/riscv: " Philippe Mathieu-Daudé
2024-04-11 12:00   ` Peter Maydell
2024-04-11 21:12   ` Richard Henderson
2024-04-11 10:43 ` [PATCH 4/9] linux-user/flatload: " Philippe Mathieu-Daudé
2024-04-11 11:40   ` Peter Maydell
2024-04-11 10:43 ` [PATCH 5/9] hw/misc/imx: " Philippe Mathieu-Daudé
2024-04-11 10:46   ` Peter Maydell
2024-04-11 10:43 ` [PATCH 6/9] hw/net/rocker: " Philippe Mathieu-Daudé
2024-04-11 11:30   ` Peter Maydell
2024-04-11 21:22     ` Philippe Mathieu-Daudé
2024-04-11 10:43 ` [PATCH 7/9] hw/riscv/virt: " Philippe Mathieu-Daudé
2024-04-11 21:29   ` Richard Henderson
2024-04-11 10:43 ` [PATCH 8/9] target/arm: " Philippe Mathieu-Daudé
2024-04-11 11:32   ` Peter Maydell
2024-04-11 21:29   ` Richard Henderson
2024-04-11 10:43 ` [PATCH 9/9] target/i386: " Philippe Mathieu-Daudé
2024-04-11 11:59   ` Peter Maydell
2024-04-11 21:46   ` Richard Henderson

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).