Skip to content

Commit

Permalink
Checking std::deque size before use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Zimmerle committed Feb 20, 2018
1 parent eeec7ef commit 2b052b0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/request_body_processor/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ int JSON::addArgument(const std::string& value) {
}
}

JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
m_containers.back());
if (a) {
a->m_elementCounter++;
if (m_containers.size() > 0) {
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
m_containers.back());
if (a) {
a->m_elementCounter++;
} else {
data = getCurrentKey();
}
} else {
data = getCurrentKey();
}


m_transaction->addArgument("JSON", path + data, value, 0);

return 1;
Expand Down Expand Up @@ -222,6 +227,10 @@ int JSON::yajl_start_array(void *ctx) {

int JSON::yajl_end_array(void *ctx) {
JSON *tthis = reinterpret_cast<JSON *>(ctx);
if (tthis->m_containers.size() <= 0) {
return 1;
}

JSONContainer *a = tthis->m_containers.back();
tthis->m_containers.pop_back();
delete a;
Expand Down Expand Up @@ -252,6 +261,10 @@ int JSON::yajl_start_map(void *ctx) {
*/
int JSON::yajl_end_map(void *ctx) {
JSON *tthis = reinterpret_cast<JSON *>(ctx);
if (tthis->m_containers.size() <= 0) {
return 1;
}

JSONContainer *a = tthis->m_containers.back();
tthis->m_containers.pop_back();
delete a;
Expand Down

0 comments on commit 2b052b0

Please sign in to comment.