From a5f3b3a6dab18e32ee5e7d0d79a63cec0d5d5cc5 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 3 Nov 2017 20:13:18 +0100 Subject: src: add method to compute storage in WriteWrap `WriteWrap` instances may contain extra storage space. `self_size()` returns the size of the *entire* struct, member fields as well as storage space, so it is not an accurate measure for the storage space available. Add a method `ExtraSize()` (like the existing `Extra()` for accessing the storage memory) that yields the wanted value, and use it in the HTTP2 impl to fix a crash. PR-URL: https://github.com/nodejs/node/pull/16727 Refs: https://github.com/nodejs/node/pull/16669 Reviewed-By: Anatoli Papirovski Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/stream_base-inl.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/stream_base-inl.h') diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 667c0a9ffb..e1e50802f2 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -160,6 +160,10 @@ char* WriteWrap::Extra(size_t offset) { offset; } +size_t WriteWrap::ExtraSize() const { + return storage_size_ - ROUND_UP(sizeof(*this), kAlignSize); +} + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -- cgit v1.2.3