aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjackpoz <giacomopoz@gmail.com>2014-05-18 00:51:40 +0200
committerjackpoz <giacomopoz@gmail.com>2014-05-18 00:51:40 +0200
commit5e86dea0b06566bc643018fe8cc026d0dd24ad79 (patch)
tree619942481ce6e2c29529d80671c0fe46065e504c /src
parentc200d2c8cc360d2cc8eb4fc2630dbac32e53a649 (diff)
Shared/Packets: Handle crash by throwing an exception instead
Throw a ByteBufferException when trying to access the first element of an empty ByteBuffer class
Diffstat (limited to 'src')
-rw-r--r--src/server/shared/Packets/ByteBuffer.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index bc46b87fa27..dd0a9d5fdf4 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -377,9 +377,19 @@ class ByteBuffer
return *this;
}
- uint8 * contents() { return &_storage[0]; }
+ uint8 * contents()
+ {
+ if (_storage.empty())
+ throw ByteBufferException();
+ return &_storage[0];
+ }
- const uint8 *contents() const { return &_storage[0]; }
+ const uint8 *contents() const
+ {
+ if (_storage.empty())
+ throw ByteBufferException();
+ return &_storage[0];
+ }
size_t size() const { return _storage.size(); }
bool empty() const { return _storage.empty(); }