diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-31 14:46:38 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-02-01 12:15:22 +0000 |
commit | 2489000d3fd66319a8355fd4e37cfdfda47296d0 (patch) | |
tree | caad79e7b5bec3863604b20190b682c0d73d2b25 /sal/qa/rtl/random | |
parent | 595848c85acc2609fcc48a40c7a9f216a2722cd8 (diff) |
loplugin:useuniqueptr extend to check local vars
just the simple and obvious case for now, of a local var being allocated
and deleted inside a single local block, and the delete happening at the
end of the block
Change-Id: I3a7a094da543debdcd2374737c2ecff91d644625
Reviewed-on: https://gerrit.libreoffice.org/33749
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal/qa/rtl/random')
-rw-r--r-- | sal/qa/rtl/random/rtl_random.cxx | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/sal/qa/rtl/random/rtl_random.cxx b/sal/qa/rtl/random/rtl_random.cxx index a9ecf9ec8b0a..f537c7c832d6 100644 --- a/sal/qa/rtl/random/rtl_random.cxx +++ b/sal/qa/rtl/random/rtl_random.cxx @@ -98,8 +98,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); rtlRandomError aError = rtl_random_addBytes(nullptr, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); @@ -107,12 +107,10 @@ public: /* rtlRandomError */ aError = rtl_random_addBytes(aPool, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); - /* rtlRandomError */ aError = rtl_random_addBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError */ aError = rtl_random_addBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); rtl_random_destroyPool(aPool); - delete [] pBuffer; - } void addBytes_001() @@ -120,16 +118,15 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); - memset(pBuffer, 0, nBufLen); + memset(pBuffer.get(), 0, nBufLen); - rtl_random_addBytes(aPool, pBuffer, nBufLen); + rtl_random_addBytes(aPool, pBuffer.get(), nBufLen); printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); rtl_random_destroyPool(aPool); - delete [] pBuffer; } // Change the following lines only, if you add, remove or rename @@ -220,8 +217,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); rtlRandomError aError = rtl_random_getBytes(nullptr, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); @@ -229,11 +226,10 @@ public: /* rtlRandomError */ aError = rtl_random_getBytes(aPool, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); - /* rtlRandomError */ aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError */ aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_001() @@ -241,16 +237,15 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); - rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_002() @@ -258,12 +253,12 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen << 1 ]; - memset(pBuffer, 0, nBufLen << 1); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen << 1 ] ); + memset(pBuffer.get(), 0, nBufLen << 1); CPPUNIT_ASSERT_MESSAGE("memset failed", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); - rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); printf("%2x %2x %2x %2x %2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3], pBuffer[4], pBuffer[5], pBuffer[6], pBuffer[7]); @@ -271,7 +266,6 @@ public: CPPUNIT_ASSERT_MESSAGE("internal memory overwrite", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_003() @@ -279,8 +273,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 1; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); Statistics aStat; @@ -291,7 +285,7 @@ public: int nCountMax = 1000000; for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) { - /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); /* CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); */ aStat.addValue(pBuffer[0], 1); @@ -303,7 +297,6 @@ public: CPPUNIT_ASSERT_MESSAGE("deviation should be less average", aStat.getMaxDeviation() < aStat.getAverage()); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_003_1() @@ -311,8 +304,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 256; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); Statistics aStat; @@ -323,7 +316,7 @@ public: int nCountMax = 10000; for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) { - /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); // CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); for (sal_uInt32 i=0;i<nBufLen;++i) @@ -336,7 +329,6 @@ public: CPPUNIT_ASSERT_MESSAGE("deviation should be less average", aStat.getMaxDeviation() < aStat.getAverage()); rtl_random_destroyPool(aPool); - delete [] pBuffer; } // Change the following lines only, if you add, remove or rename |