mirror of
https://github.com/FEX-Emu/FEX.git
synced 2024-12-15 09:59:28 +00:00
30e3d795da
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.
24 lines
657 B
C++
24 lines
657 B
C++
// SPDX-License-Identifier: MIT
|
|
#include "Common/JSONPool.h"
|
|
|
|
namespace FEX::JSON {
|
|
json_t* PoolInit(jsonPool_t* Pool);
|
|
json_t* PoolAlloc(jsonPool_t* Pool);
|
|
|
|
JsonAllocator::JsonAllocator()
|
|
: PoolObject {
|
|
.init = FEX::JSON::PoolInit,
|
|
.alloc = FEX::JSON::PoolAlloc,
|
|
} {}
|
|
|
|
json_t* PoolInit(jsonPool_t* Pool) {
|
|
JsonAllocator* alloc = reinterpret_cast<JsonAllocator*>(Pool);
|
|
return &*alloc->json_objects.emplace(alloc->json_objects.end());
|
|
}
|
|
|
|
json_t* PoolAlloc(jsonPool_t* Pool) {
|
|
JsonAllocator* alloc = reinterpret_cast<JsonAllocator*>(Pool);
|
|
return &*alloc->json_objects.emplace(alloc->json_objects.end());
|
|
}
|
|
} // namespace FEX::JSON
|