mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 18:27:37 +02:00
Detect null slot id earlier in VariantPoolList::getSlot()
This commit is contained in:
@ -42,7 +42,8 @@ inline SlotWithId VariantPool::allocSlot() {
|
||||
}
|
||||
|
||||
inline VariantSlot* VariantPool::getSlot(SlotId id) const {
|
||||
return id == NULL_SLOT ? nullptr : &slots_[id];
|
||||
ARDUINOJSON_ASSERT(id < usage_);
|
||||
return &slots_[id];
|
||||
}
|
||||
|
||||
inline SlotCount VariantPool::usage() const {
|
||||
|
@ -52,10 +52,11 @@ class VariantPoolList {
|
||||
void freeSlot(SlotWithId slot);
|
||||
|
||||
VariantSlot* getSlot(SlotId id) const {
|
||||
if (id == NULL_SLOT)
|
||||
return nullptr;
|
||||
auto poolIndex = SlotId(id / ARDUINOJSON_POOL_CAPACITY);
|
||||
auto indexInPool = SlotId(id % ARDUINOJSON_POOL_CAPACITY);
|
||||
if (poolIndex >= count_)
|
||||
return nullptr;
|
||||
ARDUINOJSON_ASSERT(poolIndex < count_);
|
||||
return pools_[poolIndex].getSlot(indexInPool);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user