Fix use of dead temporary strings in completions

This commit is contained in:
Maxime Coste 2016-02-10 13:33:49 +00:00
parent 8d37a716fb
commit 8701a53252
4 changed files with 14 additions and 3 deletions

View File

@ -175,7 +175,10 @@ void ClientManager::redraw_clients() const
CandidateList ClientManager::complete_client_name(StringView prefix,
ByteCount cursor_pos) const
{
auto c = transformed(m_clients, [](const std::unique_ptr<Client>& c){ return c->context().name(); });
auto c = transformed(m_clients,
[](const std::unique_ptr<Client>& c) -> const String&
{ return c->context().name(); });
return complete(prefix, cursor_pos, c);
}

View File

@ -60,7 +60,10 @@ const PerArgumentCommandCompleter filename_completer({
static CandidateList complete_buffer_name(StringView prefix, ByteCount cursor_pos)
{
auto c = transformed(BufferManager::instance(), [](const SafePtr<Buffer>& b){ return b->display_name(); });
auto c = transformed(BufferManager::instance(),
[](const SafePtr<Buffer>& b) -> const String&
{ return b->display_name(); });
return complete(prefix, cursor_pos, c);
}

View File

@ -59,6 +59,10 @@ template<typename Container>
CandidateList complete(StringView prefix, ByteCount cursor_pos,
const Container& container)
{
using std::begin;
static_assert(not std::is_same<decltype(*begin(container)), String>::value,
"complete require long lived strings");
prefix = prefix.substr(0, cursor_pos);
Vector<RankedMatch> matches;
for (const auto& str : container)

View File

@ -97,7 +97,8 @@ CandidateList FaceRegistry::complete_alias_name(StringView prefix,
using ValueType = std::pair<String, FaceOrAlias>;
return complete(prefix, cursor_pos,
transformed(m_aliases,
[](const ValueType& v){ return v.first; }));
[](const ValueType& v) -> const String&
{ return v.first; }));
}
FaceRegistry::FaceRegistry()