Unverified Commit 8f0a880c authored by Niels Lohmann's avatar Niels Lohmann Committed by GitHub

Merge pull request #2879 from nlohmann/issue2598

Avoid string in case of empty CBOR objects
parents fb1ee4f9 b7cc4708
...@@ -1082,38 +1082,41 @@ class binary_reader ...@@ -1082,38 +1082,41 @@ class binary_reader
return false; return false;
} }
string_t key; if (len != 0)
if (len != std::size_t(-1))
{ {
for (std::size_t i = 0; i < len; ++i) string_t key;
if (len != std::size_t(-1))
{ {
get(); for (std::size_t i = 0; i < len; ++i)
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
{ {
return false; get();
} if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
{ {
return false; return false;
}
key.clear();
} }
key.clear();
} }
} else
else
{
while (get() != 0xFF)
{ {
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) while (get() != 0xFF)
{ {
return false; if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
} {
return false;
}
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
{ {
return false; return false;
}
key.clear();
} }
key.clear();
} }
} }
......
...@@ -9298,38 +9298,41 @@ class binary_reader ...@@ -9298,38 +9298,41 @@ class binary_reader
return false; return false;
} }
string_t key; if (len != 0)
if (len != std::size_t(-1))
{ {
for (std::size_t i = 0; i < len; ++i) string_t key;
if (len != std::size_t(-1))
{ {
get(); for (std::size_t i = 0; i < len; ++i)
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
{ {
return false; get();
} if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
{ {
return false; return false;
}
key.clear();
} }
key.clear();
} }
} else
else
{
while (get() != 0xFF)
{ {
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) while (get() != 0xFF)
{ {
return false; if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
} {
return false;
}
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
{ {
return false; return false;
}
key.clear();
} }
key.clear();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment