Issue #99: replaced C99 VLAs with dynamic array using std::vector.
This commit is contained in:
parent
d11d85b1c6
commit
f51cb846a9
@ -98,12 +98,12 @@ 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
|
||||||
const 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[outSize]; // Unicode chars end up here
|
std::vector <UChar> uOutBuffer(outSize); // Unicode chars end up here
|
||||||
|
|
||||||
// To buffers
|
// To buffers
|
||||||
// converted (char) data end up here
|
// converted (char) data end up here
|
||||||
const size_t cpOutBufferSz = ucnv_getMaxCharSize(m_to) * outSize;
|
const size_t cpOutBufferSz = ucnv_getMaxCharSize(m_to) * outSize;
|
||||||
char cpOutBuffer[cpOutBufferSz];
|
std::vector <char> cpOutBuffer(cpOutBufferSz);
|
||||||
|
|
||||||
// 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());
|
||||||
@ -130,8 +130,8 @@ void charsetConverter_icu::convert(utility::inputStream& in, utility::outputStre
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Set up target pointers
|
// Set up target pointers
|
||||||
UChar* target = uOutBuffer;
|
UChar* target = &uOutBuffer[0];
|
||||||
UChar* targetLimit = target + outSize;
|
UChar* targetLimit = &target[0] + outSize;
|
||||||
|
|
||||||
toErr = U_ZERO_ERROR;
|
toErr = U_ZERO_ERROR;
|
||||||
ucnv_toUnicode(m_from, &target, targetLimit,
|
ucnv_toUnicode(m_from, &target, targetLimit,
|
||||||
@ -142,15 +142,15 @@ void charsetConverter_icu::convert(utility::inputStream& in, utility::outputStre
|
|||||||
|
|
||||||
// The Unicode source is the buffer just written and the limit
|
// The Unicode source is the buffer just written and the limit
|
||||||
// is where the previous conversion stopped (target is moved in the conversion)
|
// is where the previous conversion stopped (target is moved in the conversion)
|
||||||
const UChar* uSource = uOutBuffer;
|
const UChar* uSource = &uOutBuffer[0];
|
||||||
UChar* uSourceLimit = target;
|
UChar* uSourceLimit = &target[0];
|
||||||
UErrorCode fromErr;
|
UErrorCode fromErr;
|
||||||
|
|
||||||
// Loop until converted chars are fully written
|
// Loop until converted chars are fully written
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char* cpTarget = &cpOutBuffer[0];
|
char* cpTarget = &cpOutBuffer[0];
|
||||||
const char* cpTargetLimit = cpOutBuffer + cpOutBufferSz;
|
const char* cpTargetLimit = &cpOutBuffer[0] + cpOutBufferSz;
|
||||||
|
|
||||||
fromErr = U_ZERO_ERROR;
|
fromErr = U_ZERO_ERROR;
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ void charsetConverter_icu::convert(utility::inputStream& in, utility::outputStre
|
|||||||
throw exceptions::charset_conv_error("[ICU] Error converting from Unicode to " + m_dest.getName());
|
throw exceptions::charset_conv_error("[ICU] Error converting from Unicode to " + m_dest.getName());
|
||||||
|
|
||||||
// Write to destination stream
|
// Write to destination stream
|
||||||
out.write(cpOutBuffer, (cpTarget - cpOutBuffer));
|
out.write(&cpOutBuffer[0], (cpTarget - &cpOutBuffer[0]));
|
||||||
|
|
||||||
} while (fromErr == U_BUFFER_OVERFLOW_ERROR);
|
} while (fromErr == U_BUFFER_OVERFLOW_ERROR);
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ void charsetFilteredOutputStream_icu::writeImpl
|
|||||||
|
|
||||||
// Allocate buffer for Unicode chars
|
// Allocate buffer for Unicode chars
|
||||||
const size_t uniSize = ucnv_getMinCharSize(m_from) * count * sizeof(UChar);
|
const size_t uniSize = ucnv_getMinCharSize(m_from) * count * sizeof(UChar);
|
||||||
UChar uniBuffer[uniSize];
|
std::vector <UChar> uniBuffer(uniSize);
|
||||||
|
|
||||||
// Conversion loop
|
// Conversion loop
|
||||||
UErrorCode toErr = U_ZERO_ERROR;
|
UErrorCode toErr = U_ZERO_ERROR;
|
||||||
@ -265,8 +265,8 @@ void charsetFilteredOutputStream_icu::writeImpl
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Convert from source charset to Unicode
|
// Convert from source charset to Unicode
|
||||||
UChar* uniTarget = uniBuffer;
|
UChar* uniTarget = &uniBuffer[0];
|
||||||
UChar* uniTargetLimit = uniBuffer + uniSize;
|
UChar* uniTargetLimit = &uniBuffer[0] + uniSize;
|
||||||
|
|
||||||
toErr = U_ZERO_ERROR;
|
toErr = U_ZERO_ERROR;
|
||||||
|
|
||||||
@ -279,22 +279,22 @@ void charsetFilteredOutputStream_icu::writeImpl
|
|||||||
("[ICU] Error converting to Unicode from '" + m_sourceCharset.getName() + "'.");
|
("[ICU] Error converting to Unicode from '" + m_sourceCharset.getName() + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t uniLength = uniTarget - uniBuffer;
|
const size_t uniLength = uniTarget - &uniBuffer[0];
|
||||||
|
|
||||||
// Allocate buffer for destination charset
|
// Allocate buffer for destination charset
|
||||||
const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
|
const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
|
||||||
char cpBuffer[cpSize];
|
std::vector <char> cpBuffer(cpSize);
|
||||||
|
|
||||||
// Convert from Unicode to destination charset
|
// Convert from Unicode to destination charset
|
||||||
UErrorCode fromErr = U_ZERO_ERROR;
|
UErrorCode fromErr = U_ZERO_ERROR;
|
||||||
|
|
||||||
const UChar* cpSource = uniBuffer;
|
const UChar* cpSource = &uniBuffer[0];
|
||||||
const UChar* cpSourceLimit = uniBuffer + uniLength;
|
const UChar* cpSourceLimit = &uniBuffer[0] + uniLength;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char* cpTarget = cpBuffer;
|
char* cpTarget = &cpBuffer[0];
|
||||||
char* cpTargetLimit = cpBuffer + cpSize;
|
char* cpTargetLimit = &cpBuffer[0] + cpSize;
|
||||||
|
|
||||||
fromErr = U_ZERO_ERROR;
|
fromErr = U_ZERO_ERROR;
|
||||||
|
|
||||||
@ -307,10 +307,10 @@ void charsetFilteredOutputStream_icu::writeImpl
|
|||||||
("[ICU] Error converting from Unicode to '" + m_destCharset.getName() + "'.");
|
("[ICU] Error converting from Unicode to '" + m_destCharset.getName() + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t cpLength = cpTarget - cpBuffer;
|
const size_t cpLength = cpTarget - &cpBuffer[0];
|
||||||
|
|
||||||
// Write successfully converted bytes
|
// Write successfully converted bytes
|
||||||
m_stream.write(cpBuffer, cpLength);
|
m_stream.write(&cpBuffer[0], cpLength);
|
||||||
|
|
||||||
} while (fromErr == U_BUFFER_OVERFLOW_ERROR);
|
} while (fromErr == U_BUFFER_OVERFLOW_ERROR);
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ void charsetFilteredOutputStream_icu::flush()
|
|||||||
|
|
||||||
// Allocate buffer for Unicode chars
|
// Allocate buffer for Unicode chars
|
||||||
const size_t uniSize = ucnv_getMinCharSize(m_from) * 1024 * sizeof(UChar);
|
const size_t uniSize = ucnv_getMinCharSize(m_from) * 1024 * sizeof(UChar);
|
||||||
UChar uniBuffer[uniSize];
|
std::vector <UChar> uniBuffer(uniSize);
|
||||||
|
|
||||||
// Conversion loop (with flushing)
|
// Conversion loop (with flushing)
|
||||||
UErrorCode toErr = U_ZERO_ERROR;
|
UErrorCode toErr = U_ZERO_ERROR;
|
||||||
@ -336,8 +336,8 @@ void charsetFilteredOutputStream_icu::flush()
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Convert from source charset to Unicode
|
// Convert from source charset to Unicode
|
||||||
UChar* uniTarget = uniBuffer;
|
UChar* uniTarget = &uniBuffer[0];
|
||||||
UChar* uniTargetLimit = uniBuffer + uniSize;
|
UChar* uniTargetLimit = &uniBuffer[0] + uniSize;
|
||||||
|
|
||||||
toErr = U_ZERO_ERROR;
|
toErr = U_ZERO_ERROR;
|
||||||
|
|
||||||
@ -350,22 +350,22 @@ void charsetFilteredOutputStream_icu::flush()
|
|||||||
("[ICU] Error converting to Unicode from '" + m_sourceCharset.getName() + "'.");
|
("[ICU] Error converting to Unicode from '" + m_sourceCharset.getName() + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t uniLength = uniTarget - uniBuffer;
|
const size_t uniLength = uniTarget - &uniBuffer[0];
|
||||||
|
|
||||||
// Allocate buffer for destination charset
|
// Allocate buffer for destination charset
|
||||||
const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
|
const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
|
||||||
char cpBuffer[cpSize];
|
std::vector <char> cpBuffer(cpSize);
|
||||||
|
|
||||||
// Convert from Unicode to destination charset
|
// Convert from Unicode to destination charset
|
||||||
UErrorCode fromErr = U_ZERO_ERROR;
|
UErrorCode fromErr = U_ZERO_ERROR;
|
||||||
|
|
||||||
const UChar* cpSource = uniBuffer;
|
const UChar* cpSource = &uniBuffer[0];
|
||||||
const UChar* cpSourceLimit = uniBuffer + uniLength;
|
const UChar* cpSourceLimit = &uniBuffer[0] + uniLength;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char* cpTarget = cpBuffer;
|
char* cpTarget = &cpBuffer[0];
|
||||||
char* cpTargetLimit = cpBuffer + cpSize;
|
char* cpTargetLimit = &cpBuffer[0] + cpSize;
|
||||||
|
|
||||||
fromErr = U_ZERO_ERROR;
|
fromErr = U_ZERO_ERROR;
|
||||||
|
|
||||||
@ -378,10 +378,10 @@ void charsetFilteredOutputStream_icu::flush()
|
|||||||
("[ICU] Error converting from Unicode to '" + m_destCharset.getName() + "'.");
|
("[ICU] Error converting from Unicode to '" + m_destCharset.getName() + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t cpLength = cpTarget - cpBuffer;
|
const size_t cpLength = cpTarget - &cpBuffer[0];
|
||||||
|
|
||||||
// Write successfully converted bytes
|
// Write successfully converted bytes
|
||||||
m_stream.write(cpBuffer, cpLength);
|
m_stream.write(&cpBuffer[0], cpLength);
|
||||||
|
|
||||||
} while (fromErr == U_BUFFER_OVERFLOW_ERROR);
|
} while (fromErr == U_BUFFER_OVERFLOW_ERROR);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user