Encapsulate SafeBuf more

This commit is contained in:
Ivan Skytte Jørgensen
2016-11-07 14:38:43 +01:00
parent 96d700a3c7
commit 5249f14d42
4 changed files with 4 additions and 7 deletions

@ -5,7 +5,7 @@ class JsonItem *Json::addNewItem () {
JsonItem *ji = (JsonItem *)m_sb.getBufPtr();
if ( m_sb.m_length + (int32_t)sizeof(JsonItem) > m_sb.m_capacity ) {
if(m_sb.getAvail() < (int32_t)sizeof(JsonItem)) {
log("json: preventing buffer breach");
return NULL;
}

@ -99,7 +99,7 @@ bool Profiler::init() {
// if ( ! m_quickpollMissBuf.reserve ( 20000 ) )
// return false;
if ( m_ipBuf.m_capacity <= 0 &&
if ( m_ipBuf.getCapacity() <= 0 &&
! m_ipBuf.reserve ( 5000000 , "profbuf" ) )
return false;
@ -942,8 +942,7 @@ Profiler::getStackFrame() {
// return;
// the lines calling functions
if ( g_profiler.m_ipBuf.m_length + 8*32 >=
g_profiler.m_ipBuf.m_capacity )
if ( g_profiler.m_ipBuf.getAvail() <= 8*32 )
return;
// support 64-bit

@ -237,9 +237,9 @@ public:
const char& operator[](int32_t i) const;
public:
int32_t m_capacity;
int32_t m_length;
private:
int32_t m_capacity;
char *m_buf;
bool m_usingStack;
const char *m_label;

@ -91,8 +91,6 @@ bool Wiki::loadText ( int32_t fileSize ) {
if ( ! sb.catFile(ff2) ) return false;
sb.pushChar('\0');
// should not have reallocated too much
if ( sb.length() + 100 < sb.m_capacity ) { g_process.shutdownAbort(true); }
char *buf = sb.getBufStart();
int32_t size = sb.length() - 1;