From f1d6b50ac5a014a5cd87a605bd4f4e1e6342ef7d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 14 Aug 2007 14:37:22 +0000 Subject: Fixed a crash in the FString::prepend function on a null string corner case. Also added more tests to the FString unit tests and switched the ParamProc to using FString instead of std::string, this will break a few programs in very minor ways, a few seconds each to fix, I'd say. --- src/fstring.h | 7 +++++++ src/paramproc.cpp | 4 ++-- src/paramproc.h | 4 ++-- src/unit/fstring.cpp | 13 +++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/fstring.h b/src/fstring.h index 3cf42ef..63e1e1a 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -183,6 +183,8 @@ namespace Bu */ void prepend( const chr *pData ) { + if( pData == NULL ) + return; long nLen; for( nLen = 0; pData[nLen] != (chr)0; nLen++ ); @@ -261,6 +263,7 @@ namespace Bu return NULL; flatten(); + pFirst->pData[nLength] = (chr)0; return pFirst->pData; } @@ -274,6 +277,7 @@ namespace Bu return NULL; flatten(); + pFirst->pData[nLength] = (chr)0; return pFirst->pData; } @@ -287,6 +291,7 @@ namespace Bu return NULL; flatten(); + pFirst->pData[nLength] = (chr)0; return pFirst->pData; } @@ -300,6 +305,7 @@ namespace Bu return NULL; flatten(); + pFirst->pData[nLength] = (chr)0; return pFirst->pData; } @@ -416,6 +422,7 @@ namespace Bu } flatten(); + pFirst->pData[nLength] = (chr)0; const chr *a = pData; chr *b = pFirst->pData; for( long j = 0; *a!=(chr)0 || *b!=(chr)0; j++, a++, b++ ) diff --git a/src/paramproc.cpp b/src/paramproc.cpp index 34e973e..67ef44b 100644 --- a/src/paramproc.cpp +++ b/src/paramproc.cpp @@ -11,7 +11,7 @@ Bu::ParamProc::ParamPtr::ParamPtr() type = vtunset; } -ptrtype( std::string, str ); +ptrtype( Bu::FString, str ); ptrtype( uint64_t, uint64 ); ptrtype( uint32_t, uint32 ); ptrtype( uint16_t, uint16 ); @@ -481,7 +481,7 @@ int Bu::ParamProc::help( int argc, char *argv[] ) if( (*i)->sWord.getStr() ) { printf("--"); - std::string sTmp = (*i)->sWord.getStr(); + Bu::FString sTmp = (*i)->sWord.getStr(); if( (*i)->sExtra.getStr() ) sTmp += (*i)->sExtra.getStr(); printf( fmt, sTmp.c_str() ); diff --git a/src/paramproc.h b/src/paramproc.h index 2bca588..a48de5d 100644 --- a/src/paramproc.h +++ b/src/paramproc.h @@ -15,7 +15,7 @@ namespace Bu { public: ParamPtr(); - ParamPtr( std::string *str ); + ParamPtr( Bu::FString *str ); ParamPtr( uint64_t *uint64 ); ParamPtr( uint32_t *uint32 ); ParamPtr( uint16_t *uint16 ); @@ -55,7 +55,7 @@ namespace Bu int type; union { - std::string *str; + Bu::FString *str; uint64_t *uint64; uint32_t *uint32; uint16_t *uint16; diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp index 462ce5e..2044a86 100644 --- a/src/unit/fstring.cpp +++ b/src/unit/fstring.cpp @@ -10,6 +10,7 @@ public: addTest( Unit::compare1 ); addTest( Unit::compare2 ); addTest( Unit::appendSingle ); + addTest( Unit::shared1 ); } virtual ~Unit() @@ -36,6 +37,18 @@ public: for( char l = 'a'; l < 'g'; l++ ) b += l; unitTest( b == "abcdef" ); + unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); + } + + void shared1() + { + Bu::FString a("Hey there"); + Bu::FString b( a ); + unitTest( a.getStr() == b.getStr() ); + b += " guy"; + unitTest( a.getStr() != b.getStr() ); + a = b; + unitTest( a.getStr() == b.getStr() ); } }; -- cgit v1.2.3