diff options
author | Colin Snover | 2017-12-04 19:44:45 -0600 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-18 16:30:05 +0200 |
commit | b9a649c3e167bc8176d796db77a6b8449a731250 (patch) | |
tree | 0e11ebd6c56852d396bff0ee912a5aef50032aa9 /gui | |
parent | 08314ae61f9ce4efd8ecc221b1a6aec522d82ae8 (diff) | |
download | scummvm-rg350-b9a649c3e167bc8176d796db77a6b8449a731250.tar.gz scummvm-rg350-b9a649c3e167bc8176d796db77a6b8449a731250.tar.bz2 scummvm-rg350-b9a649c3e167bc8176d796db77a6b8449a731250.zip |
GUI: Replace use of strdup with Common::String
strdup is a POSIX API, not an ANSI C API. It is not available with
-std=c++11 on newlib-based systems, and VS 2015 will throw errors
unless it is #defined to alias to _strdup or unless deprecation
warnings are turned off (which is not a good idea in general).
Common::String is a safer and potentially faster (due to small
string optimisation) alternative, so prefer it instead.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/debugger.cpp | 22 | ||||
-rw-r--r-- | gui/debugger.h | 5 |
2 files changed, 10 insertions, 17 deletions
diff --git a/gui/debugger.cpp b/gui/debugger.cpp index 9b559d8bb9..febd10300a 100644 --- a/gui/debugger.cpp +++ b/gui/debugger.cpp @@ -51,7 +51,6 @@ namespace GUI { Debugger::Debugger() { _frameCountdown = 0; _isActive = false; - _errStr = NULL; _firstTime = true; #ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER _debuggerDialog = new GUI::ConsoleDialog(1.0f, 0.67f); @@ -159,8 +158,7 @@ void Debugger::attach(const char *entry) { g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true); // Set error string (if any) - free(_errStr); - _errStr = entry ? strdup(entry) : 0; + _errStr = entry ? entry : ""; // Reset frame countdown (i.e. attach immediately) _frameCountdown = 1; @@ -224,10 +222,9 @@ void Debugger::enter() { _firstTime = false; } - if (_errStr) { - debugPrintf("ERROR: %s\n\n", _errStr); - free(_errStr); - _errStr = NULL; + if (_errStr.size()) { + debugPrintf("ERROR: %s\n\n", _errStr.c_str()); + _errStr.clear(); } _debuggerDialog->runModal(); @@ -293,19 +290,16 @@ bool Debugger::parseCommand(const char *inputOrig) { const char *param[256]; // Parse out any params - // One of the rare occasions using strdup is OK, since splitCommands needs to modify it - char *input = strdup(inputOrig); + Common::String input(inputOrig); splitCommand(input, num_params, ¶m[0]); if (num_params == 0) { - free(input); return true; } // Handle commands first bool result; if (handleCommand(num_params, param, result)) { - free(input); return result; } @@ -390,23 +384,21 @@ bool Debugger::parseCommand(const char *inputOrig) { } } - free(input); return true; } } debugPrintf("Unknown command or variable\n"); - free(input); return true; } -void Debugger::splitCommand(char *input, int &argc, const char **argv) { +void Debugger::splitCommand(Common::String &input, int &argc, const char **argv) { byte c; enum states { DULL, IN_WORD, IN_STRING } state = DULL; const char *paramStart = nullptr; argc = 0; - for (char *p = input; *p; ++p) { + for (Common::String::iterator p = input.begin(); *p; ++p) { c = (byte)*p; switch (state) { diff --git a/gui/debugger.h b/gui/debugger.h index b12bd2761e..0f4982a755 100644 --- a/gui/debugger.h +++ b/gui/debugger.h @@ -28,6 +28,7 @@ #include "common/hashmap.h" #include "common/hash-str.h" #include "common/array.h" +#include "common/str.h" #include "common/str-array.h" namespace GUI { @@ -161,7 +162,7 @@ private: */ bool _isActive; - char *_errStr; + Common::String _errStr; /** * Initially true, set to false when Debugger::enter is called @@ -208,7 +209,7 @@ private: * Splits up the input into individual parameters * @remarks Adapted from code provided by torek on StackOverflow */ - void splitCommand(char *input, int &argc, const char **argv); + void splitCommand(Common::String &input, int &argc, const char **argv); bool parseCommand(const char *input); bool tabComplete(const char *input, Common::String &completion) const; |