danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
726 stars 164 forks source link

fix: avoid over-allocating memory for 8 byte alignment or less #510

Closed romange closed 6 months ago

romange commented 6 months ago

Fixes #509

danielaparker commented 6 months ago

Thanks!

Line 147

if (reinterpret_cast<uintptr_t>(ptr) % align == 0)

will fail compilation if ptr is a "fancy pointer". I don't have a test case for that, but you'll see it if you try to compile boost_examples/interprocess_allocator/shared_memory.cpp. I think you need to write it as

q = extension_traits::to_plain_pointer(ptr);
if (reinterpret_cast<uintptr_t>(q) % align == 0) {

Line 157

align_pad = (align-1);

requires a cast to suppress a warning.

romange commented 6 months ago

@danielaparker PTAL

danielaparker commented 6 months ago

Thanks for contributing