Store stackEnd instead of stackSize
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
@@ -63,7 +64,8 @@ enum Symbol : uint8_t {
|
||||
};
|
||||
struct Parser3 {
|
||||
Parser3(const WeaselJsonCallbacks *callbacks, void *userdata, int stackSize)
|
||||
: callbacks(callbacks), userdata(userdata), stackSize(stackSize) {
|
||||
: callbacks(callbacks), userdata(userdata),
|
||||
stackEnd(stack() + stackSize) {
|
||||
reset();
|
||||
}
|
||||
|
||||
@@ -91,7 +93,7 @@ struct Parser3 {
|
||||
--stackPtr;
|
||||
}
|
||||
[[nodiscard]] WeaselJsonStatus push(std::initializer_list<Symbol> symbols) {
|
||||
if (stackPtr >= stack() + stackSize - symbols.size()) [[unlikely]] {
|
||||
if (stackEnd - stackPtr < ptrdiff_t(symbols.size())) [[unlikely]] {
|
||||
return WeaselJson_OVERFLOW;
|
||||
}
|
||||
for (int i = symbols.size() - 1; i >= 0; --i) {
|
||||
@@ -121,10 +123,10 @@ struct Parser3 {
|
||||
WeaselJsonCallbacks const *const callbacks;
|
||||
void *const userdata;
|
||||
Symbol *stackPtr;
|
||||
Symbol *const stackEnd;
|
||||
uint32_t utf8Codepoint;
|
||||
uint32_t utf16Surrogate;
|
||||
uint32_t minCodepoint;
|
||||
int const stackSize;
|
||||
NumDfa numDfa;
|
||||
Utf8Dfa strDfa;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user