From c09febc4d81ddb3be971917c5bd6b0d3b31c43ec Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 14 Oct 2020 13:50:52 +0200 Subject: [PATCH] examples/events/EventsExample.cpp: store std::string instead of char pointer. Some compilers (ehm, microsoft) returns a temporary variable for event.key.getKeyName() that is only valid during the statement and not scope. Fix this by storing std::string instead. So the object's lifetime is the entire if statement. --- examples/events/EventsExample.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/events/EventsExample.cpp b/examples/events/EventsExample.cpp index d9859aa..0538d26 100644 --- a/examples/events/EventsExample.cpp +++ b/examples/events/EventsExample.cpp @@ -11,9 +11,9 @@ void EventsExample::init() void EventsExample::onEvent(const sp::Event& event) { if (event.type == sp::Event::Key) { - const char* name = event.key.getKeyName().c_str(); + std::string name = event.key.getKeyName(); const char* pressed = event.key.pressed ? "pressed" : "released"; - sp::Log::info("Key: %s %s", name, pressed); + sp::Log::info("Key: %s %s", name.c_str(), pressed); } }