summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-08-14 14:37:22 +0000
committerMike Buland <eichlan@xagasoft.com>2007-08-14 14:37:22 +0000
commitf1d6b50ac5a014a5cd87a605bd4f4e1e6342ef7d (patch)
treeba8615da5a64ea173001156a74fb1903ed6da9c6 /src
parentcd0fef04fab0229ac9bb332806342fd8ee3c8673 (diff)
downloadlibbu++-f1d6b50ac5a014a5cd87a605bd4f4e1e6342ef7d.tar.gz
libbu++-f1d6b50ac5a014a5cd87a605bd4f4e1e6342ef7d.tar.bz2
libbu++-f1d6b50ac5a014a5cd87a605bd4f4e1e6342ef7d.tar.xz
libbu++-f1d6b50ac5a014a5cd87a605bd4f4e1e6342ef7d.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/fstring.h7
-rw-r--r--src/paramproc.cpp4
-rw-r--r--src/paramproc.h4
-rw-r--r--src/unit/fstring.cpp13
4 files changed, 24 insertions, 4 deletions
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
183 */ 183 */
184 void prepend( const chr *pData ) 184 void prepend( const chr *pData )
185 { 185 {
186 if( pData == NULL )
187 return;
186 long nLen; 188 long nLen;
187 for( nLen = 0; pData[nLen] != (chr)0; nLen++ ); 189 for( nLen = 0; pData[nLen] != (chr)0; nLen++ );
188 190
@@ -261,6 +263,7 @@ namespace Bu
261 return NULL; 263 return NULL;
262 264
263 flatten(); 265 flatten();
266 pFirst->pData[nLength] = (chr)0;
264 return pFirst->pData; 267 return pFirst->pData;
265 } 268 }
266 269
@@ -274,6 +277,7 @@ namespace Bu
274 return NULL; 277 return NULL;
275 278
276 flatten(); 279 flatten();
280 pFirst->pData[nLength] = (chr)0;
277 return pFirst->pData; 281 return pFirst->pData;
278 } 282 }
279 283
@@ -287,6 +291,7 @@ namespace Bu
287 return NULL; 291 return NULL;
288 292
289 flatten(); 293 flatten();
294 pFirst->pData[nLength] = (chr)0;
290 return pFirst->pData; 295 return pFirst->pData;
291 } 296 }
292 297
@@ -300,6 +305,7 @@ namespace Bu
300 return NULL; 305 return NULL;
301 306
302 flatten(); 307 flatten();
308 pFirst->pData[nLength] = (chr)0;
303 return pFirst->pData; 309 return pFirst->pData;
304 } 310 }
305 311
@@ -416,6 +422,7 @@ namespace Bu
416 } 422 }
417 423
418 flatten(); 424 flatten();
425 pFirst->pData[nLength] = (chr)0;
419 const chr *a = pData; 426 const chr *a = pData;
420 chr *b = pFirst->pData; 427 chr *b = pFirst->pData;
421 for( long j = 0; *a!=(chr)0 || *b!=(chr)0; j++, a++, b++ ) 428 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()
11 type = vtunset; 11 type = vtunset;
12} 12}
13 13
14ptrtype( std::string, str ); 14ptrtype( Bu::FString, str );
15ptrtype( uint64_t, uint64 ); 15ptrtype( uint64_t, uint64 );
16ptrtype( uint32_t, uint32 ); 16ptrtype( uint32_t, uint32 );
17ptrtype( uint16_t, uint16 ); 17ptrtype( uint16_t, uint16 );
@@ -481,7 +481,7 @@ int Bu::ParamProc::help( int argc, char *argv[] )
481 if( (*i)->sWord.getStr() ) 481 if( (*i)->sWord.getStr() )
482 { 482 {
483 printf("--"); 483 printf("--");
484 std::string sTmp = (*i)->sWord.getStr(); 484 Bu::FString sTmp = (*i)->sWord.getStr();
485 if( (*i)->sExtra.getStr() ) 485 if( (*i)->sExtra.getStr() )
486 sTmp += (*i)->sExtra.getStr(); 486 sTmp += (*i)->sExtra.getStr();
487 printf( fmt, sTmp.c_str() ); 487 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
15 { 15 {
16 public: 16 public:
17 ParamPtr(); 17 ParamPtr();
18 ParamPtr( std::string *str ); 18 ParamPtr( Bu::FString *str );
19 ParamPtr( uint64_t *uint64 ); 19 ParamPtr( uint64_t *uint64 );
20 ParamPtr( uint32_t *uint32 ); 20 ParamPtr( uint32_t *uint32 );
21 ParamPtr( uint16_t *uint16 ); 21 ParamPtr( uint16_t *uint16 );
@@ -55,7 +55,7 @@ namespace Bu
55 int type; 55 int type;
56 union 56 union
57 { 57 {
58 std::string *str; 58 Bu::FString *str;
59 uint64_t *uint64; 59 uint64_t *uint64;
60 uint32_t *uint32; 60 uint32_t *uint32;
61 uint16_t *uint16; 61 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:
10 addTest( Unit::compare1 ); 10 addTest( Unit::compare1 );
11 addTest( Unit::compare2 ); 11 addTest( Unit::compare2 );
12 addTest( Unit::appendSingle ); 12 addTest( Unit::appendSingle );
13 addTest( Unit::shared1 );
13 } 14 }
14 15
15 virtual ~Unit() 16 virtual ~Unit()
@@ -36,6 +37,18 @@ public:
36 for( char l = 'a'; l < 'g'; l++ ) 37 for( char l = 'a'; l < 'g'; l++ )
37 b += l; 38 b += l;
38 unitTest( b == "abcdef" ); 39 unitTest( b == "abcdef" );
40 unitTest( strcmp( b.getStr(), "abcdef" ) == 0 );
41 }
42
43 void shared1()
44 {
45 Bu::FString a("Hey there");
46 Bu::FString b( a );
47 unitTest( a.getStr() == b.getStr() );
48 b += " guy";
49 unitTest( a.getStr() != b.getStr() );
50 a = b;
51 unitTest( a.getStr() == b.getStr() );
39 } 52 }
40}; 53};
41 54