diff mbox series

[3/9] disas/riscv: Replace sprintf() by snprintf()

Message ID 20240411104340.6617-4-philmd@linaro.org
State New
Headers show
Series misc: Replace sprintf() by snprintf() due to macOS deprecation | expand

Commit Message

Philippe Mathieu-Daudé April 11, 2024, 10:43 a.m. UTC
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(-)

Comments

Peter Maydell April 11, 2024, noon UTC | #1
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
Richard Henderson April 11, 2024, 9:12 p.m. UTC | #2
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~
diff mbox series

Patch

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