Skip to content

Commit

Permalink
Fix warning of dangling pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Feb 20, 2025
1 parent 5a187e2 commit 45b8340
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 6 additions & 11 deletions pluto/src/pluto/stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

namespace pluto {

static void* stream0_underlying_ = nullptr;

#if PLUTO_HAVE_HIC
stream::stream(stream_t s):
stream::stream(stream_t& s):
stream_{&s, [](stream_t*) {
// wrapping, no delete
}} {}
Expand All @@ -43,26 +45,19 @@ void stream::wait() const {
}

#else
stream::stream(stream_t stream):
stream::stream(stream_t& stream):
stream_{&stream, [](stream_t*) {
// wrapping, no delete
}} {}

stream::stream():
stream_{[]() {
static int s = 0;
return reinterpret_cast<stream_t*>(&s);
}(),
[](stream_t*) {
// No deletion of wrapped static variable
}} {}
stream::stream(): stream(stream0_underlying_) {}

void stream::wait() const {
// Nothing
}
#endif

static stream stream0_{nullptr};
static stream stream0_{stream0_underlying_};

static const stream* default_stream_ = &stream0_;

Expand Down
2 changes: 1 addition & 1 deletion pluto/src/pluto/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class stream {
using stream_t = void*;

public:
explicit stream(stream_t);
explicit stream(stream_t&);
stream();

[[nodiscard]] stream_t value() const { return *stream_; }
Expand Down

0 comments on commit 45b8340

Please sign in to comment.