Finally figured how how to clear than damn Coverity finding on STREAM_FORMAT_STATE

pull/96/head
Jeffrey Walton 2015-12-29 07:16:44 -05:00
parent 9e4e210834
commit 51d674c7d8
2 changed files with 35 additions and 14 deletions

View File

@ -468,7 +468,7 @@ bool TestSecBlock()
cout << "passed:"; cout << "passed:";
cout << " Append word32" << endl; cout << " Append word32" << endl;
//********** Append **********// //********** Concatenate **********//
try try
{ {
@ -555,7 +555,7 @@ bool TestSecBlock()
a.Assign(str1, COUNTOF(str1)); a.Assign(str1, COUNTOF(str1));
b.Assign(str1, COUNTOF(str1)); b.Assign(str1, COUNTOF(str1));
temp &= (a == b); temp &= (a.operator==(b));
a.Assign(str3, COUNTOF(str3)); a.Assign(str3, COUNTOF(str3));
b.Assign(str3, COUNTOF(str3)); b.Assign(str3, COUNTOF(str3));
@ -592,7 +592,7 @@ bool TestSecBlock()
a.Assign(str1, COUNTOF(str1)); a.Assign(str1, COUNTOF(str1));
b.Assign(str1, COUNTOF(str1)); b.Assign(str1, COUNTOF(str1));
temp &= (a == b); temp &= (a.operator==(b));
a.Assign(str3, COUNTOF(str3)); a.Assign(str3, COUNTOF(str3));
b.Assign(str3, COUNTOF(str3)); b.Assign(str3, COUNTOF(str3));
@ -861,12 +861,10 @@ bool TestRDRAND()
} }
else else
cout << "passed:"; cout << "passed:";
const std::streamsize oldp = cout.precision(6); StreamState ss(cout);
const std::ios::fmtflags oldf = cout.setf(std::ios::fixed, std::ios::floatfield); cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
cout << " Maurer Randomness Test returned value " << mv << endl; cout << " Maurer Randomness Test returned value " << mv << endl;
cout.precision(oldp);
cout.setf(oldf, std::ios::floatfield);
if (meter.GetTotalBytes() < SIZE) if (meter.GetTotalBytes() < SIZE)
{ {
@ -934,12 +932,10 @@ bool TestRDSEED()
} }
else else
cout << "passed:"; cout << "passed:";
const std::streamsize oldp = cout.precision(6); StreamState ss(cout);
const std::ios::fmtflags oldf = cout.setf(std::ios::fixed, std::ios::floatfield); cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
cout << " Maurer Randomness Test returned value " << mv << endl; cout << " Maurer Randomness Test returned value " << mv << endl;
cout.precision(oldp);
cout.setf(oldf, std::ios::floatfield);
if (meter.GetTotalBytes() < SIZE) if (meter.GetTotalBytes() < SIZE)
{ {

View File

@ -2,6 +2,8 @@
#define CRYPTOPP_VALIDATE_H #define CRYPTOPP_VALIDATE_H
#include "cryptlib.h" #include "cryptlib.h"
#include <iostream>
#include <iomanip>
bool ValidateAll(bool thorough); bool ValidateAll(bool thorough);
bool TestSettings(); bool TestSettings();
@ -87,12 +89,35 @@ bool TestSecBlock();
bool TestPolynomialMod2(); bool TestPolynomialMod2();
#endif #endif
// Coverity findings // Coverity finding
template <class T, bool NON_NEGATIVE> template <class T, bool NON_NEGATIVE>
T StringToValue(const std::string& str); T StringToValue(const std::string& str);
// Coverity finding
template<> template<>
int StringToValue<int, true>(const std::string& str); int StringToValue<int, true>(const std::string& str);
// Coverity finding
class StreamState
{
public:
StreamState(std::ostream& out)
: m_out(out), m_fmt(out.flags()), m_prec(out.precision())
{
}
~StreamState()
{
m_out.precision(m_prec);
m_out.flags(m_fmt);
}
private:
std::ostream& m_out;
std::ios_base::fmtflags m_fmt;
std::streamsize m_prec;
};
// Functions that need a RNG; uses AES inf CFB mode with Seed. // Functions that need a RNG; uses AES inf CFB mode with Seed.
CryptoPP::RandomNumberGenerator & GlobalRNG(); CryptoPP::RandomNumberGenerator & GlobalRNG();