diff --git a/src/zstring.cpp b/src/zstring.cpp index a74edd01b..e9b41a6d7 100644 --- a/src/zstring.cpp +++ b/src/zstring.cpp @@ -66,8 +66,7 @@ FString::FString (const char *copyStr) { if (copyStr == NULL || *copyStr == '\0') { - NullString.RefCount++; - Chars = &NullString.Nothing[0]; + ResetToNull(); } else { @@ -87,8 +86,7 @@ FString::FString (char oneChar) { if (oneChar == '\0') { - NullString.RefCount++; - Chars = &NullString.Nothing[0]; + ResetToNull(); } else { @@ -220,8 +218,7 @@ FString &FString::operator = (const char *copyStr) if (copyStr == NULL || *copyStr == '\0') { Data()->Release(); - NullString.RefCount++; - Chars = &NullString.Nothing[0]; + ResetToNull(); } else { @@ -362,8 +359,7 @@ FString &FString::CopyCStrPart(const char *tail, size_t tailLen) else { Data()->Release(); - NullString.RefCount++; - Chars = &NullString.Nothing[0]; + ResetToNull(); } return *this; } @@ -373,8 +369,7 @@ void FString::Truncate(size_t newlen) if (newlen == 0) { Data()->Release(); - NullString.RefCount++; - Chars = &NullString.Nothing[0]; + ResetToNull(); } else if (newlen < Len()) { diff --git a/src/zstring.h b/src/zstring.h index cdb4dc521..e7ab098dd 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -120,7 +120,7 @@ enum ELumpNum class FString { public: - FString () : Chars(&NullString.Nothing[0]) { NullString.RefCount++; } + FString () { ResetToNull(); } // Copy constructors FString (const FString &other) { AttachToOther (other); } @@ -311,6 +311,12 @@ protected: const FStringData *Data() const { return (FStringData *)Chars - 1; } FStringData *Data() { return (FStringData *)Chars - 1; } + void ResetToNull() + { + NullString.RefCount++; + Chars = &NullString.Nothing[0]; + } + void AttachToOther (const FString &other); void AllocBuffer (size_t len); void ReallocBuffer (size_t newlen);