diff options
author | Timothy J Fontaine <tjfontaine@gmail.com> | 2014-02-05 08:50:40 -0800 |
---|---|---|
committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2014-02-08 15:31:27 -0800 |
commit | 5c832e44c3c61ad41506df0d283901aba6aea187 (patch) | |
tree | 08d45b505d04bdfd52bb38e4f52f62f6c5982cd2 /src/node_buffer.h | |
parent | 2e8bb57fe37fd75323d3e3290be7264df97fe4dc (diff) | |
download | node-new-5c832e44c3c61ad41506df0d283901aba6aea187.tar.gz |
src: refactor buffer bounds checking
Consolidate buffer bounds checking logic into Buffer namespace and use
it consistently throughout the source.
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(); |