diff mbox series

[1/2] disas/m68k: Replace sprintf() by snprintf()

Message ID 20240411213933.36548-2-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.

Inline sprintf_vma() and use snprintf() instead of sprintf(),
silencing the following warning:

  [38/244] Compiling C object libcommon.fa.p/disas_m68k.c.o
  disas/m68k.c:977:7: 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_vma (buf, disp);
      ^

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/disas/dis-asm.h | 2 --
 disas/m68k.c            | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

Comments

Richard Henderson April 11, 2024, 9:57 p.m. UTC | #1
On 4/11/24 14:39, Philippe Mathieu-Daudé wrote:
> @@ -974,7 +974,7 @@ print_base (int regno, bfd_vma disp, disassemble_info *info)
>         else
>   	(*info->fprintf_func) (info->stream, "%s@(", reg_names[regno]);
>   
> -      sprintf_vma (buf, disp);
> +      snprintf(buf, sizeof(buf), "%0" PRIx64, disp);
>         (*info->fprintf_func) (info->stream, "%s", buf);
>       }
>   }
> @@ -1069,7 +1069,7 @@ print_indexed (int basereg,
>         (*info->fprintf_func) (info->stream, ",%s", buf);
>         buf[0] = '\0';
>       }
> -  sprintf_vma (vmabuf, outer_disp);
> +  snprintf(vmabuf, sizeof(vmabuf), "%0" PRIx64, outer_disp);
>     (*info->fprintf_func) (info->stream, ")@(%s", vmabuf);
>     if (buf[0] != '\0')
>       (*info->fprintf_func) (info->stream, ",%s", buf);

In both cases, there's no need for the sprintf at all.
Fold everything into the adjacent fprintf.


r~
diff mbox series

Patch

diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h
index b26867b641..1d8a4ce9a1 100644
--- a/include/disas/dis-asm.h
+++ b/include/disas/dis-asm.h
@@ -15,8 +15,6 @@  typedef void *PTR;
 typedef uint64_t bfd_vma;
 typedef int64_t bfd_signed_vma;
 typedef uint8_t bfd_byte;
-#define sprintf_vma(s,x) sprintf (s, "%0" PRIx64, x)
-#define snprintf_vma(s,ss,x) snprintf (s, ss, "%0" PRIx64, x)
 
 #define BFD64
 
diff --git a/disas/m68k.c b/disas/m68k.c
index 800b4145ac..e8e61c7a4e 100644
--- a/disas/m68k.c
+++ b/disas/m68k.c
@@ -974,7 +974,7 @@  print_base (int regno, bfd_vma disp, disassemble_info *info)
       else
 	(*info->fprintf_func) (info->stream, "%s@(", reg_names[regno]);
 
-      sprintf_vma (buf, disp);
+      snprintf(buf, sizeof(buf), "%0" PRIx64, disp);
       (*info->fprintf_func) (info->stream, "%s", buf);
     }
 }
@@ -1069,7 +1069,7 @@  print_indexed (int basereg,
       (*info->fprintf_func) (info->stream, ",%s", buf);
       buf[0] = '\0';
     }
-  sprintf_vma (vmabuf, outer_disp);
+  snprintf(vmabuf, sizeof(vmabuf), "%0" PRIx64, outer_disp);
   (*info->fprintf_func) (info->stream, ")@(%s", vmabuf);
   if (buf[0] != '\0')
     (*info->fprintf_func) (info->stream, ",%s", buf);