diff --git a/bench.cpp b/bench.cpp index b0534879..cfa67531 100644 --- a/bench.cpp +++ b/bench.cpp @@ -44,64 +44,55 @@ static const byte defaultKey[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJ void OutputResultBytes(const char *name, double length, double timeTaken) { - // Coverity finding (http://stackoverflow.com/a/30968371 does not squash the finding) - std::ostringstream out; - out.copyfmt(cout); + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. + StreamState ss(cout); // Coverity finding if (length < 0.0000000001f) length = 0.000001f; if (timeTaken < 0.0000000001f) timeTaken = 0.000001f; double mbs = length / timeTaken / (1024*1024); - out << "\n" << name; -// out << "" << setprecision(3) << length / (1024*1024); - out << setiosflags(ios::fixed); -// out << "" << setprecision(3) << timeTaken; - out << "" << setprecision(0) << setiosflags(ios::fixed) << mbs; + cout << "\n" << name; +// cout << "" << setprecision(3) << length / (1024*1024); + cout << setiosflags(ios::fixed); +// cout << "" << setprecision(3) << timeTaken; + cout << "" << setprecision(0) << setiosflags(ios::fixed) << mbs; if (g_hertz) - out << "" << setprecision(1) << setiosflags(ios::fixed) << timeTaken * g_hertz / length; + cout << "" << setprecision(1) << setiosflags(ios::fixed) << timeTaken * g_hertz / length; logtotal += log(mbs); logcount++; - - cout << out.str(); } void OutputResultKeying(double iterations, double timeTaken) { - // Coverity finding (http://stackoverflow.com/a/30968371 does not squash the finding) - std::ostringstream out; - out.copyfmt(cout); + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. + StreamState ss(cout); // Coverity finding if (iterations < 0.0000000001f) iterations = 0.000001f; if (timeTaken < 0.0000000001f) timeTaken = 0.000001f; - out << "" << setprecision(3) << setiosflags(ios::fixed) << (1000*1000*timeTaken/iterations); + cout << "" << setprecision(3) << setiosflags(ios::fixed) << (1000*1000*timeTaken/iterations); if (g_hertz) - out << "" << setprecision(0) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations; - - cout << out.str(); + cout << "" << setprecision(0) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations; } void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken) { - // Coverity finding (http://stackoverflow.com/a/30968371 does not squash the finding) - std::ostringstream out; - out.copyfmt(cout); + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. + StreamState ss(cout); // Coverity finding if (!iterations) iterations++; if (timeTaken < 0.0000000001f) timeTaken = 0.000001f; - out << "\n" << name << " " << operation << (pc ? " with precomputation" : ""); - out << "" << setprecision(2) << setiosflags(ios::fixed) << (1000*timeTaken/iterations); + cout << "\n" << name << " " << operation << (pc ? " with precomputation" : ""); + cout << "" << setprecision(2) << setiosflags(ios::fixed) << (1000*timeTaken/iterations); if (g_hertz) - out << "" << setprecision(2) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations / 1000000; + cout << "" << setprecision(2) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations / 1000000; logtotal += log(iterations/timeTaken); logcount++; - - cout << out.str(); } /* diff --git a/validat1.cpp b/validat1.cpp index 952d3ccf..d2825081 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -1059,6 +1059,7 @@ bool TestRDRAND() else cout << "passed:"; + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. StreamState ss(cout); cout << std::setiosflags(std::ios::fixed) << std::setprecision(6); cout << " Maurer Randomness Test returned value " << mv << endl; @@ -1136,6 +1137,7 @@ bool TestRDSEED() else cout << "passed:"; + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. StreamState ss(cout); cout << std::setiosflags(std::ios::fixed) << std::setprecision(6); cout << " Maurer Randomness Test returned value " << mv << endl; diff --git a/validat2.cpp b/validat2.cpp index bfd85aee..db09f27f 100644 --- a/validat2.cpp +++ b/validat2.cpp @@ -80,7 +80,9 @@ bool ValidateBBS() static const byte output2[] = { 0x74,0x45,0x48,0xAE,0xAC,0xB7,0x0E,0xDF,0xAF,0xD7, 0xD5,0x0E,0x8E,0x29,0x83,0x75,0x6B,0x27,0x46,0xA1}; - + + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. + StreamState ss(cout); byte buf[20]; bbs.GenerateBlock(buf, 20); diff --git a/validat3.cpp b/validat3.cpp index fbdfcef1..3870af2a 100644 --- a/validat3.cpp +++ b/validat3.cpp @@ -377,6 +377,9 @@ bool ValidateMD5MAC() {0x18,0xe3,0x49,0xa5,0x24,0x44,0xb3,0x0e,0x5e,0xba,0x5a,0xdd,0xdc,0xd9,0xf1,0x8d}, {0xf2,0xb9,0x06,0xa5,0xb8,0x4b,0x9b,0x4b,0xbe,0x95,0xed,0x32,0x56,0x4e,0xe7,0xeb}}}; + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. + StreamState ss(cout); + byte digest[MD5MAC::DIGESTSIZE]; bool pass=true, fail; @@ -448,6 +451,9 @@ bool ValidateXMACC() {0x76,0x54,0x32,0x16,0xfb,0x0f,0xd3,0xdf,0x4c,0x4b,0xc3,0x05,0x9d,0x63,0x1e,0xba,0x25,0x2b,0xbe,0x35}, {0x76,0x54,0x32,0x17,0xc6,0xfe,0xe6,0x5f,0xb1,0x35,0x8a,0xf5,0x32,0x7a,0x80,0xbd,0xb8,0x72,0xee,0xae}}}; + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. + StreamState ss(cout); + byte digest[XMACC_MD5::DIGESTSIZE]; bool pass=true, fail; @@ -504,6 +510,9 @@ bool ValidateTTMAC() {0x54,0xba,0xc3,0x92,0xa8,0x86,0x80,0x6d,0x16,0x95,0x56,0xfc,0xbb,0x67,0x89,0xb5,0x4f,0xb3,0x64,0xfb}, {0x0c,0xed,0x2c,0x9f,0x8f,0x0d,0x9d,0x03,0x98,0x1a,0xb5,0xc8,0x18,0x4b,0xac,0x43,0xdd,0x54,0xc4,0x84}}; + // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. + StreamState ss(cout); + byte digest[TTMAC::DIGESTSIZE]; bool pass=true, fail;