Skip to content

fix: Fix a dangling pointer#939

Merged
ngxson merged 1 commit intocrosspoint-reader:masterfrom
Uri-Tauber:fix/dangling-pointer
Feb 18, 2026
Merged

fix: Fix a dangling pointer#939
ngxson merged 1 commit intocrosspoint-reader:masterfrom
Uri-Tauber:fix/dangling-pointer

Conversation

@Uri-Tauber
Copy link
Contributor

Summary

  • What is the goal of this PR? Fix a dangling pointer issue caused by using .c_str() on a temporary std::string.

basepath.substr() creates a temporary std::string, and calling .c_str() on it returns a pointer to its internal buffer (not a copy). Since the temporary string is destroyed at the end of the full expression, folderName ends up holding a dangling pointer, leading to undefined behavior.

To solve this, we stores the result in a persistent std::string object, ensuring the underlying buffer remains valid for the duration of its use.

A similar pattern caused the behavior reported in #728 (comment)


AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? < NO >

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97c3314 and b47e1f6.

📒 Files selected for processing (1)
  • src/activities/home/MyLibraryActivity.cpp
🔇 Additional comments (1)
src/activities/home/MyLibraryActivity.cpp (1)

199-200: Good fix for the temporary string lifetime issue.

Storing the substring in a std::string before calling c_str() removes the dangling pointer risk.


📝 Walkthrough

Walkthrough

A local variable folderName in MyLibraryActivity.cpp was changed from auto type to explicit std::string. The ternary expression now constructs a std::string directly, and the header drawing logic was adjusted to call c_str() on the variable instead of using a string literal. No functional behavior changes; memory management and type safety are explicitly clarified.

Changes

Cohort / File(s) Summary
Type Clarification
src/activities/home/MyLibraryActivity.cpp
Changed local variable folderName from auto to explicit std::string type; adjusted ternary operator and header rendering to use c_str() call for type safety.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (3 files):

⚔️ docs/i18n.md (content)
⚔️ lib/Epub/Epub/blocks/TextBlock.cpp (content)
⚔️ src/activities/home/MyLibraryActivity.cpp (content)

These conflicts must be resolved before merging into master.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: Fix a dangling pointer' directly describes the main change in the PR—fixing a dangling pointer issue caused by improper c_str() usage on temporary strings.
Description check ✅ Passed The description clearly explains the dangling pointer bug, the root cause (c_str() on temporary std::string), and the solution (storing result in persistent std::string), all directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@ngxson ngxson merged commit dc6562a into crosspoint-reader:master Feb 18, 2026
7 checks passed
lukestein pushed a commit to lukestein/crosspoint-reader that referenced this pull request Feb 18, 2026
## Summary

* **What is the goal of this PR?** Fix a dangling pointer issue caused
by using `.c_str()` on a temporary `std::string`.

`basepath.substr()` creates a temporary `std::string`, and calling
`.c_str()` on it returns a pointer to its internal buffer (not a copy).
Since the temporary string is destroyed at the end of the full
expression, `folderName` ends up holding a dangling pointer, leading to
undefined behavior.

To solve this, we stores the result in a persistent `std::string`
object, ensuring the underlying buffer remains valid for the duration of
its use.

A similar pattern caused the behavior reported in
crosspoint-reader#728 (comment)

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**< NO >**_
@Uri-Tauber Uri-Tauber deleted the fix/dangling-pointer branch February 18, 2026 16:12
ariel-lindemann pushed a commit to ariel-lindemann/crosspoint-reader that referenced this pull request Feb 19, 2026
## Summary

* **What is the goal of this PR?** Fix a dangling pointer issue caused
by using `.c_str()` on a temporary `std::string`.

`basepath.substr()` creates a temporary `std::string`, and calling
`.c_str()` on it returns a pointer to its internal buffer (not a copy).
Since the temporary string is destroyed at the end of the full
expression, `folderName` ends up holding a dangling pointer, leading to
undefined behavior.

To solve this, we stores the result in a persistent `std::string`
object, ensuring the underlying buffer remains valid for the duration of
its use.

A similar pattern caused the behavior reported in
crosspoint-reader#728 (comment)

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**< NO >**_
saslv pushed a commit to saslv/crosspoint-reader that referenced this pull request Feb 19, 2026
## Summary

* **What is the goal of this PR?** Fix a dangling pointer issue caused
by using `.c_str()` on a temporary `std::string`.

`basepath.substr()` creates a temporary `std::string`, and calling
`.c_str()` on it returns a pointer to its internal buffer (not a copy).
Since the temporary string is destroyed at the end of the full
expression, `folderName` ends up holding a dangling pointer, leading to
undefined behavior.

To solve this, we stores the result in a persistent `std::string`
object, ensuring the underlying buffer remains valid for the duration of
its use.

A similar pattern caused the behavior reported in
crosspoint-reader#728 (comment)

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**< NO >**_
el pushed a commit to el/crosspoint-reader that referenced this pull request Feb 19, 2026
## Summary

* **What is the goal of this PR?** Fix a dangling pointer issue caused
by using `.c_str()` on a temporary `std::string`.

`basepath.substr()` creates a temporary `std::string`, and calling
`.c_str()` on it returns a pointer to its internal buffer (not a copy).
Since the temporary string is destroyed at the end of the full
expression, `folderName` ends up holding a dangling pointer, leading to
undefined behavior.

To solve this, we stores the result in a persistent `std::string`
object, ensuring the underlying buffer remains valid for the duration of
its use.

A similar pattern caused the behavior reported in
crosspoint-reader#728 (comment)

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**< NO >**_
lukestein pushed a commit to lukestein/crosspoint-reader that referenced this pull request Feb 20, 2026
## Summary

* **What is the goal of this PR?** Fix a dangling pointer issue caused
by using `.c_str()` on a temporary `std::string`.

`basepath.substr()` creates a temporary `std::string`, and calling
`.c_str()` on it returns a pointer to its internal buffer (not a copy).
Since the temporary string is destroyed at the end of the full
expression, `folderName` ends up holding a dangling pointer, leading to
undefined behavior.

To solve this, we stores the result in a persistent `std::string`
object, ensuring the underlying buffer remains valid for the duration of
its use.

A similar pattern caused the behavior reported in
crosspoint-reader#728 (comment)

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**< NO >**_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants