fix several clang-analyzer issues
This commit is contained in:
parent
f5f9f4e1a7
commit
1ca2b86ed1
|
@ -1243,7 +1243,9 @@ int tss_wcstombs(ntmbs_t pbz, const_ntwcs_t pwz, size_t nCount)
|
|||
int tss_mbstowcs(ntwcs_t pwz, const_ntmbs_t pbz, size_t nBytes)
|
||||
{
|
||||
cDebug d("tss_mbstowcs");
|
||||
|
||||
if (!pbz)
|
||||
return 0;
|
||||
|
||||
size_t N;
|
||||
size_t nConv;
|
||||
const_ntmbs_t end = &pbz[nBytes];
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
#endif
|
||||
|
||||
#//include <fcntl.h>
|
||||
#//include <errno.h>
|
||||
#include <errno.h>
|
||||
|
||||
//=========================================================================
|
||||
// INCLUDES
|
||||
|
|
|
@ -114,15 +114,19 @@ wc16_string::~wc16_string()
|
|||
mpData->Release();
|
||||
}
|
||||
|
||||
void wc16_string::operator=(const wc16_string& rhs)
|
||||
wc16_string& wc16_string::operator=(const wc16_string& rhs)
|
||||
{
|
||||
if (mpData)
|
||||
mpData->Release();
|
||||
if (this != &rhs)
|
||||
{
|
||||
if (mpData)
|
||||
mpData->Release();
|
||||
|
||||
mpData = rhs.mpData;
|
||||
mpData = rhs.mpData;
|
||||
|
||||
if (mpData)
|
||||
mpData->AddRef();
|
||||
if (mpData)
|
||||
mpData->AddRef();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
|
||||
~wc16_string();
|
||||
|
||||
void operator=(const wc16_string& rhs);
|
||||
wc16_string& operator=(const wc16_string& rhs);
|
||||
int compare(const wc16_string& rhs) const;
|
||||
|
||||
size_type length() const;
|
||||
|
|
|
@ -329,7 +329,7 @@ void cIntegrityCheck::ProcessDir(cDbDataSourceIter dbIter, iFCODataSourceIter* p
|
|||
#ifdef DEBUG
|
||||
if (dbIter.Done())
|
||||
{
|
||||
d.TraceDebug("Processing directory %s\n", pIter->GetParentName().AsString().c_str());
|
||||
d.TraceDebug("Processing directory %s\n", (pIter ? pIter->GetParentName().AsString().c_str() : _T("[none]")));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -307,8 +307,11 @@ unsigned int cByteQueue::Peek(uint8_t& outByte) const
|
|||
|
||||
cByteQueue& cByteQueue::operator=(const cByteQueue& rhs)
|
||||
{
|
||||
Destroy();
|
||||
CopyFrom(rhs);
|
||||
if (this != &rhs)
|
||||
{
|
||||
Destroy();
|
||||
CopyFrom(rhs);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,10 +51,7 @@ void HashTest1()
|
|||
cDebug d("TestHashTable()::Test1");
|
||||
d.TraceDetail("Entering ...\n");
|
||||
|
||||
//return val for all function calls.
|
||||
bool ret = true;
|
||||
|
||||
//test data
|
||||
//test data
|
||||
TSTRING string = _T("test string");
|
||||
TSTRING string2 = _T("another test string");
|
||||
TSTRING string3 = _T("yet another test string");
|
||||
|
@ -73,18 +70,16 @@ void HashTest1()
|
|||
|
||||
//Test insert and lookup.
|
||||
htable.Insert(string, data_ptr);
|
||||
ret &= htable.Lookup(string, test_lookup);
|
||||
TEST(ret);
|
||||
TEST(htable.Lookup(string, test_lookup));
|
||||
|
||||
//Make sure value is being stored and returned correctly
|
||||
d.TraceDetail("Value returned from table is %i, and should be %i.\n", *((int*)test_lookup), var);
|
||||
TEST(*((int*)test_lookup) == var);
|
||||
|
||||
//Check remove and lookup (lookup should fail)
|
||||
ret &= htable.Remove(string);
|
||||
TEST(ret);
|
||||
ret &= !htable.Lookup(string, test_lookup);
|
||||
TEST(ret);
|
||||
TEST(htable.Remove(string));
|
||||
TEST(!htable.Lookup(string, test_lookup));
|
||||
|
||||
//Has test_lookup's value changed? It shouldn't have...
|
||||
TEST(*((int*)test_lookup) == var);
|
||||
|
||||
|
@ -106,14 +101,17 @@ void HashTest1()
|
|||
#endif
|
||||
|
||||
//Test IsEmpty()
|
||||
ret &= !htable.IsEmpty();
|
||||
TEST(!htable.IsEmpty());
|
||||
|
||||
//Test Clear(), IsEmpty()
|
||||
ret &= htable.Clear();
|
||||
TEST(htable.Clear());
|
||||
ret &= htable.IsEmpty();
|
||||
TEST(htable.IsEmpty());
|
||||
}
|
||||
|
||||
|
||||
// TODO: Turn this into a working, useful test, or remove it.
|
||||
void HashTest3()
|
||||
{
|
||||
/*
|
||||
//Test the Hash table with arbitrary key
|
||||
|
||||
|
@ -158,6 +156,7 @@ void HashTest1()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
void HashTest2()
|
||||
{
|
||||
cDebug d("TestHashTable()::Test2");
|
||||
|
|
|
@ -62,20 +62,20 @@ template<class E, class T> bool CanBeRepresentedAs(E e, T t);
|
|||
|
||||
// Constructing this class will write to a memory location
|
||||
// offset by ALIGN_SIZE. If it chokes, you'll get a bus error
|
||||
template<int ALIGN_SIZE> class AlignMe
|
||||
template<class T, int ALIGN_SIZE> class AlignMe
|
||||
{
|
||||
public:
|
||||
AlignMe();
|
||||
|
||||
private:
|
||||
uint8_t a[sizeof(int64_t) + ALIGN_SIZE]; // we want to be able to access a int64_t at address [ALIGN_SIZE]
|
||||
uint8_t a[sizeof(T) + ALIGN_SIZE + 1]; // we want to be able to access a T at address [ALIGN_SIZE]
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// TEMPLATIZED UTIL CLASSES IMPLEMENTATIONS
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
template<int ALIGN_SIZE> AlignMe<ALIGN_SIZE>::AlignMe()
|
||||
template<class T, int ALIGN_SIZE> AlignMe<T, ALIGN_SIZE>::AlignMe()
|
||||
{
|
||||
// HP-UX does not play your silly alignment games, at least unless you
|
||||
// first invoke something called "allow_unaligned_data_access()", which
|
||||
|
@ -86,42 +86,38 @@ template<int ALIGN_SIZE> AlignMe<ALIGN_SIZE>::AlignMe()
|
|||
#if (!IS_HPUX && !IS_SOLARIS) //Turns out Solaris SPARC is unhappy with this test too, btw
|
||||
//TCOUT << _T("Testing alignment of size ") << ALIGN_SIZE << std::endl;
|
||||
|
||||
// access a double in the byte array to see if it is aligned. if it isn't and the CPU
|
||||
// access a value in the byte array to see if it is aligned. if it isn't and the CPU
|
||||
// can't handle it, you'll get a bus error
|
||||
|
||||
// this should choke if the CPU can't
|
||||
// handle misaligned memory access
|
||||
int32_t* pi = (int32_t*)&a[ALIGN_SIZE];
|
||||
//TCOUT << _T("Testing alignment of an int32...") << std::endl;
|
||||
//TCOUT << _T("Reading...") << std::endl;
|
||||
int32_t i = *pi; // access memory for read
|
||||
//TCOUT << _T("Read succeeded.") << std::endl;
|
||||
//TCOUT << _T("Writing...") << std::endl;
|
||||
*pi = i; // access memory for write
|
||||
TCOUT << _T("Write succeeded.") << std::endl;
|
||||
|
||||
|
||||
// this should choke if the CPU can't
|
||||
// handle misaligned memory access
|
||||
int64_t* pb = (int64_t*)&a[ALIGN_SIZE];
|
||||
//TCOUT << _T("Testing alignment of an int64...") << std::endl;
|
||||
//TCOUT << _T("Reading...") << std::endl;
|
||||
int64_t I = *pb; // access memory for read
|
||||
//TCOUT << _T("Read succeeded") << std::endl;
|
||||
//TCOUT << _T("Writing...") << std::endl;
|
||||
*pb = I; // access memory for write
|
||||
//TCOUT << _T("Write succeeded.") << std::endl;
|
||||
|
||||
|
||||
/*TCOUT << _T("Alignment of ") << ALIGN_SIZE << _T(" ") << ( ALIGN_SIZE == 1 ? _T("byte") : _T("bytes") ) << _T(" is OK") << std::endl
|
||||
<< _T("=========================================\n"); */
|
||||
|
||||
TEST("Aligned"); // The actual test is not bus erroring up above; this just tells the framework we tested something.
|
||||
|
||||
memset(a, 0, sizeof(T) + ALIGN_SIZE + 1);
|
||||
|
||||
T* valuePtr = (T*)&a[ALIGN_SIZE];
|
||||
TEST(*valuePtr == 0);
|
||||
|
||||
T value = *valuePtr; // access memory for read
|
||||
TEST(value == 0);
|
||||
|
||||
*valuePtr = value; // access memory for write
|
||||
TEST(*valuePtr == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void testAlignmentForType()
|
||||
{
|
||||
AlignMe<T, 128> a128;
|
||||
AlignMe<T, 64> a64;
|
||||
AlignMe<T, 32> a32;
|
||||
AlignMe<T, 16> a16;
|
||||
AlignMe<T, 8> a8;
|
||||
AlignMe<T, 4> a4;
|
||||
AlignMe<T, 2> a2;
|
||||
AlignMe<T, 1> a1;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// UTIL FUNCTIONS
|
||||
/////////////////////////////////////////////////////////
|
||||
|
@ -135,16 +131,18 @@ void TestAlignment()
|
|||
|
||||
// TCOUT << _T("Testing for byte alignment\n")
|
||||
// << _T("=========================================\n");
|
||||
testAlignmentForType<int64_t>();
|
||||
testAlignmentForType<int32_t>();
|
||||
testAlignmentForType<int16_t>();
|
||||
|
||||
AlignMe<128> a128;
|
||||
AlignMe<64> a64;
|
||||
AlignMe<32> a32;
|
||||
AlignMe<16> a16;
|
||||
AlignMe<8> a8;
|
||||
AlignMe<4> a4;
|
||||
AlignMe<2> a2;
|
||||
AlignMe<1> a1;
|
||||
testAlignmentForType<float>();
|
||||
testAlignmentForType<double>();
|
||||
testAlignmentForType<long double>();
|
||||
}
|
||||
|
||||
|
||||
void TestAlignment2()
|
||||
{
|
||||
// - - - - - - - - - - - - - - - - - - - - - -
|
||||
// test a misaligned memory access -- if this
|
||||
// chokes, your CPU can't handle such accesses
|
||||
|
@ -321,7 +319,8 @@ void TestPlatformDetection()
|
|||
|
||||
void RegisterSuite_Platform()
|
||||
{
|
||||
RegisterTest("Platform", "Alignment", TestAlignment);
|
||||
RegisterTest("Platform", "Sizes", TestSizes);
|
||||
RegisterTest("Platform", "Alignment", TestAlignment);
|
||||
RegisterTest("Platform", "Alignment2", TestAlignment2);
|
||||
RegisterTest("Platform", "Sizes", TestSizes);
|
||||
RegisterTest("Platform", "PlatformDetection", TestPlatformDetection);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue