Avoid nullptr subtraction when flushing scalars at EOF #43

Closed
weaselbot wants to merge 2 commits from weaselbot/weaseljson:weaselbot/issue-40 into main
Showing only changes of commit bf3f2fe810 - Show all commits
+5 -10
View File
@@ -83,10 +83,7 @@ struct Parser3 {
[[nodiscard]] WeaselJsonStatus parse(char *buf, int len);
void flushNumber(bool done, char *buf) {
int len = 0;
if (dataBegin != nullptr && buf != nullptr) {
len = buf - dataBegin;
}
int len = (intptr_t)buf - (intptr_t)dataBegin;
assert(len >= 0);
if (done || len > 0) {
callbacks->on_number_data(userdata, dataBegin ? dataBegin : "", len,
@@ -95,13 +92,11 @@ struct Parser3 {
}
void flushString(bool done, char *buf) {
int len = 0;
if (dataBegin != nullptr) {
int len;
if (!(flags & WeaselJsonRaw)) {
len = writeBuf - dataBegin;
} else if (buf != nullptr) {
len = buf - dataBegin;
}
len = (intptr_t)writeBuf - (intptr_t)dataBegin;
} else {
len = (intptr_t)buf - (intptr_t)dataBegin;
}
assert(len >= 0);
if (done || len > 0) {