* Fixed CID 1650: the "raw" buffer could be leaked.
* Automatic whitespace cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38420 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#include "UdfString.h"
|
#include "UdfString.h"
|
||||||
|
|
||||||
#include "ByteOrder.h"
|
#include <ByteOrder.h>
|
||||||
|
|
||||||
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Converts the given unicode character to utf8.
|
/*! \brief Converts the given unicode character to utf8.
|
||||||
@@ -16,8 +18,7 @@
|
|||||||
upon returning, out will point to a pointer to
|
upon returning, out will point to a pointer to
|
||||||
the fifth character in \c str.
|
the fifth character in \c str.
|
||||||
*/
|
*/
|
||||||
static
|
static void
|
||||||
void
|
|
||||||
unicode_to_utf8(uint32 c, char **out)
|
unicode_to_utf8(uint32 c, char **out)
|
||||||
{
|
{
|
||||||
char *s = *out;
|
char *s = *out;
|
||||||
@@ -50,8 +51,7 @@ unicode_to_utf8(uint32 c, char **out)
|
|||||||
\return The 4-byte unicode character, or **in if passed an
|
\return The 4-byte unicode character, or **in if passed an
|
||||||
invalid character, or 0 if passed any NULL pointers.
|
invalid character, or 0 if passed any NULL pointers.
|
||||||
*/
|
*/
|
||||||
static
|
static uint32
|
||||||
uint32
|
|
||||||
utf8_to_unicode(const char **in)
|
utf8_to_unicode(const char **in)
|
||||||
{
|
{
|
||||||
if (!in)
|
if (!in)
|
||||||
@@ -92,6 +92,9 @@ utf8_to_unicode(const char **in)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Creates an empty string object. */
|
/*! \brief Creates an empty string object. */
|
||||||
UdfString::UdfString()
|
UdfString::UdfString()
|
||||||
:
|
:
|
||||||
@@ -162,6 +165,8 @@ UdfString::SetTo(const char *utf8)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayDeleter<uint32> rawDeleter(raw);
|
||||||
|
|
||||||
const char *in = utf8;
|
const char *in = utf8;
|
||||||
uint32 rawLength = 0;
|
uint32 rawLength = 0;
|
||||||
for (uint32 i = 0; i < length && uint32(in - utf8) < length; i++, rawLength++)
|
for (uint32 i = 0; i < length && uint32(in - utf8) < length; i++, rawLength++)
|
||||||
@@ -191,7 +196,7 @@ UdfString::SetTo(const char *utf8)
|
|||||||
if (canUse8bit) {
|
if (canUse8bit) {
|
||||||
fCs0Length = rawLength + 1;
|
fCs0Length = rawLength + 1;
|
||||||
fCs0String = new(nothrow) char[fCs0Length];
|
fCs0String = new(nothrow) char[fCs0Length];
|
||||||
if (fCs0String) {
|
if (fCs0String != NULL) {
|
||||||
fCs0String[0] = '\x08'; // 8-bit compressed unicode
|
fCs0String[0] = '\x08'; // 8-bit compressed unicode
|
||||||
for (uint32 i = 0; i < rawLength; i++)
|
for (uint32 i = 0; i < rawLength; i++)
|
||||||
fCs0String[i + 1] = raw[i] % 256;
|
fCs0String[i + 1] = raw[i] % 256;
|
||||||
@@ -204,7 +209,7 @@ UdfString::SetTo(const char *utf8)
|
|||||||
} else {
|
} else {
|
||||||
fCs0Length = rawLength * 2 + 1;
|
fCs0Length = rawLength * 2 + 1;
|
||||||
fCs0String = new(nothrow) char[fCs0Length];
|
fCs0String = new(nothrow) char[fCs0Length];
|
||||||
if (fCs0String) {
|
if (fCs0String != NULL) {
|
||||||
uint32 pos = 0;
|
uint32 pos = 0;
|
||||||
fCs0String[pos++] = '\x10'; // 16-bit unicode
|
fCs0String[pos++] = '\x10'; // 16-bit unicode
|
||||||
for (uint32 i = 0; i < rawLength; i++) {
|
for (uint32 i = 0; i < rawLength; i++) {
|
||||||
@@ -222,9 +227,6 @@ UdfString::SetTo(const char *utf8)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Clean up
|
|
||||||
delete [] raw;
|
|
||||||
raw = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user