diff options
Diffstat (limited to 'src/node_buffer.h')
-rw-r--r-- | src/node_buffer.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/node_buffer.h b/src/node_buffer.h index 7b7cf8e586..cb401b3b72 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -93,6 +93,20 @@ class NODE_EXTERN Buffer: public ObjectWrap { return Buffer::Length(b->handle_); } + // This is verbose to be explicit with inline commenting + static inline bool IsWithinBounds(size_t off, size_t len, size_t max) { + // Asking to seek too far into the buffer + // check to avoid wrapping in subsequent subtraction + if (off > max) + return false; + + // Asking for more than is left over in the buffer + if (max - off < len) + return false; + + // Otherwise we're in bounds + return true; + } ~Buffer(); |