Skip to content

Commit

Permalink
buffer: properly apply offset on fast path
Browse files Browse the repository at this point in the history
PR-URL: nodejs#54391
  • Loading branch information
ronag committed Aug 15, 2024
1 parent ccf05ef commit f0ba68b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1479,9 +1479,10 @@ uint32_t FastWriteString(Local<Value> receiver,
CHECK(offset <= dst.length());
CHECK(dst.length() - offset <= std::numeric_limits<uint32_t>::max());

max_length = std::min<uint32_t>(dst.length() - offset, max_length);
const auto size = std::min(
{static_cast<uint32_t>(dst.length() - offset), max_length, src.length});

memcpy(dst_data, src.data, max_length);
memcpy(dst_data + offset, src.data, size);

return max_length;
}
Expand Down

0 comments on commit f0ba68b

Please sign in to comment.