Fixed auto_ptr<> not to be used with new[].

This commit is contained in:
Vincent Richard 2014-05-27 22:02:52 +02:00
parent b5d26604ef
commit 96f6d2389f

View File

@ -97,17 +97,13 @@ void charsetConverter_icu::convert(utility::inputStream& in, utility::outputStre
// From buffers // From buffers
byte_t cpInBuffer[16]; // stream data put here byte_t cpInBuffer[16]; // stream data put here
size_t outSize = ucnv_getMinCharSize(m_from) * sizeof(cpInBuffer) * sizeof(UChar); const size_t outSize = ucnv_getMinCharSize(m_from) * sizeof(cpInBuffer) * sizeof(UChar);
UChar* uOutBuffer = new UChar[outSize]; // Unicode chars end up here UChar uOutBuffer[outSize]; // Unicode chars end up here
// Auto delete Unicode char buffer
std::auto_ptr<UChar> cleanup(uOutBuffer);
// To buffers // To buffers
// converted (char) data end up here // converted (char) data end up here
size_t cpOutBufferSz = ucnv_getMaxCharSize(m_to) * outSize; const size_t cpOutBufferSz = ucnv_getMaxCharSize(m_to) * outSize;
char* cpOutBuffer = new char[cpOutBufferSz]; char cpOutBuffer[cpOutBufferSz];
std::auto_ptr<char> cleanupOut(cpOutBuffer);
// Set replacement chars for when converting from Unicode to codepage // Set replacement chars for when converting from Unicode to codepage
icu::UnicodeString substString(m_options.invalidSequence.c_str()); icu::UnicodeString substString(m_options.invalidSequence.c_str());
@ -257,9 +253,8 @@ void charsetFilteredOutputStream_icu::writeImpl
throw exceptions::charset_conv_error("Cannot initialize converters."); throw exceptions::charset_conv_error("Cannot initialize converters.");
// Allocate buffer for Unicode chars // Allocate buffer for Unicode chars
size_t uniSize = ucnv_getMinCharSize(m_from) * count * sizeof(UChar); const size_t uniSize = ucnv_getMinCharSize(m_from) * count * sizeof(UChar);
UChar* uniBuffer = new UChar[uniSize]; UChar uniBuffer[uniSize];
std::auto_ptr <UChar> uniCleanup(uniBuffer); // auto delete Unicode buffer
// Conversion loop // Conversion loop
UErrorCode toErr = U_ZERO_ERROR; UErrorCode toErr = U_ZERO_ERROR;
@ -287,9 +282,8 @@ void charsetFilteredOutputStream_icu::writeImpl
const size_t uniLength = uniTarget - uniBuffer; const size_t uniLength = uniTarget - uniBuffer;
// Allocate buffer for destination charset // Allocate buffer for destination charset
size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength; const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
char* cpBuffer = new char[cpSize]; char cpBuffer[cpSize];
std::auto_ptr <char> cpCleanup(cpBuffer); // auto delete CP buffer
// Convert from Unicode to destination charset // Convert from Unicode to destination charset
UErrorCode fromErr = U_ZERO_ERROR; UErrorCode fromErr = U_ZERO_ERROR;
@ -330,9 +324,8 @@ void charsetFilteredOutputStream_icu::flush()
throw exceptions::charset_conv_error("Cannot initialize converters."); throw exceptions::charset_conv_error("Cannot initialize converters.");
// Allocate buffer for Unicode chars // Allocate buffer for Unicode chars
size_t uniSize = ucnv_getMinCharSize(m_from) * 1024 * sizeof(UChar); const size_t uniSize = ucnv_getMinCharSize(m_from) * 1024 * sizeof(UChar);
UChar* uniBuffer = new UChar[uniSize]; UChar uniBuffer[uniSize];
std::auto_ptr <UChar> uniCleanup(uniBuffer); // auto delete Unicode buffer
// Conversion loop (with flushing) // Conversion loop (with flushing)
UErrorCode toErr = U_ZERO_ERROR; UErrorCode toErr = U_ZERO_ERROR;
@ -360,9 +353,8 @@ void charsetFilteredOutputStream_icu::flush()
const size_t uniLength = uniTarget - uniBuffer; const size_t uniLength = uniTarget - uniBuffer;
// Allocate buffer for destination charset // Allocate buffer for destination charset
size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength; const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
char* cpBuffer = new char[cpSize]; char cpBuffer[cpSize];
std::auto_ptr <char> cpCleanup(cpBuffer); // auto delete CP buffer
// Convert from Unicode to destination charset // Convert from Unicode to destination charset
UErrorCode fromErr = U_ZERO_ERROR; UErrorCode fromErr = U_ZERO_ERROR;