From 95af6d7c0859c7e21853d4b47ab9587af7f213b8 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 26 Feb 2022 11:18:19 +0100 Subject: [PATCH] Get rid of all sprintf calls --- source/Irrlicht/CIrrDeviceLinux.cpp | 2 +- source/Irrlicht/CIrrDeviceSDL.cpp | 6 +++--- source/Irrlicht/CIrrDeviceWin32.cpp | 6 +++--- source/Irrlicht/CNullDriver.cpp | 4 ++-- source/Irrlicht/CProfiler.cpp | 15 +++------------ source/Irrlicht/CZipReader.cpp | 10 +++++----- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index c4f8d4e7..243415d7 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -1701,7 +1701,7 @@ bool CIrrDeviceLinux::activateJoysticks(core::array & joystickInf for (joystick = 0; joystick < joystickInfo.size(); ++joystick) { char logString[256]; - (void)sprintf(logString, "Found joystick %u, %u axes, %u buttons '%s'", + snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'", joystick, joystickInfo[joystick].Axes, joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str()); os::Printer::log(logString, ELL_INFORMATION); diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 1ecf56d9..bf7da7fd 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -846,9 +846,9 @@ bool CIrrDeviceSDL::activateJoysticks(core::array & joystickInfo) for(joystick = 0; joystick < (int)joystickInfo.size(); ++joystick) { char logString[256]; - (void)sprintf(logString, "Found joystick %d, %d axes, %d buttons '%s'", - joystick, joystickInfo[joystick].Axes, - joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str()); + snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'", + joystick, joystickInfo[joystick].Axes, + joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str()); os::Printer::log(logString, ELL_INFORMATION); } diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index 101068e7..4fedde21 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -514,7 +514,7 @@ bool SJoystickWin32Control::activateJoysticks(core::array & joyst for(joystick = 0; joystick < joystickInfo.size(); ++joystick) { char logString[256]; - (void)sprintf(logString, "Found joystick %d, %d axes, %d buttons '%s'", + snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'", joystick, joystickInfo[joystick].Axes, joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str()); os::Printer::log(logString, ELL_INFORMATION); @@ -1096,12 +1096,12 @@ void CIrrDeviceWin32::resizeIfNecessary() if (r.right < 2 || r.bottom < 2) { - sprintf(tmp, "Ignoring resize operation to (%ld %ld)", r.right, r.bottom); + snprintf_irr(tmp, sizeof(tmp), "Ignoring resize operation to (%ld %ld)", r.right, r.bottom); os::Printer::log(tmp); } else { - sprintf(tmp, "Resizing window (%ld %ld)", r.right, r.bottom); + snprintf_irr(tmp, sizeof(tmp), "Resizing window (%ld %ld)", r.right, r.bottom); os::Printer::log(tmp); getVideoDriver()->OnResize(irr::core::dimension2du((u32)r.right, (u32)r.bottom)); diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 71fc9a8e..20ee0938 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -1307,8 +1307,8 @@ bool CNullDriver::checkPrimitiveCount(u32 prmCount) const if (prmCount > m) { - char tmp[1024]; - sprintf(tmp,"Could not draw triangles, too many primitives(%u), maximum is %u.", prmCount, m); + char tmp[128]; + snprintf_irr(tmp, sizeof(tmp), "Could not draw triangles, too many primitives(%u), maximum is %u.", prmCount, m); os::Printer::log(tmp, ELL_ERROR); return false; } diff --git a/source/Irrlicht/CProfiler.cpp b/source/Irrlicht/CProfiler.cpp index 537bea44..9428f213 100644 --- a/source/Irrlicht/CProfiler.cpp +++ b/source/Irrlicht/CProfiler.cpp @@ -73,21 +73,12 @@ core::stringw CProfiler::getAsString(const SProfileData& data) const { if ( data.getCallsCounter() > 0 ) { -#ifdef _MSC_VER -#pragma warning(disable:4996) // 'sprintf' was declared deprecated -#endif - // Can't use swprintf as it fails on some platforms (especially mobile platforms) - // Can't use Irrlicht functions because we have no string formatting. - char dummy[1023]; - sprintf(dummy, "%-15.15s%-12u%-12u%-12u%-12u", - core::stringc(data.getName()).c_str(), data.getCallsCounter(), data.getTimeSum(), + wchar_t dummy[512]; + swprintf_irr(dummy, 512, L"%-15.15s%-12u%-12u%-12u%-12u", + data.getName().c_str(), data.getCallsCounter(), data.getTimeSum(), data.getTimeSum() / data.getCallsCounter(), data.getLongestTime()); - dummy[1022] = 0; return core::stringw(dummy); -#ifdef _MSC_VER -#pragma warning(default :4996) // 'sprintf' was declared deprecated -#endif } else { diff --git a/source/Irrlicht/CZipReader.cpp b/source/Irrlicht/CZipReader.cpp index cac4df2e..d394313d 100644 --- a/source/Irrlicht/CZipReader.cpp +++ b/source/Irrlicht/CZipReader.cpp @@ -448,7 +448,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index) //99 - AES encryption, WinZip 9 const SZipFileEntry &e = FileInfo[Files[index].ID]; - wchar_t buf[64]; + char buf[64]; s16 actualCompressionMethod=e.header.CompressionMethod; IReadFile* decrypted=0; u8* decryptedBuf=0; @@ -470,7 +470,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index) c8* pBuf = new c8[ uncompressedSize ]; if (!pBuf) { - swprintf_irr ( buf, 64, L"Not enough memory for decompressing %s", core::stringw(Files[index].FullName).c_str() ); + snprintf_irr ( buf, 64, "Not enough memory for decompressing %s", Files[index].FullName.c_str() ); os::Printer::log( buf, ELL_ERROR); if (decrypted) decrypted->drop(); @@ -483,7 +483,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index) pcData = new u8[decryptedSize]; if (!pcData) { - swprintf_irr ( buf, 64, L"Not enough memory for decompressing %s", core::stringw(Files[index].FullName).c_str() ); + snprintf_irr ( buf, 64, "Not enough memory for decompressing %s", Files[index].FullName.c_str() ); os::Printer::log( buf, ELL_ERROR); delete [] pBuf; return 0; @@ -524,7 +524,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index) if (err != Z_OK) { - swprintf_irr ( buf, 64, L"Error decompressing %s", core::stringw(Files[index].FullName).c_str() ); + snprintf_irr ( buf, 64, "Error decompressing %s", Files[index].FullName.c_str() ); os::Printer::log( buf, ELL_ERROR); delete [] pBuf; return 0; @@ -551,7 +551,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index) os::Printer::log("Decryption support not enabled. File cannot be read.", ELL_ERROR); return 0; default: - swprintf_irr ( buf, 64, L"file has unsupported compression method. %s", core::stringw(Files[index].FullName).c_str() ); + snprintf_irr ( buf, 64, "file has unsupported compression method. %s", Files[index].FullName.c_str() ); os::Printer::log( buf, ELL_ERROR); return 0; };