forked from bblanchon/ArduinoJson
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 {
|
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 {
|
inline SlotCount VariantPool::usage() const {
|
||||||
|
@@ -52,10 +52,11 @@ class VariantPoolList {
|
|||||||
void freeSlot(SlotWithId slot);
|
void freeSlot(SlotWithId slot);
|
||||||
|
|
||||||
VariantSlot* getSlot(SlotId id) const {
|
VariantSlot* getSlot(SlotId id) const {
|
||||||
|
if (id == NULL_SLOT)
|
||||||
|
return nullptr;
|
||||||
auto poolIndex = SlotId(id / ARDUINOJSON_POOL_CAPACITY);
|
auto poolIndex = SlotId(id / ARDUINOJSON_POOL_CAPACITY);
|
||||||
auto indexInPool = SlotId(id % ARDUINOJSON_POOL_CAPACITY);
|
auto indexInPool = SlotId(id % ARDUINOJSON_POOL_CAPACITY);
|
||||||
if (poolIndex >= count_)
|
ARDUINOJSON_ASSERT(poolIndex < count_);
|
||||||
return nullptr;
|
|
||||||
return pools_[poolIndex].getSlot(indexInPool);
|
return pools_[poolIndex].getSlot(indexInPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user