| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eb74125 commit 03be967
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -442,11 +442,24 @@ void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) { | |||
| 442 | 442 | UErrorCode status = U_ZERO_ERROR; | |
| 443 | 443 | MaybeStackBuffer<UChar> result; | |
| 444 | 444 | MaybeLocal<Object> ret; | |
| 445 | - size_t limit = converter->min_char_size() * input.length(); | ||
| 445 | + | ||
| 446 | + UBool flush = (flags & CONVERTER_FLAGS_FLUSH) == CONVERTER_FLAGS_FLUSH; | ||
| 447 | + | ||
| 448 | + // When flushing the final chunk, the limit is the maximum | ||
| 449 | + // of either the input buffer length or the number of pending | ||
| 450 | + // characters times the min char size. | ||
| 451 | + size_t limit = converter->min_char_size() * | ||
| 452 | + (!flush ? | ||
| 453 | + input.length() : | ||
| 454 | + std::max( | ||
| 455 | + input.length(), | ||
| 456 | + static_cast<size_t>( | ||
| 457 | + ucnv_toUCountPending(converter->conv(), &status)))); | ||
| 458 | + status = U_ZERO_ERROR; | ||
| 459 | + | ||
| 446 | 460 | if (limit > 0) | |
| 447 | 461 | result.AllocateSufficientStorage(limit); | |
| 448 | 462 | ||
| 449 | - UBool flush = (flags & CONVERTER_FLAGS_FLUSH) == CONVERTER_FLAGS_FLUSH; | ||
| 450 | 463 | auto cleanup = OnScopeLeave([&]() { | |
| 451 | 464 | if (flush) { | |
| 452 | 465 | // Reset the converter state. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments