Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:goupilmtos:games
pinball
0001-Do-not-return-pointer-to-temporary.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0001-Do-not-return-pointer-to-temporary.patch of Package pinball
From 6257513fa8fe8504da1c637e10cf51f2b738a292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de> Date: Thu, 14 Dec 2017 02:49:00 +0100 Subject: [PATCH] Do not return pointer to temporary string text is only valid until the scope is left, so text.c_str() is an invalid reference to the heap (in case of SSO). --- src/Pinball.cpp | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Pinball.cpp b/src/Pinball.cpp index 9d89fcc..8a914c2 100755 --- a/src/Pinball.cpp +++ b/src/Pinball.cpp @@ -7,10 +7,7 @@ email : henqvist@excite.com ***************************************************************************/ -#include <fstream> #include <string> -//#include <sstream> -#include <strstream> #include <iostream> #include <sys/stat.h> @@ -141,27 +137,31 @@ protected: return EM_MENU_NOP; } const char * getText() { - ostrstream stm; - stm.clear(); - string name(m_Name); - const char * keyname = Config::getInstance()->getKeyCommonName(Config::getInstance()->getKey(name)); - string key; - if (keyname != NULL) { - key = string(keyname); - } else { - key = string("unknown"); - } - name = name + ":"; - while (name.size() < 12) { - name = name + " "; - } - while (key.size() < 12) { - key = " " + key; - } - stm << name << key << '\0'; - string text = stm.str(); - return text.c_str(); + EMKey key = Config::getInstance()->getKey(m_Name); + if (key == m_Key) + return m_Label.c_str(); + + string label(m_Name); + label.reserve(24); + + string keyname = Config::getInstance()->getKeyCommonName(key); + if (!keyname.size()) + keyname = "unknown"; + + label += ":"; + size_t filllen = 24 - label.size() - keyname.size(); + label += string(filllen , ' '); + + label += keyname; + m_Label = label; + m_Key = key; + + return m_Label.c_str(); } + +private: + string m_Label; + EMKey m_Key; }; -- 2.15.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor