Merge pull request 'Handle null parser in WeaselJsonParser_parse' (#54) from null-parser into main
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (push) Successful in 53s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (push) Successful in 50s
CI / pre-commit (push) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (push) Successful in 1m41s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (push) Successful in 1m53s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (push) Successful in 53s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (push) Successful in 50s
CI / pre-commit (push) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (push) Successful in 1m41s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (push) Successful in 1m53s
Reviewed-on: #54
This commit was merged in pull request #54.
This commit is contained in:
@@ -38,6 +38,8 @@ enum WeaselJsonStatus {
|
|||||||
WeaselJson_REJECT,
|
WeaselJson_REJECT,
|
||||||
/** json is too deeply nested */
|
/** json is too deeply nested */
|
||||||
WeaselJson_OVERFLOW,
|
WeaselJson_OVERFLOW,
|
||||||
|
/** Tried to call parse on a null parser */
|
||||||
|
WeaselJson_NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct WeaselJsonParser WeaselJsonParser;
|
typedef struct WeaselJsonParser WeaselJsonParser;
|
||||||
@@ -65,7 +67,7 @@ void WeaselJsonParser_destroy(WeaselJsonParser *parser);
|
|||||||
/** Incrementally parse `len` more bytes starting at `buf`. `buf` may be
|
/** Incrementally parse `len` more bytes starting at `buf`. `buf` may be
|
||||||
* modified. Call with `len` 0 to indicate end of data. `buf` may be null if
|
* modified. Call with `len` 0 to indicate end of data. `buf` may be null if
|
||||||
* `len` is 0. `len` must not be negative; a negative length is treated as a
|
* `len` is 0. `len` must not be negative; a negative length is treated as a
|
||||||
* rejected input. */
|
* rejected input. Returns WeaselJson_NULL if parser is null */
|
||||||
WeaselJsonStatus WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf,
|
WeaselJsonStatus WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf,
|
||||||
int len);
|
int len);
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ WeaselJsonParser_destroy(WeaselJsonParser *parser) {
|
|||||||
|
|
||||||
__attribute__((visibility("default"))) WeaselJsonStatus
|
__attribute__((visibility("default"))) WeaselJsonStatus
|
||||||
WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf, int len) {
|
WeaselJsonParser_parse(WeaselJsonParser *parser, char *buf, int len) {
|
||||||
|
if (parser == nullptr) [[unlikely]] {
|
||||||
|
return WeaselJson_NULL;
|
||||||
|
}
|
||||||
return ((Parser3 *)parser)->parse(buf, len);
|
return ((Parser3 *)parser)->parse(buf, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -330,6 +330,10 @@ TEST_CASE("parse rejects negative length") {
|
|||||||
WeaselJsonParser_destroy(parser);
|
WeaselJsonParser_destroy(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Calling parse with nullptr doesn't crash") {
|
||||||
|
REQUIRE(WeaselJsonParser_parse(nullptr, nullptr, 0) == WeaselJson_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("streaming") { testStreaming(json); }
|
TEST_CASE("streaming") { testStreaming(json); }
|
||||||
|
|
||||||
TEST_CASE("reset clears inKey and transient state") {
|
TEST_CASE("reset clears inKey and transient state") {
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ int main(int argc, char **argv) {
|
|||||||
case WeaselJson_REJECT:
|
case WeaselJson_REJECT:
|
||||||
case WeaselJson_OVERFLOW:
|
case WeaselJson_OVERFLOW:
|
||||||
return 1;
|
return 1;
|
||||||
|
case WeaselJson_NULL:
|
||||||
|
fprintf(stderr, "parse called with a null parser\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (l == 0) {
|
if (l == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class WeaselJsonStatus(enum.Enum):
|
|||||||
AGAIN = 1
|
AGAIN = 1
|
||||||
REJECT = 2
|
REJECT = 2
|
||||||
OVERFLOW = 3
|
OVERFLOW = 3
|
||||||
|
NULL = 4
|
||||||
|
|
||||||
|
|
||||||
class WeaselJsonCallbacksBase:
|
class WeaselJsonCallbacksBase:
|
||||||
|
|||||||
Reference in New Issue
Block a user