From 8701a53252cbcd54e33ffe9f9257aadcde95c8aa Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 10 Feb 2016 13:33:49 +0000 Subject: [PATCH] Fix use of dead temporary strings in completions --- src/client_manager.cc | 5 ++++- src/commands.cc | 5 ++++- src/completion.hh | 4 ++++ src/face_registry.cc | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/client_manager.cc b/src/client_manager.cc index 540d18c7..d06e7259 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -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& c){ return c->context().name(); }); + auto c = transformed(m_clients, + [](const std::unique_ptr& c) -> const String& + { return c->context().name(); }); + return complete(prefix, cursor_pos, c); } diff --git a/src/commands.cc b/src/commands.cc index 0a34cd65..6304378d 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -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& b){ return b->display_name(); }); + auto c = transformed(BufferManager::instance(), + [](const SafePtr& b) -> const String& + { return b->display_name(); }); + return complete(prefix, cursor_pos, c); } diff --git a/src/completion.hh b/src/completion.hh index 47b08c73..1cc219c0 100644 --- a/src/completion.hh +++ b/src/completion.hh @@ -59,6 +59,10 @@ template CandidateList complete(StringView prefix, ByteCount cursor_pos, const Container& container) { + using std::begin; + static_assert(not std::is_same::value, + "complete require long lived strings"); + prefix = prefix.substr(0, cursor_pos); Vector matches; for (const auto& str : container) diff --git a/src/face_registry.cc b/src/face_registry.cc index cf404e63..53e93f78 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -97,7 +97,8 @@ CandidateList FaceRegistry::complete_alias_name(StringView prefix, using ValueType = std::pair; return complete(prefix, cursor_pos, transformed(m_aliases, - [](const ValueType& v){ return v.first; })); + [](const ValueType& v) -> const String& + { return v.first; })); } FaceRegistry::FaceRegistry()