diff --git a/src/add-ons/kernel/file_systems/udf/DString.cpp b/src/add-ons/kernel/file_systems/udf/DString.cpp index cf914acbbd..cdb867d1d0 100644 --- a/src/add-ons/kernel/file_systems/udf/DString.cpp +++ b/src/add-ons/kernel/file_systems/udf/DString.cpp @@ -3,10 +3,12 @@ * Distributed under the terms of the MIT License. */ + #include "DString.h" #include + /*! \brief Creates a useless, empty string object. */ DString::DString() : @@ -51,13 +53,19 @@ DString::DString(const char *utf8, uint8 fieldLength) } +DString::~DString() +{ + delete[] fString; +} + + void DString::SetTo(const DString &ref) { _Clear(); if (ref.Length() > 0) { fString = new(nothrow) uint8[ref.Length()]; - if (fString) { + if (fString != NULL) { fLength = ref.Length(); memcpy(fString, ref.String(), fLength); } @@ -94,7 +102,7 @@ DString::SetTo(const UdfString &string, uint8 fieldLength) if (destLength < fieldLength - 1) memset(&fString[destLength], 0, fieldLength - 1 - destLength); // Write the string length to the last character in the field - fString[fieldLength - 1] = destLength; + fString[fieldLength - 1] = destLength; } else { // Empty strings are to contain all zeros memset(fString, 0, fieldLength); @@ -120,7 +128,7 @@ void DString::_Clear() { DEBUG_INIT("DString"); - delete [] fString; + delete[] fString; fString = NULL; fLength = 0; } diff --git a/src/add-ons/kernel/file_systems/udf/DString.h b/src/add-ons/kernel/file_systems/udf/DString.h index f8ae1f037b..94f6718663 100644 --- a/src/add-ons/kernel/file_systems/udf/DString.h +++ b/src/add-ons/kernel/file_systems/udf/DString.h @@ -2,16 +2,17 @@ * Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net. * Distributed under the terms of the MIT License. */ - #ifndef _D_STRING_H #define _D_STRING_H + #include "UdfDebug.h" #include "UdfString.h" #include + /*! \brief Fixed-length d-string class that takes a UdfString as input and provides a properly formatted ECMA-167 d-string of the given field length as ouput. @@ -20,23 +21,28 @@ */ class DString { public: - DString(); - DString(const DString &ref); - DString(const UdfString &string, uint8 fieldLength); - DString(const char *utf8, uint8 fieldLength); + DString(); + DString(const DString &ref); + DString(const UdfString &string, + uint8 fieldLength); + DString(const char *utf8, uint8 fieldLength); + ~DString(); - uint8 Length() const { return fLength; } + uint8 Length() const { return fLength; } - void SetTo(const DString &ref); - void SetTo(const UdfString &string, uint8 fieldLength); - void SetTo(const char *utf8, uint8 fieldLength); + void SetTo(const DString &ref); + void SetTo(const UdfString &string, uint8 fieldLength); + void SetTo(const char *utf8, uint8 fieldLength); + + const uint8* String() const { return fString; } - const uint8* String() const { return fString; } private: - void _Clear(); + void _Clear(); - uint8 fLength; - uint8 *fString; +private: + uint8 fLength; + uint8 *fString; }; + #endif // _D_STRING_H