File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -203,15 +203,23 @@ void BindingData::EncodeInto(const FunctionCallbackInfo<Value>& args) {
203203 if (view.is_one_byte ()) {
204204 auto data = reinterpret_cast <const char *>(view.data8 ());
205205 simdutf::result result = simdutf::validate_ascii_with_errors (data, length);
206- // Only copy what fits in the destination
207- written = read = std::min (result.count , dest_length);
208- if (read > 0 ) {
209- memcpy (write_result, data, read);
210- write_result += read;
211- data += read;
212- length -= read;
213- dest_length -= read;
206+ written = read = result.count ;
207+
208+ // Check if ASCII portion exceeds destination size
209+ if (result.count > dest_length) {
210+ written = read = dest_length;
211+ memcpy (write_result, data, dest_length);
212+ binding_data->encode_into_results_buffer_ [0 ] = static_cast <double >(read);
213+ binding_data->encode_into_results_buffer_ [1 ] =
214+ static_cast <double >(written);
215+ return ;
214216 }
217+
218+ memcpy (write_result, data, read);
219+ write_result += read;
220+ data += read;
221+ length -= read;
222+ dest_length -= read;
215223 if (length != 0 && dest_length != 0 ) {
216224 size_t rest = findBestFit (data, length, dest_length);
217225 if (rest != 0 ) {
You can’t perform that action at this time.
0 commit comments