Skip to content

Commit

Permalink
Prevent memcpy(nullptr, ..., 0) call (#4736)
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Dyachenko authored and GitHub Enterprise committed May 13, 2024
1 parent 22fb795 commit d766608
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions groups/bdl/bdlbb/bdlbb_blobstreambuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,13 @@ bsl::streamsize OutBlobStreamBuf::xsputn(const char_type *source,
bsl::streamsize remainingChars = epptr() - pptr();
bsl::streamsize canCopy = bsl::min(remainingChars, numLeft);

bsl::memcpy(pptr(), source + numCopied, canCopy);
pbump(static_cast<int>(canCopy));
numCopied += canCopy;
numLeft -= canCopy;
if (canCopy > 0) {
BSLS_ASSERT(pptr());
bsl::memcpy(pptr(), source + numCopied, canCopy);
pbump(static_cast<int>(canCopy));
numCopied += canCopy;
numLeft -= canCopy;
}

if (0 < numLeft) {
if (traits_type::eof() ==
Expand Down

0 comments on commit d766608

Please sign in to comment.