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