m68k: Remove sprintf() calls due to macOS deprecation
cover m68k: Remove sprintf() calls due to macOS deprecation
Continuation of:
https://lore.kernel.org/qemu-devel/[email protected]/
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(-)
Signature · 1 line
2.41.0
PATCH 1/2 disas/m68k: Replace sprintf() by snprintf()
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);
^
--- include/disas/dis-asm.h | 2 -- disas/m68k.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-)
include/disas/dis-asm.h +0 -2
@@ -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
disas/m68k.c +2 -2
@@ -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);
Signature · 1 line
2.41.0
Re: [PATCH 1/2] disas/m68k: Replace sprintf() by snprintf()
Quoted 10 lines · Philippe Mathieu-Daudé
disas/m68k.c +1
-1@@ -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); } }
disas/m68k.c print_indexed (int basereg, · line 1075
Quoted 8 lines
disas/m68k.c +1
-1@@ -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~
PATCH 2/2 target/m68k: Remove sprintf() calls
In reply to 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);
^--- target/m68k/translate.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
target/m68k/translate.c +15 -12
@@ -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" );
Signature · 1 line
2.41.0
Re: [PATCH 2/2] target/m68k: Remove sprintf() calls
Quoted 19 lines · 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); ^
Quoted 4 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/m68k/translate.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
r~