Skip to content

Commit

Permalink
backend/outbuf: Add bounds checks (in DEBUG builds)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Sep 13, 2015
1 parent 381e65f commit d537ec8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/backend/outbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ char *Outbuffer::toString()
void Outbuffer::setsize(size_t size)
{
p = buf + size;

#ifdef DEBUG
assert(p <= pend); // Attempting to seek past end of buffer
#endif
}

void Outbuffer::writesLEB128(int value)
Expand Down
8 changes: 8 additions & 0 deletions src/backend/outbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#include <string.h>

#ifdef DEBUG
#include <assert.h>
#endif

// Output buffer

// (This used to be called OutBuffer, we renamed it to avoid name conflicts with Mars.)
Expand Down Expand Up @@ -40,6 +44,10 @@ struct Outbuffer
// Reserve nbytes in buffer
void reserve(size_t nbytes)
{
#ifdef DEBUG
assert(buf <= p && p <= pend); // Wrote past the end of the buffer!
#endif

if (pend - p < nbytes)
enlarge(nbytes);
}
Expand Down

0 comments on commit d537ec8

Please sign in to comment.