Refactor error reporting for bounds checks. (#464)
This introduces a very limited formatter that can embed strings and hex representations of pointers / integers in an internal buffer. This is used to format error strings for passing to `Pal::error`. This is used, in turn, by a wrapper for reporting bounds checks, which can be used by external functions to implement bounds checks. This removes the sprintf_l usage from the bounds checks. This provides enough of a format implementation that the tests introduced in #465 can be refactored to use this, instead of their custom `printf` wrapper and that can be used by SNMALLOC_CHECK. This will be a follow-on PR.
This commit is contained in:
@@ -237,6 +237,24 @@ int main(int argc, char** argv)
|
||||
|
||||
setup();
|
||||
|
||||
// Smoke test the fatal error builder. Check that it can generate strings
|
||||
// including all of the kinds of things that it expects to be able to format.
|
||||
void* fakeptr = reinterpret_cast<void*>(static_cast<uintptr_t>(0x42));
|
||||
FatalErrorBuilder<1024> b{
|
||||
"testing pointer {} size_t {} message, {} world, null is {}",
|
||||
fakeptr,
|
||||
size_t(42),
|
||||
"hello",
|
||||
nullptr};
|
||||
if (
|
||||
strcmp(
|
||||
"testing pointer 0x42 size_t 0x2a message, hello world, null is 0x0",
|
||||
b.get_message()) != 0)
|
||||
{
|
||||
printf("Incorrect rendering of fatal error message: %s\n", b.get_message());
|
||||
abort();
|
||||
}
|
||||
|
||||
our_free(nullptr);
|
||||
|
||||
/* A very large allocation size that we expect to fail. */
|
||||
|
||||
Reference in New Issue
Block a user