Repository navigation
Fix g++ 11 incompatibility issue - #16512
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR changes the internal JSON object representation in two C++ files. ChangesJVal Pointer-Based Object Storage
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/cpp/thinc_ner.cpp`:
- Around line 34-38: The copy-assignment operator in JVal is not exception-safe
because it deletes obj before the replacement allocation succeeds, which can
leave a dangling pointer and cause double-free in ~JVal. Update JVal::operator=
to allocate the new JObjMap copy into a temporary first, then replace obj only
after the allocation succeeds. Keep the self-assignment check and preserve the
existing copies of type, str, arr, and num in JVal.
In `@internal/cpp/thinc_parser.cpp`:
- Line 27: The JVal copy-assignment operator is not exception-safe and can leave
obj dangling if copying the JObjMap allocation fails. Update JVal::operator= to
allocate the new JObjMap before deleting the existing obj, then swap or assign
the new pointer only after successful allocation. Keep the existing
self-assignment check and ensure the ownership of obj remains valid throughout
the assignment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a16053fc-7bb7-4791-974c-6cdd20d8d46c
📒 Files selected for processing (2)
internal/cpp/thinc_ner.cppinternal/cpp/thinc_parser.cpp
| JVal& operator=(const JVal& o) { | ||
| if (this != &o) { delete obj; type=o.type; str=o.str; arr=o.arr; num=o.num; | ||
| obj = o.obj ? new JObjMap(*o.obj) : nullptr; } | ||
| return *this; | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Copy-assignment is not exception-safe → double-free (UB).
Same issue as thinc_parser.cpp: delete obj executes before the new allocation, so if new JObjMap(*o.obj) throws, obj is left dangling and ~JVal will delete it a second time. Allocate into a temporary first, then delete.
🛡️ Proposed fix (allocate-then-delete)
JVal& operator=(const JVal& o) {
- if (this != &o) { delete obj; type=o.type; str=o.str; arr=o.arr; num=o.num;
- obj = o.obj ? new JObjMap(*o.obj) : nullptr; }
+ if (this != &o) { JObjMap* tmp = o.obj ? new JObjMap(*o.obj) : nullptr;
+ delete obj; obj = tmp; type=o.type; str=o.str; arr=o.arr; num=o.num; }
return *this;
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| JVal& operator=(const JVal& o) { | |
| if (this != &o) { delete obj; type=o.type; str=o.str; arr=o.arr; num=o.num; | |
| obj = o.obj ? new JObjMap(*o.obj) : nullptr; } | |
| return *this; | |
| } | |
| JVal& operator=(const JVal& o) { | |
| if (this != &o) { JObjMap* tmp = o.obj ? new JObjMap(*o.obj) : nullptr; | |
| delete obj; obj = tmp; type=o.type; str=o.str; arr=o.arr; num=o.num; } | |
| return *this; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/cpp/thinc_ner.cpp` around lines 34 - 38, The copy-assignment
operator in JVal is not exception-safe because it deletes obj before the
replacement allocation succeeds, which can leave a dangling pointer and cause
double-free in ~JVal. Update JVal::operator= to allocate the new JObjMap copy
into a temporary first, then replace obj only after the allocation succeeds.
Keep the self-assignment check and preserve the existing copies of type, str,
arr, and num in JVal.
| ~JVal(){delete obj;} | ||
| JVal()=default; | ||
| JVal(const JVal& o):type(o.type),str(o.str),arr(o.arr),num(o.num){if(o.obj)obj=new JObjMap(*o.obj);} | ||
| JVal& operator=(const JVal& o){if(this!=&o){delete obj;type=o.type;str=o.str;arr=o.arr;num=o.num;obj=o.obj?new JObjMap(*o.obj):nullptr;}return*this;} |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Copy-assignment is not exception-safe → double-free (UB).
delete obj runs first, leaving obj dangling. If the subsequent new JObjMap(*o.obj) throws (e.g. bad_alloc), obj still points at freed memory, and the eventual ~JVal(){delete obj;} deletes it again. Allocate before deleting.
🛡️ Proposed fix (allocate-then-delete)
- JVal& operator=(const JVal& o){if(this!=&o){delete obj;type=o.type;str=o.str;arr=o.arr;num=o.num;obj=o.obj?new JObjMap(*o.obj):nullptr;}return*this;}
+ JVal& operator=(const JVal& o){if(this!=&o){JObjMap* tmp=o.obj?new JObjMap(*o.obj):nullptr;delete obj;obj=tmp;type=o.type;str=o.str;arr=o.arr;num=o.num;}return*this;}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| JVal& operator=(const JVal& o){if(this!=&o){delete obj;type=o.type;str=o.str;arr=o.arr;num=o.num;obj=o.obj?new JObjMap(*o.obj):nullptr;}return*this;} | |
| JVal& operator=(const JVal& o){if(this!=&o){JObjMap* tmp=o.obj?new JObjMap(*o.obj):nullptr;delete obj;obj=tmp;type=o.type;str=o.str;arr=o.arr;num=o.num;}return*this;} |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/cpp/thinc_parser.cpp` at line 27, The JVal copy-assignment operator
is not exception-safe and can leave obj dangling if copying the JObjMap
allocation fails. Update JVal::operator= to allocate the new JObjMap before
deleting the existing obj, then swap or assign the new pointer only after
successful allocation. Keep the existing self-assignment check and ensure the
ownership of obj remains valid throughout the assignment.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16512 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
No description provided.