Skip to content

Commit 8701a53

Browse files
committed
Fix use of dead temporary strings in completions
1 parent 8d37a71 commit 8701a53

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/client_manager.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ void ClientManager::redraw_clients() const
175175
CandidateList ClientManager::complete_client_name(StringView prefix,
176176
ByteCount cursor_pos) const
177177
{
178-
auto c = transformed(m_clients, [](const std::unique_ptr<Client>& c){ return c->context().name(); });
178+
auto c = transformed(m_clients,
179+
[](const std::unique_ptr<Client>& c) -> const String&
180+
{ return c->context().name(); });
181+
179182
return complete(prefix, cursor_pos, c);
180183
}
181184

src/commands.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ const PerArgumentCommandCompleter filename_completer({
6060

6161
static CandidateList complete_buffer_name(StringView prefix, ByteCount cursor_pos)
6262
{
63-
auto c = transformed(BufferManager::instance(), [](const SafePtr<Buffer>& b){ return b->display_name(); });
63+
auto c = transformed(BufferManager::instance(),
64+
[](const SafePtr<Buffer>& b) -> const String&
65+
{ return b->display_name(); });
66+
6467
return complete(prefix, cursor_pos, c);
6568
}
6669

src/completion.hh

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ template<typename Container>
5959
CandidateList complete(StringView prefix, ByteCount cursor_pos,
6060
const Container& container)
6161
{
62+
using std::begin;
63+
static_assert(not std::is_same<decltype(*begin(container)), String>::value,
64+
"complete require long lived strings");
65+
6266
prefix = prefix.substr(0, cursor_pos);
6367
Vector<RankedMatch> matches;
6468
for (const auto& str : container)

src/face_registry.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ CandidateList FaceRegistry::complete_alias_name(StringView prefix,
9797
using ValueType = std::pair<String, FaceOrAlias>;
9898
return complete(prefix, cursor_pos,
9999
transformed(m_aliases,
100-
[](const ValueType& v){ return v.first; }));
100+
[](const ValueType& v) -> const String&
101+
{ return v.first; }));
101102
}
102103

103104
FaceRegistry::FaceRegistry()

0 commit comments

Comments
 (0)