Skip to content
Snippets Groups Projects
Unverified Commit 0a39c2d7 authored by Eric Niebler's avatar Eric Niebler Committed by GitHub
Browse files

Merge pull request #13 from Lastique/fix_advancing_nullptr

Avoid advancing null pointers, which is UB
parents 0a314d9d 9e8a972a
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@
# pragma warning(disable : 4127) // conditional expression constant
#endif
#include <cstddef>
#include <algorithm>
#include <functional>
......@@ -210,22 +211,20 @@ public:
T *push_sequence(std::size_t count, T const &t)
{
// This is the ptr to return
T *ptr = this->curr_;
// Advance the high-water mark
this->curr_ += count;
// Check to see if we have overflowed this buffer
if(std::less<void*>()(this->end_, this->curr_))
std::size_t size_left = static_cast< std::size_t >(this->end_ - this->curr_);
if (size_left < count)
{
// oops, back this out.
this->curr_ = ptr;
// allocate a new block and return a ptr to the new memory
return this->grow_(count, t);
}
// This is the ptr to return
T *ptr = this->curr_;
// Advance the high-water mark
this->curr_ += count;
return ptr;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment