switch text transcoder error case
This commit is contained in:
+5
-7
@@ -84,8 +84,8 @@ string TextTranscoder::operator()(const void* src, size_t src_size) {
|
|||||||
const void* orig_src = src;
|
const void* orig_src = src;
|
||||||
deque<string> blocks;
|
deque<string> blocks;
|
||||||
while (src_size > 0) {
|
while (src_size > 0) {
|
||||||
// Assume 2x input size on average, but always allocate at least 4 bytes
|
// Assume 2x input size on average, but always allocate at least 8 bytes
|
||||||
string& block = blocks.emplace_back(max<size_t>((src_size << 2), 4), '\0');
|
string& block = blocks.emplace_back(max<size_t>((src_size << 1), 8), '\0');
|
||||||
char* dest = block.data();
|
char* dest = block.data();
|
||||||
size_t dest_size = block.size();
|
size_t dest_size = block.size();
|
||||||
size_t ret = iconv(
|
size_t ret = iconv(
|
||||||
@@ -95,11 +95,6 @@ string TextTranscoder::operator()(const void* src, size_t src_size) {
|
|||||||
reinterpret_cast<char**>(&dest),
|
reinterpret_cast<char**>(&dest),
|
||||||
&dest_size);
|
&dest_size);
|
||||||
block.resize(block.size() - dest_size);
|
block.resize(block.size() - dest_size);
|
||||||
if (block.size() == 0) {
|
|
||||||
// This should never happen because no character should be more than 4
|
|
||||||
// bytes long in any known encoding
|
|
||||||
throw runtime_error("block size too small for conversion");
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t bytes_read = reinterpret_cast<const char*>(src) - reinterpret_cast<const char*>(orig_src);
|
size_t bytes_read = reinterpret_cast<const char*>(src) - reinterpret_cast<const char*>(orig_src);
|
||||||
if (ret == this->FAILURE_RESULT) {
|
if (ret == this->FAILURE_RESULT) {
|
||||||
@@ -114,6 +109,9 @@ string TextTranscoder::operator()(const void* src, size_t src_size) {
|
|||||||
throw runtime_error("transcoding failed: " + string_for_error(errno));
|
throw runtime_error("transcoding failed: " + string_for_error(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((bytes_read == 0) && (src_size != 0)) {
|
||||||
|
throw runtime_error("failed to transcode input data");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return join(blocks, "");
|
return join(blocks, "");
|
||||||
|
|||||||
Reference in New Issue
Block a user