mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
src: do not make Resize(0)’d buffers base nullptr
This fixes issues in which APIs that accept pointers created this way treat `nullptr` and a zero-length buffer differently. We already do something similar for our `Malloc()` implementation. PR-URL: https://github.com/nodejs/node/pull/26731 Fixes: https://github.com/nodejs/node/issues/26514 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
bca23f2ee7
commit
d117e41e50
1 file changed
+4
-2
+4
-2
@@ -759,8 +759,10 @@ inline AllocatedBuffer::AllocatedBuffer(Environment* env, uv_buf_t buf)
|
||||
: env_(env), buffer_(buf) {}
|
||||
|
||||
inline void AllocatedBuffer::Resize(size_t len) {
|
||||
char* new_data = env_->Reallocate(buffer_.base, buffer_.len, len);
|
||||
CHECK_IMPLIES(len > 0, new_data != nullptr);
|
||||
// The `len` check is to make sure we don't end up with `nullptr` as our base.
|
||||
char* new_data = env_->Reallocate(buffer_.base, buffer_.len,
|
||||
len > 0 ? len : 1);
|
||||
CHECK_NOT_NULL(new_data);
|
||||
buffer_ = uv_buf_init(new_data, len);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user