From fdc5e8760fb7ac0af8e7ebb98a2076db15e31082 Mon Sep 17 00:00:00 2001 From: aura Date: Mon, 16 Mar 2026 10:15:01 +0100 Subject: giga refactor, fix ALL the leaks --- src/util/string.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/util/string.h') diff --git a/src/util/string.h b/src/util/string.h index 6d44b53..7dfab69 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -54,23 +54,19 @@ struct ARRSTR { template struct __str : public LIST { __str() : LIST() {} - __str( U32 count, const CT* str ) { - this->data = 0; - this->capacity = this->size = 0; + __str( U32 count, const CT* str ) : LIST() { this->reserve( count * 2 ); memcpy( this->data, str, count ); this->size = count; this->data[this->size] = 0; } - __str( const CT* fmt, ... ) { + __str( const CT* fmt, ... ) : LIST() { va_list args; va_start( args, fmt ); va_list args2; va_copy( args2, args ); U32 c = vsnprintf( 0, 0, fmt, args ); va_end( args ); - this->data = 0; - this->capacity = this->size = 0; this->reserve( c * 2 ); vsnprintf( this->data, c + 1, fmt, args2 ); this->data[c] = 0; @@ -89,8 +85,6 @@ struct __str : public LIST { if( this->data && this->data != other.data ) free( this->data ); - this->data = 0; - if( !other.capacity || !other.size ) { this->capacity = 1; this->size = 0; @@ -116,8 +110,9 @@ struct __str : public LIST { __str operator+( const CT rhs ) { __str ret = *this; ret.push( rhs ); return ret; } __str& operator+=( const __str& rhs ) { return this->append( rhs ); } __str& operator+=( const CT* rhs ) { return this->append( rhs ); } - __str& operator+=( const CT rhs ) { this->push( rhs ); return this; } + __str& operator+=( const CT rhs ) { this->push( rhs ); return *this; } + operator const CT*() { return this->data; } operator CT*() { return this->data; } CT operator[]( U32 i ) { @@ -128,10 +123,8 @@ struct __str : public LIST { if( rhs.size != this->size ) return 0; - for( U32 i = 0; i < this->size; ++i ) { - if( this->data[i] != rhs.data[i] ) - return 0; - } + if( !!memcmp( this->data, rhs.data, this->size ) ) + return 0; return 1; } @@ -165,7 +158,7 @@ struct __str : public LIST { __str& append( const CT* str ) { U32 len; for( len = 0; !!str[len]; ++len ); - if( this->size + len + 1 > this->capacity ) + if( this->size + len + 1 >= this->capacity ) this->reserve( this->size + len + 1 ); memcpy( this->data + this->size, str, len * sizeof(CT) ); @@ -179,7 +172,7 @@ struct __str : public LIST { if( this->size + len + 1 >= this->capacity ) this->reserve( this->size + len + 1 ); - memcpy( this->data + this->size, str, len * sizeof(CT) ); + memcpy( this->data + this->size, str.data, len * sizeof(CT) ); this->size += len; this->data[this->size] = 0; return *this; -- cgit v1.2.3