Skip to content

Commit

Permalink
SERVER-85681: Fix for negative value being passed to BasicBufBuilder:…
Browse files Browse the repository at this point in the history
…… (#18357)

GitOrigin-RevId: d09e7d25846ab014a5c0ee846e89ed31f53d6b99
  • Loading branch information
binhvomongodb authored and MongoDB Bot committed Jan 25, 2024
1 parent f117e03 commit a281dc6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/mongo/bson/util/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class BasicBufBuilder {
@return point to region that was skipped. pointer may change later (on realloc), so for
immediate use only
*/
char* skip(int n) {
char* skip(size_t n) {
return grow(n);
}

Expand Down Expand Up @@ -398,7 +398,7 @@ class BasicBufBuilder {
}
void appendBuf(const void* src, size_t len) {
if (len)
memcpy(grow((int)len), src, len);
memcpy(grow(len), src, len);
}

template <class T>
Expand All @@ -407,7 +407,7 @@ class BasicBufBuilder {
}

void appendStr(StringData str, bool includeEndingNull = true) {
const int len = str.size() + (includeEndingNull ? 1 : 0);
const size_t len = str.size() + (includeEndingNull ? 1 : 0);
str.copyTo(grow(len), includeEndingNull);
}

Expand All @@ -427,9 +427,8 @@ class BasicBufBuilder {
}

/* returns the pre-grow write position */
char* grow(int by) {
invariant(by >= 0);
if (MONGO_likely(by <= _end - _nextByte)) {
char* grow(size_t by) {
if (MONGO_likely(by <= static_cast<size_t>(_end - _nextByte))) {
char* oldNextByte = _nextByte;
_nextByte += by;
return oldNextByte;
Expand Down

0 comments on commit a281dc6

Please sign in to comment.