diff --git a/src/core/codeconvert.cpp b/src/core/codeconvert.cpp index 8d4577d..9066446 100644 --- a/src/core/codeconvert.cpp +++ b/src/core/codeconvert.cpp @@ -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]; diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index 3cdca6a..ec0c34f 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -102,7 +102,7 @@ #endif #//include -#//include +#include //========================================================================= // INCLUDES diff --git a/src/core/wchar16.cpp b/src/core/wchar16.cpp index 99e2faa..b28c315 100644 --- a/src/core/wchar16.cpp +++ b/src/core/wchar16.cpp @@ -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; } diff --git a/src/core/wchar16.h b/src/core/wchar16.h index 8b5f454..8b6366a 100644 --- a/src/core/wchar16.h +++ b/src/core/wchar16.h @@ -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; diff --git a/src/tripwire/integritycheck.cpp b/src/tripwire/integritycheck.cpp index 6c78101..73b3069 100644 --- a/src/tripwire/integritycheck.cpp +++ b/src/tripwire/integritycheck.cpp @@ -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 { diff --git a/src/twcrypto/bytequeue.cpp b/src/twcrypto/bytequeue.cpp index d52c747..8c53e53 100644 --- a/src/twcrypto/bytequeue.cpp +++ b/src/twcrypto/bytequeue.cpp @@ -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; } diff --git a/src/twtest/hashtable_t.cpp b/src/twtest/hashtable_t.cpp index 7642ad7..0318ab6 100644 --- a/src/twtest/hashtable_t.cpp +++ b/src/twtest/hashtable_t.cpp @@ -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"); diff --git a/src/twtest/platform_t.cpp b/src/twtest/platform_t.cpp index 097ffd0..da1972d 100644 --- a/src/twtest/platform_t.cpp +++ b/src/twtest/platform_t.cpp @@ -62,20 +62,20 @@ template 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 class AlignMe +template 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 AlignMe::AlignMe() +template AlignMe::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 AlignMe::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 +void testAlignmentForType() +{ + AlignMe a128; + AlignMe a64; + AlignMe a32; + AlignMe a16; + AlignMe a8; + AlignMe a4; + AlignMe a2; + AlignMe a1; +} + ///////////////////////////////////////////////////////// // UTIL FUNCTIONS ///////////////////////////////////////////////////////// @@ -135,16 +131,18 @@ void TestAlignment() // TCOUT << _T("Testing for byte alignment\n") // << _T("=========================================\n"); + testAlignmentForType(); + testAlignmentForType(); + testAlignmentForType(); - 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(); + testAlignmentForType(); + testAlignmentForType(); +} + +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); }