From 982d9385b988835072c4fb000eca61b026fc1d6f Mon Sep 17 00:00:00 2001 From: arbee Date: Sat, 3 Jun 2023 16:52:00 -0400 Subject: [PATCH] Clean up several sprintf() deprecation warningss in non-3rdparty code. [R. Belmont] --- src/devices/cpu/h8/h8_timer16.cpp | 2 +- src/devices/cpu/i386/i386dasm.cpp | 8 ++++---- src/devices/cpu/m68000/m68kfpu.cpp | 2 +- src/devices/cpu/powerpc/ppccom.cpp | 6 +++--- src/devices/cpu/powerpc/ppcdrc.cpp | 4 ++-- src/devices/imagedev/flopdrv.cpp | 2 +- src/devices/machine/corvushd.cpp | 2 +- src/devices/machine/i2cmem.cpp | 2 +- src/devices/machine/wd_fdc.cpp | 8 ++++---- src/emu/attotime.cpp | 8 ++++---- src/emu/debug/debugcmd.cpp | 2 +- src/emu/debug/debugcpu.cpp | 2 +- src/emu/debug/dvmemory.cpp | 8 ++++---- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/devices/cpu/h8/h8_timer16.cpp b/src/devices/cpu/h8/h8_timer16.cpp index 2527a2aa0cb..2d000a50b71 100644 --- a/src/devices/cpu/h8/h8_timer16.cpp +++ b/src/devices/cpu/h8/h8_timer16.cpp @@ -330,7 +330,7 @@ void h8_timer16_device::device_start() memset(m_timer_channel, 0, sizeof(m_timer_channel)); for(int i=0; i(tm); } diff --git a/src/devices/cpu/i386/i386dasm.cpp b/src/devices/cpu/i386/i386dasm.cpp index 2140df040b1..6b882259574 100644 --- a/src/devices/cpu/i386/i386dasm.cpp +++ b/src/devices/cpu/i386/i386dasm.cpp @@ -1914,9 +1914,9 @@ char *i386_disassembler::hexstring(uint32_t value, int digits) static char buffer[20]; buffer[0] = '0'; if (digits) - sprintf(&buffer[1], "%0*Xh", digits, value); + snprintf(&buffer[1], 19, "%0*Xh", digits, value); else - sprintf(&buffer[1], "%Xh", value); + snprintf(&buffer[1], 19, "%Xh", value); return (buffer[1] >= '0' && buffer[1] <= '9') ? &buffer[1] : &buffer[0]; } @@ -1925,9 +1925,9 @@ char *i386_disassembler::hexstring64(uint32_t lo, uint32_t hi) static char buffer[40]; buffer[0] = '0'; if (hi != 0) - sprintf(&buffer[1], "%X%08Xh", hi, lo); + snprintf(&buffer[1], 39, "%X%08Xh", hi, lo); else - sprintf(&buffer[1], "%Xh", lo); + snprintf(&buffer[1], 39, "%Xh", lo); return (buffer[1] >= '0' && buffer[1] <= '9') ? &buffer[1] : &buffer[0]; } diff --git a/src/devices/cpu/m68000/m68kfpu.cpp b/src/devices/cpu/m68000/m68kfpu.cpp index c884772d83e..e8acf965db6 100644 --- a/src/devices/cpu/m68000/m68kfpu.cpp +++ b/src/devices/cpu/m68000/m68kfpu.cpp @@ -118,7 +118,7 @@ inline void m68000_musashi_device::store_pack_float80(u32 ea, int k, floatx80 fp dw1 = dw2 = dw3 = 0; ch = &str[0]; - sprintf(str, "%.16e", fx80_to_double(fpr)); + snprintf(str, 128, "%.16e", fx80_to_double(fpr)); if (*ch == '-') { diff --git a/src/devices/cpu/powerpc/ppccom.cpp b/src/devices/cpu/powerpc/ppccom.cpp index f72faa59f66..b0e4b583955 100644 --- a/src/devices/cpu/powerpc/ppccom.cpp +++ b/src/devices/cpu/powerpc/ppccom.cpp @@ -876,15 +876,15 @@ void ppc_device::device_start() for (int regnum = 0; regnum < 32; regnum++) { char buf[10]; - sprintf(buf, "r%d", regnum); + snprintf(buf, 10, "r%d", regnum); m_drcuml->symbol_add(&m_core->r[regnum], sizeof(m_core->r[regnum]), buf); - sprintf(buf, "fpr%d", regnum); + snprintf(buf, 10, "fpr%d", regnum); m_drcuml->symbol_add(&m_core->f[regnum], sizeof(m_core->f[regnum]), buf); } for (int regnum = 0; regnum < 8; regnum++) { char buf[10]; - sprintf(buf, "cr%d", regnum); + snprintf(buf, 10, "cr%d", regnum); m_drcuml->symbol_add(&m_core->cr[regnum], sizeof(m_core->cr[regnum]), buf); } m_drcuml->symbol_add(&m_core->xerso, sizeof(m_core->xerso), "xerso"); diff --git a/src/devices/cpu/powerpc/ppcdrc.cpp b/src/devices/cpu/powerpc/ppcdrc.cpp index 58933f9e0c3..b1f2a2a2568 100644 --- a/src/devices/cpu/powerpc/ppcdrc.cpp +++ b/src/devices/cpu/powerpc/ppcdrc.cpp @@ -1465,7 +1465,7 @@ void ppc_device::static_generate_lsw_entries(int mode) char temp[20]; /* allocate a handle */ - sprintf(temp, "lsw%d", regnum); + snprintf(temp, 20, "lsw%d", regnum); alloc_handle(m_drcuml.get(), &m_lsw[mode][regnum], temp); UML_HANDLE(block, *m_lsw[mode][regnum]); // handle lsw UML_LABEL(block, regnum); // regnum: @@ -1517,7 +1517,7 @@ void ppc_device::static_generate_stsw_entries(int mode) char temp[20]; /* allocate a handle */ - sprintf(temp, "stsw%d", regnum); + snprintf(temp, 20, "stsw%d", regnum); alloc_handle(m_drcuml.get(), &m_stsw[mode][regnum], temp); UML_HANDLE(block, *m_stsw[mode][regnum]); // handle stsw UML_LABEL(block, regnum); // regnum: diff --git a/src/devices/imagedev/flopdrv.cpp b/src/devices/imagedev/flopdrv.cpp index 4443cbb461c..7c422790c14 100644 --- a/src/devices/imagedev/flopdrv.cpp +++ b/src/devices/imagedev/flopdrv.cpp @@ -108,7 +108,7 @@ void legacy_floppy_image_device::log_readwrite(const char *name, int head, int t char membuf[1024]; int i; for (i = 0; i < length; i++) - sprintf(membuf + i*2, "%02x", (int) (uint8_t) buf[i]); + snprintf(membuf + i*2, 1024 - (i*2), "%02x", (int) (uint8_t) buf[i]); logerror("%s: head=%i track=%i sector=%i buffer='%s'\n", name, head, track, sector, membuf); } diff --git a/src/devices/machine/corvushd.cpp b/src/devices/machine/corvushd.cpp index e6cdead1c10..6b4a2c15c99 100644 --- a/src/devices/machine/corvushd.cpp +++ b/src/devices/machine/corvushd.cpp @@ -282,7 +282,7 @@ void corvus_hdc_device::dump_buffer(uint8_t *buffer, uint16_t length) { for(uint16_t offset = 0; offset < length; offset += 16) { int buf_offset = 0; for(uint8_t byte_idx = 0; byte_idx < 16 && (offset + byte_idx) < length; byte_idx++) { - sprintf(data_buf + buf_offset, "%02x ", *(buffer + offset)); + snprintf(data_buf + buf_offset, 128 - buf_offset, "%02x ", *(buffer + offset)); ascii_buf[byte_idx] = isprint(*(buffer + offset)) ? *(buffer + offset) : '.'; } if((length - offset) < 16) { diff --git a/src/devices/machine/i2cmem.cpp b/src/devices/machine/i2cmem.cpp index b1d1d0d372c..74504eb43ce 100644 --- a/src/devices/machine/i2cmem.cpp +++ b/src/devices/machine/i2cmem.cpp @@ -52,7 +52,7 @@ static inline void ATTR_PRINTF( 3, 4 ) verboselog( device_t *device, int n_level va_list v; char buf[ 32768 ]; va_start( v, s_fmt ); - vsprintf( buf, s_fmt, v ); + vsnprintf( buf, 32768, s_fmt, v ); va_end( v ); device->logerror( "%s: I2CMEM %s", device->machine().describe_context(), buf ); } diff --git a/src/devices/machine/wd_fdc.cpp b/src/devices/machine/wd_fdc.cpp index b6570b1da0d..96803ca77f9 100644 --- a/src/devices/machine/wd_fdc.cpp +++ b/src/devices/machine/wd_fdc.cpp @@ -932,9 +932,9 @@ void wd_fdc_device_base::write_track_continue() if(format_last_byte_count) { char buf[32]; if(format_last_byte_count > 1) - sprintf(buf, "%dx%02x", format_last_byte_count, format_last_byte); + snprintf(buf, 32, "%dx%02x", format_last_byte_count, format_last_byte); else - sprintf(buf, "%02x", format_last_byte); + snprintf(buf, 32, "%02x", format_last_byte); format_description_string += buf; } LOGDESC("track description %s\n", format_description_string.c_str()); @@ -2104,9 +2104,9 @@ void wd_fdc_device_base::live_run(attotime limit) if(format_last_byte_count) { char buf[32]; if(format_last_byte_count > 1) - sprintf(buf, "%dx%02x ", format_last_byte_count, format_last_byte); + snprintf(buf, 32, "%dx%02x ", format_last_byte_count, format_last_byte); else - sprintf(buf, "%02x ", format_last_byte); + snprintf(buf, 32, "%02x ", format_last_byte); format_description_string += buf; } format_last_byte = data; diff --git a/src/emu/attotime.cpp b/src/emu/attotime.cpp index a1ba4d9ed61..030c3193551 100644 --- a/src/emu/attotime.cpp +++ b/src/emu/attotime.cpp @@ -119,11 +119,11 @@ const char *attotime::as_string(int precision) const // special case: never if (*this == never) - sprintf(buffer, "%-*s", precision, "(never)"); + snprintf(buffer, 30, "%-*s", precision, "(never)"); // case 1: we want no precision; seconds only else if (precision == 0) - sprintf(buffer, "%d", m_seconds); + snprintf(buffer, 30, "%d", m_seconds); // case 2: we want 9 or fewer digits of precision else if (precision <= 9) @@ -135,7 +135,7 @@ const char *attotime::as_string(int precision) const upper /= 10; temp++; } - sprintf(buffer, "%d.%0*d", m_seconds, precision, upper); + snprintf(buffer, 30, "%d.%0*d", m_seconds, precision, upper); } // case 3: more than 9 digits of precision @@ -149,7 +149,7 @@ const char *attotime::as_string(int precision) const lower /= 10; temp++; } - sprintf(buffer, "%d.%09d%0*d", m_seconds, upper, precision - 9, lower); + snprintf(buffer, 30, "%d.%09d%0*d", m_seconds, upper, precision - 9, lower); } return buffer; } diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index 813baee1841..730565494a4 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -170,7 +170,7 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu if ((valcount == 1) && (blockcount == 1) && strstr(name, "/globals/")) { char symname[100]; - sprintf(symname, ".%s", strrchr(name, '/') + 1); + snprintf(symname, 100, ".%s", strrchr(name, '/') + 1); m_global_array[itemnum].base = base; m_global_array[itemnum].size = valsize; symtable.add( diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index a24cf555aee..5c5a186e2aa 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -94,7 +94,7 @@ debugger_cpu::debugger_cpu(running_machine &machine) for (int regnum = 0; regnum < NUM_TEMP_VARIABLES; regnum++) { char symname[10]; - sprintf(symname, "temp%d", regnum); + snprintf(symname, 10, "temp%d", regnum); m_symtable->add(symname, symbol_table::READ_WRITE, &m_tempvar[regnum]); } } diff --git a/src/emu/debug/dvmemory.cpp b/src/emu/debug/dvmemory.cpp index c0fe1ead5c6..da792305c0d 100644 --- a/src/emu/debug/dvmemory.cpp +++ b/src/emu/debug/dvmemory.cpp @@ -309,7 +309,7 @@ void debug_view_memory::generate_row(debug_view_char *destmin, debug_view_char * // generate the address char addrtext[20]; - sprintf(addrtext, m_addrformat.c_str(), address); + snprintf(addrtext, 20, m_addrformat.c_str(), address); debug_view_char *dest = destrow + m_section[0].m_pos + 1; for (int ch = 0; addrtext[ch] != 0 && ch < m_section[0].m_width - 1; ch++, dest++) if (dest >= destmin && dest < destmax) @@ -359,15 +359,15 @@ void debug_view_memory::generate_row(debug_view_char *destmin, debug_view_char * switch (m_data_format) { case data_format::FLOAT_32BIT: - sprintf(valuetext, "%.8g", u32_to_float(u32(chunkdata))); + snprintf(valuetext, 64, "%.8g", u32_to_float(u32(chunkdata))); break; case data_format::FLOAT_64BIT: - sprintf(valuetext, "%.24g", u64_to_double(chunkdata)); + snprintf(valuetext, 64, "%.24g", u64_to_double(chunkdata)); break; case data_format::FLOAT_80BIT: { float64_t f64 = extF80M_to_f64(&chunkdata80); - sprintf(valuetext, "%.24g", u64_to_double(f64.v)); + snprintf(valuetext, 64, "%.24g", u64_to_double(f64.v)); break; } default: