mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-09 00:00:17 +02:00
Fixes #3691 We weren't checking if the file was empty before using its `at` function member. This was causing an early crash if the config file existed but was empty. Consolidates the three locations that copy and pasted the json allocator tools and adds an empty check for all of them. Also adds two missing checks to the ThunksDB handler that could have resulted in the same crash if ThunksDB was an empty file.
26 lines
584 B
C++
26 lines
584 B
C++
// SPDX-License-Identifier: MIT
|
|
|
|
#include <FEXCore/fextl/memory.h>
|
|
#include <FEXCore/fextl/list.h>
|
|
|
|
#include <tiny-json.h>
|
|
|
|
namespace FEX::JSON {
|
|
struct JsonAllocator {
|
|
jsonPool_t PoolObject;
|
|
fextl::list<json_t> json_objects;
|
|
|
|
JsonAllocator();
|
|
};
|
|
static_assert(offsetof(JsonAllocator, PoolObject) == 0, "This needs to be at offset zero");
|
|
|
|
template<typename T>
|
|
const json_t* CreateJSON(T& Container, JsonAllocator& Allocator) {
|
|
if (Container.empty()) {
|
|
return nullptr;
|
|
}
|
|
|
|
return json_createWithPool(&Container.at(0), &Allocator.PoolObject);
|
|
}
|
|
} // namespace FEX::JSON
|