* [PATCH 0/2] m68k: Remove sprintf() calls due to macOS deprecation
@ 2024-04-11 21:39 Philippe Mathieu-Daudé
2024-04-11 21:39 ` [PATCH 1/2] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
2024-04-11 21:39 ` [PATCH 2/2] target/m68k: Remove sprintf() calls Philippe Mathieu-Daudé
0 siblings, 2 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 21:39 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier, Philippe =?unknown-8bit?q?Mathieu-Daud=C3=A9?=
Continuation of:
https://lore.kernel.org/qemu-devel/20240411101550.99392-1-philmd@linaro.org/
Philippe Mathieu-Daudé (2):
disas/m68k: Replace sprintf() by snprintf()
target/m68k: Remove sprintf() calls
include/disas/dis-asm.h | 2 --
disas/m68k.c | 4 ++--
target/m68k/translate.c | 27 +++++++++++++++------------
3 files changed, 17 insertions(+), 16 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] disas/m68k: Replace sprintf() by snprintf()
2024-04-11 21:39 [PATCH 0/2] m68k: Remove sprintf() calls due to macOS deprecation Philippe Mathieu-Daudé
@ 2024-04-11 21:39 ` Philippe Mathieu-Daudé
2024-04-11 21:57 ` Richard Henderson
2024-04-11 21:39 ` [PATCH 2/2] target/m68k: Remove sprintf() calls Philippe Mathieu-Daudé
1 sibling, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 21:39 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier, Philippe Mathieu-Daudé
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(-)
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);
--
2.41.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] target/m68k: Remove sprintf() calls
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:39 ` Philippe Mathieu-Daudé
2024-04-11 21:58 ` Richard Henderson
1 sibling, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-11 21:39 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier, Philippe Mathieu-Daudé
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] disas/m68k: Replace sprintf() by snprintf()
2024-04-11 21:39 ` [PATCH 1/2] disas/m68k: Replace sprintf() by snprintf() Philippe Mathieu-Daudé
@ 2024-04-11 21:57 ` Richard Henderson
0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2024-04-11 21:57 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Laurent Vivier
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~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] target/m68k: Remove sprintf() calls
2024-04-11 21:39 ` [PATCH 2/2] target/m68k: Remove sprintf() calls Philippe Mathieu-Daudé
@ 2024-04-11 21:58 ` Richard Henderson
0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2024-04-11 21:58 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Laurent Vivier
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~
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-11 21:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/2] target/m68k: Remove sprintf() calls Philippe Mathieu-Daudé
2024-04-11 21:58 ` 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).