viewer#3010 Fix malfunctioning json array to llsd parsing

Was reserving 'size' elements, then appending more elements on top.
master
Andrey Kleshchev 2024-11-05 22:11:18 +02:00 committed by Andrey Kleshchev
parent a9e0bc996e
commit 55732f7343
1 changed files with 5 additions and 4 deletions

View File

@ -63,15 +63,16 @@ LLSD LlsdFromJson(const boost::json::value& val)
case boost::json::kind::array:
{
result = LLSD::emptyArray();
auto& array = val.as_array();
const boost::json::array& array = val.as_array();
size_t size = array.size();
// allocate elements 0 .. (size() - 1) to avoid incremental allocation
if (! array.empty())
{
result[array.size() - 1] = LLSD();
result[size - 1] = LLSD();
}
for (const auto &element : array)
for (size_t i = 0; i < size; i++)
{
result.append(LlsdFromJson(element));
result[i] = (LlsdFromJson(array[i]));
}
break;
}