Skip to content

Commit 2b052b0

Browse files
author
Felipe Zimmerle
committed
Checking std::deque size before use it
1 parent eeec7ef commit 2b052b0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/request_body_processor/json.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,19 @@ int JSON::addArgument(const std::string& value) {
127127
}
128128
}
129129

130-
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
131-
m_containers.back());
132-
if (a) {
133-
a->m_elementCounter++;
130+
if (m_containers.size() > 0) {
131+
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
132+
m_containers.back());
133+
if (a) {
134+
a->m_elementCounter++;
135+
} else {
136+
data = getCurrentKey();
137+
}
134138
} else {
135139
data = getCurrentKey();
136140
}
137141

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

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

223228
int JSON::yajl_end_array(void *ctx) {
224229
JSON *tthis = reinterpret_cast<JSON *>(ctx);
230+
if (tthis->m_containers.size() <= 0) {
231+
return 1;
232+
}
233+
225234
JSONContainer *a = tthis->m_containers.back();
226235
tthis->m_containers.pop_back();
227236
delete a;
@@ -252,6 +261,10 @@ int JSON::yajl_start_map(void *ctx) {
252261
*/
253262
int JSON::yajl_end_map(void *ctx) {
254263
JSON *tthis = reinterpret_cast<JSON *>(ctx);
264+
if (tthis->m_containers.size() <= 0) {
265+
return 1;
266+
}
267+
255268
JSONContainer *a = tthis->m_containers.back();
256269
tthis->m_containers.pop_back();
257270
delete a;

0 commit comments

Comments
 (0)