Make RapidJSON Stack::Bottom pointer cast explicit via void*#173
Merged
SergioRZMasson merged 1 commit intoJul 14, 2026
Conversation
Stack::Bottom<T>() returns the internal raw byte buffer (char* stack_) reinterpret_cast directly to T*. When T is a wider element type (e.g. a wide-character type) this is a narrow-to-wide pointer conversion that some compilers and static analysis tools diagnose as a potentially misaligned/narrowing cast. Apply a small CMake patch during the RapidJSON ExternalProject_Add download step (matching the existing fix-null-allocator-deref.cmake mechanism) that routes the cast through void*: reinterpret_cast<T*>(stack_) -> reinterpret_cast<T*>(static_cast<void*>(stack_)) This makes the raw-storage intent explicit. It is address-identical and preserves the exact behavior of the generic memory stack, covering both the const and non-const Bottom() overloads, and is idempotent. Validated by applying the patch to RapidJSON at the pinned commit (232389d4) and compiling a translation unit that includes rapidjson and exercises Stack::Bottom<char>/<wchar_t> (const and non-const overloads) plus Document parse + Writer, with -Wall -Wextra -Werror. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SergioRZMasson
force-pushed
the
sergioze/fix-rapidjson-string-type-conversion
branch
from
July 14, 2026 19:55
e757686 to
531ef16
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Stack::Bottom<T>()returns the internal raw byte buffer (char* stack_)reinterpret_castdirectly toT*. WhenTis a wider element type (e.g. awide-character type), this is a narrow-to-wide pointer conversion that some
compilers and static analysis tools diagnose as a potentially
misaligned/narrowing cast.
Change
Following the same mechanism as the existing
fix-null-allocator-deref.cmakepatch (#167), a small CMake
string(REPLACE)patch is applied during theRapidJSON
ExternalProject_Adddownload step, routing the cast throughvoid*:reinterpret_cast<T*>(stack_)→reinterpret_cast<T*>(static_cast<void*>(stack_))This makes the "treat this buffer as raw storage" intent explicit. It is
address-identical and preserves the exact behavior of the generic memory stack,
covers both the
constand non-constBottom()overloads, and is idempotent.Changes
External/RapidJSON/patches/fix-string-type-conversion.cmakeExternal/RapidJSON/CMakeRapidJSONDownload.txt.in— chain the newpatch after the existing one in
PATCH_COMMANDValidation
Applied the patch to RapidJSON at the pinned commit (
232389d4) and compiled atranslation unit that includes rapidjson and exercises
Stack::Bottom<char>/<wchar_t>(const+ non-const) plusDocumentparse +Writer, withclang++ -std=c++14 -Wall -Wextra -Werror. Re-running the patchis a no-op.