]> git.lizzy.rs Git - irrlicht.git/commitdiff
Get rid of all sprintf calls
authorsfan5 <sfan5@live.de>
Sat, 26 Feb 2022 10:18:19 +0000 (11:18 +0100)
committersfan5 <sfan5@live.de>
Sat, 26 Feb 2022 11:11:27 +0000 (12:11 +0100)
source/Irrlicht/CIrrDeviceLinux.cpp
source/Irrlicht/CIrrDeviceSDL.cpp
source/Irrlicht/CIrrDeviceWin32.cpp
source/Irrlicht/CNullDriver.cpp
source/Irrlicht/CProfiler.cpp
source/Irrlicht/CZipReader.cpp

index c4f8d4e70259ceb9d45fed4df4c0083f4362dbaa..243415d773ce8844f6becf1ae27fda31d38c376e 100644 (file)
@@ -1701,7 +1701,7 @@ bool CIrrDeviceLinux::activateJoysticks(core::array<SJoystickInfo> & joystickInf
        for (joystick = 0; joystick < joystickInfo.size(); ++joystick)\r
        {\r
                char logString[256];\r
-               (void)sprintf(logString, "Found joystick %u, %u axes, %u buttons '%s'",\r
+               snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'",\r
                        joystick, joystickInfo[joystick].Axes,\r
                        joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str());\r
                os::Printer::log(logString, ELL_INFORMATION);\r
index 1ecf56d9609e01854f6f0e2bac82ceb3d27c3511..bf7da7fdaa4065083fac12936903ea52d0c731e3 100644 (file)
@@ -846,9 +846,9 @@ bool CIrrDeviceSDL::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
        for(joystick = 0; joystick < (int)joystickInfo.size(); ++joystick)\r
        {\r
                char logString[256];\r
-               (void)sprintf(logString, "Found joystick %d, %d axes, %d buttons '%s'",\r
-               joystick, joystickInfo[joystick].Axes,\r
-               joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str());\r
+               snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'",\r
+                       joystick, joystickInfo[joystick].Axes,\r
+                       joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str());\r
                os::Printer::log(logString, ELL_INFORMATION);\r
        }\r
 \r
index 101068e73c337cb82d976880497956cd249c4400..4fedde2151d2e759f3882f137594c298aef528ed 100644 (file)
@@ -514,7 +514,7 @@ bool SJoystickWin32Control::activateJoysticks(core::array<SJoystickInfo> & joyst
        for(joystick = 0; joystick < joystickInfo.size(); ++joystick)\r
        {\r
                char logString[256];\r
-               (void)sprintf(logString, "Found joystick %d, %d axes, %d buttons '%s'",\r
+               snprintf_irr(logString, sizeof(logString), "Found joystick %d, %d axes, %d buttons '%s'",\r
                        joystick, joystickInfo[joystick].Axes,\r
                        joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str());\r
                os::Printer::log(logString, ELL_INFORMATION);\r
@@ -1096,12 +1096,12 @@ void CIrrDeviceWin32::resizeIfNecessary()
 \r
        if (r.right < 2 || r.bottom < 2)\r
        {\r
-               sprintf(tmp, "Ignoring resize operation to (%ld %ld)", r.right, r.bottom);\r
+               snprintf_irr(tmp, sizeof(tmp), "Ignoring resize operation to (%ld %ld)", r.right, r.bottom);\r
                os::Printer::log(tmp);\r
        }\r
        else\r
        {\r
-               sprintf(tmp, "Resizing window (%ld %ld)", r.right, r.bottom);\r
+               snprintf_irr(tmp, sizeof(tmp), "Resizing window (%ld %ld)", r.right, r.bottom);\r
                os::Printer::log(tmp);\r
 \r
                getVideoDriver()->OnResize(irr::core::dimension2du((u32)r.right, (u32)r.bottom));\r
index 71fc9a8e1043a0a9153e103da432e4905e6f22e0..20ee0938b73e69b3208f7da0ffd0008f7496ae20 100644 (file)
@@ -1307,8 +1307,8 @@ bool CNullDriver::checkPrimitiveCount(u32 prmCount) const
 \r
        if (prmCount > m)\r
        {\r
-               char tmp[1024];\r
-               sprintf(tmp,"Could not draw triangles, too many primitives(%u), maximum is %u.", prmCount, m);\r
+               char tmp[128];\r
+               snprintf_irr(tmp, sizeof(tmp), "Could not draw triangles, too many primitives(%u), maximum is %u.", prmCount, m);\r
                os::Printer::log(tmp, ELL_ERROR);\r
                return false;\r
        }\r
index 537bea44cbadd3edbdc3dca5fdb490f4edc5c2ca..9428f2136ab94dfba262dd9983c344322656174c 100644 (file)
@@ -73,21 +73,12 @@ core::stringw CProfiler::getAsString(const SProfileData& data) const
 {\r
        if ( data.getCallsCounter() > 0 )\r
        {\r
-#ifdef _MSC_VER\r
-#pragma warning(disable:4996)  // 'sprintf' was declared deprecated\r
-#endif\r
-               // Can't use swprintf as it fails on some platforms (especially mobile platforms)\r
-               // Can't use Irrlicht functions because we have no string formatting.\r
-               char dummy[1023];\r
-               sprintf(dummy, "%-15.15s%-12u%-12u%-12u%-12u",\r
-                       core::stringc(data.getName()).c_str(), data.getCallsCounter(), data.getTimeSum(),\r
+               wchar_t dummy[512];\r
+               swprintf_irr(dummy, 512, L"%-15.15s%-12u%-12u%-12u%-12u",\r
+                       data.getName().c_str(), data.getCallsCounter(), data.getTimeSum(),\r
                        data.getTimeSum() / data.getCallsCounter(), data.getLongestTime());\r
-               dummy[1022] = 0;\r
 \r
                return core::stringw(dummy);\r
-#ifdef _MSC_VER\r
-#pragma warning(default :4996) // 'sprintf' was declared deprecated\r
-#endif\r
        }\r
        else\r
        {\r
index cac4df2eb7e5766b51893dfad5347249d65b19fd..d394313d9853c79de57627f93d29099f65f87da9 100644 (file)
@@ -448,7 +448,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index)
        //99 - AES encryption, WinZip 9\r
 \r
        const SZipFileEntry &e = FileInfo[Files[index].ID];\r
-       wchar_t buf[64];\r
+       char buf[64];\r
        s16 actualCompressionMethod=e.header.CompressionMethod;\r
        IReadFile* decrypted=0;\r
        u8* decryptedBuf=0;\r
@@ -470,7 +470,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index)
                        c8* pBuf = new c8[ uncompressedSize ];\r
                        if (!pBuf)\r
                        {\r
-                               swprintf_irr ( buf, 64, L"Not enough memory for decompressing %s", core::stringw(Files[index].FullName).c_str() );\r
+                               snprintf_irr ( buf, 64, "Not enough memory for decompressing %s", Files[index].FullName.c_str() );\r
                                os::Printer::log( buf, ELL_ERROR);\r
                                if (decrypted)\r
                                        decrypted->drop();\r
@@ -483,7 +483,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index)
                                pcData = new u8[decryptedSize];\r
                                if (!pcData)\r
                                {\r
-                                       swprintf_irr ( buf, 64, L"Not enough memory for decompressing %s", core::stringw(Files[index].FullName).c_str() );\r
+                                       snprintf_irr ( buf, 64, "Not enough memory for decompressing %s", Files[index].FullName.c_str() );\r
                                        os::Printer::log( buf, ELL_ERROR);\r
                                        delete [] pBuf;\r
                                        return 0;\r
@@ -524,7 +524,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index)
 \r
                        if (err != Z_OK)\r
                        {\r
-                               swprintf_irr ( buf, 64, L"Error decompressing %s", core::stringw(Files[index].FullName).c_str() );\r
+                               snprintf_irr ( buf, 64, "Error decompressing %s", Files[index].FullName.c_str() );\r
                                os::Printer::log( buf, ELL_ERROR);\r
                                delete [] pBuf;\r
                                return 0;\r
@@ -551,7 +551,7 @@ IReadFile* CZipReader::createAndOpenFile(u32 index)
                os::Printer::log("Decryption support not enabled. File cannot be read.", ELL_ERROR);\r
                return 0;\r
        default:\r
-               swprintf_irr ( buf, 64, L"file has unsupported compression method. %s", core::stringw(Files[index].FullName).c_str() );\r
+               snprintf_irr ( buf, 64, "file has unsupported compression method. %s", Files[index].FullName.c_str() );\r
                os::Printer::log( buf, ELL_ERROR);\r
                return 0;\r
        };\r