aboutsummaryrefslogtreecommitdiff
path: root/ByteBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ByteBuffer.cpp')
-rw-r--r--ByteBuffer.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/ByteBuffer.cpp b/ByteBuffer.cpp
index 2b2f33b..2d4a258 100644
--- a/ByteBuffer.cpp
+++ b/ByteBuffer.cpp
@@ -2,14 +2,11 @@
#include <string.h>
#include <sstream>
#include <iomanip>
-#include <cassert>
-#include <elf.h>
-#include <stdint-gcc.h>
using namespace std;
ByteBuffer::ByteBuffer(const uint8_t *bytes, size_t capacity) :
- bytes(bytes), capacity(capacity), zero(&bytes[0]), end(&bytes[0]) {
+ bytes(bytes), capacity(capacity), zero(&bytes[0]), end(&bytes[capacity]) {
ptr = (uint8_t *) &bytes[0];
}
@@ -78,10 +75,9 @@ ByteBuffer ByteBuffer::view(uint8_t *ptr, const uint8_t *end) const {
void ByteBuffer::checkAndUpdateEnd(size_t newBytes) {
uint8_t *newPtr = ptr + newBytes;
if (newPtr >= end) {
- throw ByteBufferException(string("New size is too large! cursor=") + to_string(getCursor()) + ", size=" + to_string(getSize()) + ", capacity=" + to_string(capacity));
- }
-
- if (newPtr > end) {
+ if (newPtr >= &zero[capacity]) {
+ throw ByteBufferException(string("New size is too large! cursor=") + to_string(getCursor()) + ", size=" + to_string(getSize()) + ", capacity=" + to_string(capacity));
+ }
end = newPtr;
}
}