Checking std::deque size before use it

This commit is contained in:
Felipe Zimmerle
2018-02-06 22:47:24 -03:00
parent eeec7efb68
commit 2b052b0edb

View File

@@ -127,14 +127,19 @@ int JSON::addArgument(const std::string& value) {
} }
} }
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>( if (m_containers.size() > 0) {
m_containers.back()); JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
if (a) { m_containers.back());
a->m_elementCounter++; if (a) {
a->m_elementCounter++;
} else {
data = getCurrentKey();
}
} else { } else {
data = getCurrentKey(); data = getCurrentKey();
} }
m_transaction->addArgument("JSON", path + data, value, 0); m_transaction->addArgument("JSON", path + data, value, 0);
return 1; return 1;
@@ -222,6 +227,10 @@ int JSON::yajl_start_array(void *ctx) {
int JSON::yajl_end_array(void *ctx) { int JSON::yajl_end_array(void *ctx) {
JSON *tthis = reinterpret_cast<JSON *>(ctx); JSON *tthis = reinterpret_cast<JSON *>(ctx);
if (tthis->m_containers.size() <= 0) {
return 1;
}
JSONContainer *a = tthis->m_containers.back(); JSONContainer *a = tthis->m_containers.back();
tthis->m_containers.pop_back(); tthis->m_containers.pop_back();
delete a; delete a;
@@ -252,6 +261,10 @@ int JSON::yajl_start_map(void *ctx) {
*/ */
int JSON::yajl_end_map(void *ctx) { int JSON::yajl_end_map(void *ctx) {
JSON *tthis = reinterpret_cast<JSON *>(ctx); JSON *tthis = reinterpret_cast<JSON *>(ctx);
if (tthis->m_containers.size() <= 0) {
return 1;
}
JSONContainer *a = tthis->m_containers.back(); JSONContainer *a = tthis->m_containers.back();
tthis->m_containers.pop_back(); tthis->m_containers.pop_back();
delete a; delete a;