Cherry-Pick: Fix memnew_placement with char * arguments (godotengine/godot#112033) - #1417
morgothaufheroin88 wants to merge 2 commits into
Conversation
… the description version, allocating on the heap instead of ni the given memory. (cherry picked from commit 65bf51600652bddc8faea0f7f6a1ead0e28da81b)
Covers the memnew_placement() overload-resolution bug fixed in the previous commit (godotengine/godot#112033): with a char* placement address the description overload of operator new was picked, so push_back()/insert()/resize_initialized() on a LocalVector<char> wrote into a freshly allocated block and left the vector's storage untouched. The test fails on the unfixed code (elements read back as 0) and passes with the fix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. WalkthroughThe change adds a ChangesPlacement-new overload fix
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The placement-new fix has appropriate regression coverage and no remaining merge-blocking risk was identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
JoltedJon
left a comment
There was a problem hiding this comment.
Tested and see that it's fixed with this PR. Thanks for bringing this in!
Cherry-pick of godotengine/godot#112033 (upstream commit 65bf51600652bddc8faea0f7f6a1ead0e28da81b, merged 2025-10-25), plus a regression test.
memnew_placement(ptr, T(...))expands to::new (ptr) T(...). Whenptris achar *, overload resolution prefersoperator new(size_t, const char *p_description)(the "new with description" overload incore/os/memory.h) over the standardoperator new(size_t, void *), becausechar *→const char *is a better conversion thanchar *→void *. The object is then constructed in a freshly allocated block and the intended storage is never written.Concretely,
LocalVector<char>::push_back(),insert(),resize_initialized()andmemnew_arr_placement()oncharstorage silently produce garbage and leak. Nothing in the current tree hits this (allLocalVector<char>users go throughresize()+memcpy), but I ran into it immediately while writing a follow-upFileAccess::get_line()PR, and upstream hit it as data loss (godotengine/godot#112022).The upstream fix adds an
operator new(size_t, char *)overload that forwards to placement new. It is applied verbatim with the original author and(cherry picked from ...)trailer; the test is a separate commit.Testing
[LocalVector] Push Back char.fails onmaster(CHECK( vector[0] == 'a' )→0 == 97) and passes with the fix.Summary by CodeRabbit
Bug Fixes
Tests