mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-02 08:48:27 +01:00
Added JsonDocument::overflowed() (closes #1358)
This commit is contained in:
@@ -29,7 +29,8 @@ class MemoryPool {
|
||||
: _begin(buf),
|
||||
_left(buf),
|
||||
_right(buf ? buf + capa : 0),
|
||||
_end(buf ? buf + capa : 0) {
|
||||
_end(buf ? buf + capa : 0),
|
||||
_overflowed(false) {
|
||||
ARDUINOJSON_ASSERT(isAligned(_begin));
|
||||
ARDUINOJSON_ASSERT(isAligned(_right));
|
||||
ARDUINOJSON_ASSERT(isAligned(_end));
|
||||
@@ -48,6 +49,10 @@ class MemoryPool {
|
||||
return size_t(_left - _begin + _end - _right);
|
||||
}
|
||||
|
||||
bool overflowed() const {
|
||||
return _overflowed;
|
||||
}
|
||||
|
||||
VariantSlot* allocVariant() {
|
||||
return allocRight<VariantSlot>();
|
||||
}
|
||||
@@ -91,9 +96,14 @@ class MemoryPool {
|
||||
return str;
|
||||
}
|
||||
|
||||
void markAsOverflowed() {
|
||||
_overflowed = true;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_left = _begin;
|
||||
_right = _end;
|
||||
_overflowed = false;
|
||||
}
|
||||
|
||||
bool canAlloc(size_t bytes) const {
|
||||
@@ -171,8 +181,10 @@ class MemoryPool {
|
||||
#endif
|
||||
|
||||
char* allocString(size_t n) {
|
||||
if (!canAlloc(n))
|
||||
if (!canAlloc(n)) {
|
||||
_overflowed = true;
|
||||
return 0;
|
||||
}
|
||||
char* s = _left;
|
||||
_left += n;
|
||||
checkInvariants();
|
||||
@@ -185,13 +197,16 @@ class MemoryPool {
|
||||
}
|
||||
|
||||
void* allocRight(size_t bytes) {
|
||||
if (!canAlloc(bytes))
|
||||
if (!canAlloc(bytes)) {
|
||||
_overflowed = true;
|
||||
return 0;
|
||||
}
|
||||
_right -= bytes;
|
||||
return _right;
|
||||
}
|
||||
|
||||
char *_begin, *_left, *_right, *_end;
|
||||
bool _overflowed;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user