Undefined behaviour: (1) Placement `new` done on an existing object without destroying and (2) the return value of placement `new` is discarded
@sankurm is already working on this.
Since Sep 15, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
Research direction
Start in score/concurrency/future/interruptible_state.h at lines 82, 102, and 118, then inspect the surrounding lifetime and assignment logic. Check the other placement-new instances noted in the issue and run the existing concurrency/future tests. Done means the reported undefined-behaviour cases are addressed without introducing new object-lifetime problems.
Written by the indexing model from the issue text.
Description
The following code on this line:
new (&value_) score::Result<Value>{std::move(value)};
This has two problems:
- The existing object is not destroyed. FYI, the
Errortype is currently trivially destructible. If this does not hold true in the future, this code would have the undefined behaviour of constructing another object at the same location without destroying the existing object. See this. - The return of the placement new should not be discarded. It is okay to assign it back to
value_. To read about the issue see this reference.
It is suggested that either the existing object be destroyed before placement new OR a new object be assigned to the existing one:
Suggested:
value_ = score::Result<Value>{std::move(value)}; //Preferred
The following is a possible fix but I would discourage it.
value_->~score::Result<Value>();
value_ = new (&value_) score::Result<Value>{std::move(value)};
The same issue is observed on all these lines also:
- https://github.com/eclipse-score/baselibs/blob/529cd6ba80cc16220e1a3bf1f491736ab07317ea/score/concurrency/future/interruptible_state.h#L102
- https://github.com/eclipse-score/baselibs/blob/529cd6ba80cc16220e1a3bf1f491736ab07317ea/score/concurrency/future/interruptible_state.h#L118
It may be worth checking other instances of this error and address, preferably, by creating new issues.
- Dominant language
- C++
- Stars
- 26
- Forks
- 86
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 41
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from eclipse-score/baselibs
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
eclipse-score/baselibs#495 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 72/100
eclipse-score/baselibs#368 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
eclipse-score/baselibs#602 ·
-
c++ comp-cpp-containers
Difficulty 3/5 1-2 days Newbie friendliness 68/100
eclipse-score/baselibs#601 ·
-
eclipse-score/baselibs#595 · 1 assignee ·
All issues in eclipse-score/baselibs
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·