fix several clang-analyzer issues
This commit is contained in:
parent
f5f9f4e1a7
commit
1ca2b86ed1
|
@ -1243,6 +1243,8 @@ 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)
|
int tss_mbstowcs(ntwcs_t pwz, const_ntmbs_t pbz, size_t nBytes)
|
||||||
{
|
{
|
||||||
cDebug d("tss_mbstowcs");
|
cDebug d("tss_mbstowcs");
|
||||||
|
if (!pbz)
|
||||||
|
return 0;
|
||||||
|
|
||||||
size_t N;
|
size_t N;
|
||||||
size_t nConv;
|
size_t nConv;
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#//include <fcntl.h>
|
#//include <fcntl.h>
|
||||||
#//include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
// INCLUDES
|
// INCLUDES
|
||||||
|
|
|
@ -114,15 +114,19 @@ wc16_string::~wc16_string()
|
||||||
mpData->Release();
|
mpData->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wc16_string::operator=(const wc16_string& rhs)
|
wc16_string& wc16_string::operator=(const wc16_string& rhs)
|
||||||
{
|
{
|
||||||
if (mpData)
|
if (this != &rhs)
|
||||||
mpData->Release();
|
{
|
||||||
|
if (mpData)
|
||||||
|
mpData->Release();
|
||||||
|
|
||||||
mpData = rhs.mpData;
|
mpData = rhs.mpData;
|
||||||
|
|
||||||
if (mpData)
|
if (mpData)
|
||||||
mpData->AddRef();
|
mpData->AddRef();
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
|
|
||||||
~wc16_string();
|
~wc16_string();
|
||||||
|
|
||||||
void operator=(const wc16_string& rhs);
|
wc16_string& operator=(const wc16_string& rhs);
|
||||||
int compare(const wc16_string& rhs) const;
|
int compare(const wc16_string& rhs) const;
|
||||||
|
|
||||||
size_type length() const;
|
size_type length() const;
|
||||||
|
|
|
@ -329,7 +329,7 @@ void cIntegrityCheck::ProcessDir(cDbDataSourceIter dbIter, iFCODataSourceIter* p
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (dbIter.Done())
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -307,8 +307,11 @@ unsigned int cByteQueue::Peek(uint8_t& outByte) const
|
||||||
|
|
||||||
cByteQueue& cByteQueue::operator=(const cByteQueue& rhs)
|
cByteQueue& cByteQueue::operator=(const cByteQueue& rhs)
|
||||||
{
|
{
|
||||||
Destroy();
|
if (this != &rhs)
|
||||||
CopyFrom(rhs);
|
{
|
||||||
|
Destroy();
|
||||||
|
CopyFrom(rhs);
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,7 @@ void HashTest1()
|
||||||
cDebug d("TestHashTable()::Test1");
|
cDebug d("TestHashTable()::Test1");
|
||||||
d.TraceDetail("Entering ...\n");
|
d.TraceDetail("Entering ...\n");
|
||||||
|
|
||||||
//return val for all function calls.
|
//test data
|
||||||
bool ret = true;
|
|
||||||
|
|
||||||
//test data
|
|
||||||
TSTRING string = _T("test string");
|
TSTRING string = _T("test string");
|
||||||
TSTRING string2 = _T("another test string");
|
TSTRING string2 = _T("another test string");
|
||||||
TSTRING string3 = _T("yet another test string");
|
TSTRING string3 = _T("yet another test string");
|
||||||
|
@ -73,18 +70,16 @@ void HashTest1()
|
||||||
|
|
||||||
//Test insert and lookup.
|
//Test insert and lookup.
|
||||||
htable.Insert(string, data_ptr);
|
htable.Insert(string, data_ptr);
|
||||||
ret &= htable.Lookup(string, test_lookup);
|
TEST(htable.Lookup(string, test_lookup));
|
||||||
TEST(ret);
|
|
||||||
|
|
||||||
//Make sure value is being stored and returned correctly
|
//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);
|
d.TraceDetail("Value returned from table is %i, and should be %i.\n", *((int*)test_lookup), var);
|
||||||
TEST(*((int*)test_lookup) == var);
|
TEST(*((int*)test_lookup) == var);
|
||||||
|
|
||||||
//Check remove and lookup (lookup should fail)
|
//Check remove and lookup (lookup should fail)
|
||||||
ret &= htable.Remove(string);
|
TEST(htable.Remove(string));
|
||||||
TEST(ret);
|
TEST(!htable.Lookup(string, test_lookup));
|
||||||
ret &= !htable.Lookup(string, test_lookup);
|
|
||||||
TEST(ret);
|
|
||||||
//Has test_lookup's value changed? It shouldn't have...
|
//Has test_lookup's value changed? It shouldn't have...
|
||||||
TEST(*((int*)test_lookup) == var);
|
TEST(*((int*)test_lookup) == var);
|
||||||
|
|
||||||
|
@ -106,14 +101,17 @@ void HashTest1()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Test IsEmpty()
|
//Test IsEmpty()
|
||||||
ret &= !htable.IsEmpty();
|
|
||||||
TEST(!htable.IsEmpty());
|
TEST(!htable.IsEmpty());
|
||||||
|
|
||||||
//Test Clear(), IsEmpty()
|
//Test Clear(), IsEmpty()
|
||||||
ret &= htable.Clear();
|
|
||||||
TEST(htable.Clear());
|
TEST(htable.Clear());
|
||||||
ret &= htable.IsEmpty();
|
|
||||||
TEST(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
|
//Test the Hash table with arbitrary key
|
||||||
|
|
||||||
|
@ -158,6 +156,7 @@ void HashTest1()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTest2()
|
void HashTest2()
|
||||||
{
|
{
|
||||||
cDebug d("TestHashTable()::Test2");
|
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
|
// Constructing this class will write to a memory location
|
||||||
// offset by ALIGN_SIZE. If it chokes, you'll get a bus error
|
// 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:
|
public:
|
||||||
AlignMe();
|
AlignMe();
|
||||||
|
|
||||||
private:
|
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
|
// 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
|
// HP-UX does not play your silly alignment games, at least unless you
|
||||||
// first invoke something called "allow_unaligned_data_access()", which
|
// 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
|
#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;
|
//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
|
// can't handle it, you'll get a bus error
|
||||||
|
|
||||||
// this should choke if the CPU can't
|
// this should choke if the CPU can't
|
||||||
// handle misaligned memory access
|
// handle misaligned memory access
|
||||||
int32_t* pi = (int32_t*)&a[ALIGN_SIZE];
|
memset(a, 0, sizeof(T) + ALIGN_SIZE + 1);
|
||||||
//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;
|
|
||||||
|
|
||||||
|
T* valuePtr = (T*)&a[ALIGN_SIZE];
|
||||||
|
TEST(*valuePtr == 0);
|
||||||
|
|
||||||
// this should choke if the CPU can't
|
T value = *valuePtr; // access memory for read
|
||||||
// handle misaligned memory access
|
TEST(value == 0);
|
||||||
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.
|
|
||||||
|
|
||||||
|
*valuePtr = value; // access memory for write
|
||||||
|
TEST(*valuePtr == 0);
|
||||||
#endif
|
#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
|
// UTIL FUNCTIONS
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
|
@ -135,16 +131,18 @@ void TestAlignment()
|
||||||
|
|
||||||
// TCOUT << _T("Testing for byte alignment\n")
|
// TCOUT << _T("Testing for byte alignment\n")
|
||||||
// << _T("=========================================\n");
|
// << _T("=========================================\n");
|
||||||
|
testAlignmentForType<int64_t>();
|
||||||
|
testAlignmentForType<int32_t>();
|
||||||
|
testAlignmentForType<int16_t>();
|
||||||
|
|
||||||
AlignMe<128> a128;
|
testAlignmentForType<float>();
|
||||||
AlignMe<64> a64;
|
testAlignmentForType<double>();
|
||||||
AlignMe<32> a32;
|
testAlignmentForType<long double>();
|
||||||
AlignMe<16> a16;
|
}
|
||||||
AlignMe<8> a8;
|
|
||||||
AlignMe<4> a4;
|
|
||||||
AlignMe<2> a2;
|
|
||||||
AlignMe<1> a1;
|
|
||||||
|
|
||||||
|
|
||||||
|
void TestAlignment2()
|
||||||
|
{
|
||||||
// - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - -
|
||||||
// test a misaligned memory access -- if this
|
// test a misaligned memory access -- if this
|
||||||
// chokes, your CPU can't handle such accesses
|
// chokes, your CPU can't handle such accesses
|
||||||
|
@ -321,7 +319,8 @@ void TestPlatformDetection()
|
||||||
|
|
||||||
void RegisterSuite_Platform()
|
void RegisterSuite_Platform()
|
||||||
{
|
{
|
||||||
RegisterTest("Platform", "Alignment", TestAlignment);
|
RegisterTest("Platform", "Alignment", TestAlignment);
|
||||||
RegisterTest("Platform", "Sizes", TestSizes);
|
RegisterTest("Platform", "Alignment2", TestAlignment2);
|
||||||
|
RegisterTest("Platform", "Sizes", TestSizes);
|
||||||
RegisterTest("Platform", "PlatformDetection", TestPlatformDetection);
|
RegisterTest("Platform", "PlatformDetection", TestPlatformDetection);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue