The public C API functions WeaselJsonParser_reset and WeaselJsonParser_destroy cast the supplied pointer and dispatch directly without checking for null. Passing nullptr causes immediate undefined behavior (dereferencing/invoking a destructor on a null pointer), even though WeaselJsonParser_create can legitimately return nullptr when allocation fails or the stack size is too small.
Affected code (src/lib.cpp):
__attribute__((visibility("default")))voidWeaselJsonParser_reset(WeaselJsonParser*parser){((Parser3*)parser)->reset();// UB if parser == nullptr
}__attribute__((visibility("default")))voidWeaselJsonParser_destroy(WeaselJsonParser*parser){((Parser3*)parser)->~Parser3();// UB if parser == nullptr
free(parser);}
This is inconsistent with the usual C convention that free(NULL) is safe, and it makes cleanup code fragile when creation fails. For example:
WeaselJsonParser*p=WeaselJsonParser_create(-1,&c,nullptr,0);// p == nullptr
WeaselJsonParser_destroy(p);// crash / UB
Expected behavior: both functions should return early (or otherwise behave safely) when parser is nullptr, similar to how free(nullptr) is a no-op.
The public C API functions `WeaselJsonParser_reset` and `WeaselJsonParser_destroy` cast the supplied pointer and dispatch directly without checking for null. Passing `nullptr` causes immediate undefined behavior (dereferencing/invoking a destructor on a null pointer), even though `WeaselJsonParser_create` can legitimately return `nullptr` when allocation fails or the stack size is too small.
Affected code (`src/lib.cpp`):
```cpp
__attribute__((visibility("default"))) void
WeaselJsonParser_reset(WeaselJsonParser *parser) {
((Parser3 *)parser)->reset(); // UB if parser == nullptr
}
__attribute__((visibility("default"))) void
WeaselJsonParser_destroy(WeaselJsonParser *parser) {
((Parser3 *)parser)->~Parser3(); // UB if parser == nullptr
free(parser);
}
```
This is inconsistent with the usual C convention that `free(NULL)` is safe, and it makes cleanup code fragile when creation fails. For example:
```cpp
WeaselJsonParser *p = WeaselJsonParser_create(-1, &c, nullptr, 0);
// p == nullptr
WeaselJsonParser_destroy(p); // crash / UB
```
Expected behavior: both functions should return early (or otherwise behave safely) when `parser` is `nullptr`, similar to how `free(nullptr)` is a no-op.
weaselbot
was assigned by andrew2026-06-29 17:04:46 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
The public C API functions
WeaselJsonParser_resetandWeaselJsonParser_destroycast the supplied pointer and dispatch directly without checking for null. Passingnullptrcauses immediate undefined behavior (dereferencing/invoking a destructor on a null pointer), even thoughWeaselJsonParser_createcan legitimately returnnullptrwhen allocation fails or the stack size is too small.Affected code (
src/lib.cpp):This is inconsistent with the usual C convention that
free(NULL)is safe, and it makes cleanup code fragile when creation fails. For example:Expected behavior: both functions should return early (or otherwise behave safely) when
parserisnullptr, similar to howfree(nullptr)is a no-op.