From cd6e185d65089c017dc534de0aa124a502254dd0 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 14 Jul 2016 22:19:10 +0300 Subject: [PATCH] Fix issue where the command arguments would always fallback to string because the identified variable was not set to true. Fix issue with boolean argument types where more data then necessary was copied from the argument string which could cause it to fail if anything other than the null terminator was following the boolean argument. Few other minor adjustments to keep the code style consistent. --- source/Command.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/Command.cpp b/source/Command.cpp index 6c1a9908..1d4f359e 100644 --- a/source/Command.cpp +++ b/source/Command.cpp @@ -695,7 +695,7 @@ bool Controller::Parse(Context & ctx) // Get the object from the stack and add it to the argument list along with it's type ctx.mArgv.emplace_back(CMDARG_INTEGER, Var< Object >(DefaultVM::Get(), -1).value); // We've identified the correct value type - identified = false; + identified = true; } } // Attempt to treat the value as an floating point number if possible @@ -719,7 +719,7 @@ bool Controller::Parse(Context & ctx) // Get the object from the stack and add it to the argument list along with it's type ctx.mArgv.emplace_back(CMDARG_FLOAT, Var< Object >(DefaultVM::Get(), -1).value); // We've identified the correct value type - identified = false; + identified = true; } } @@ -728,13 +728,16 @@ bool Controller::Parse(Context & ctx) { // Allocate memory for enough data to form a boolean value CharT lc[6]; + // Don't modify the original string or buffer pointer + CStr bptr = lc; + CSStr sptr = str; // Fill the temporary buffer with data from the internal buffer - std::snprintf(lc, 6, "%.5s", str); - // Convert all characters to lowercase - for (Uint32 i = 0; i < 5; ++i) + for (; sptr < end; ++sptr, ++bptr) { - lc[i] = std::tolower(lc[i]); + *bptr = std::tolower(*sptr); } + // Terminate the copied string portion + *bptr = '\0'; // Remember the current stack size const StackGuard sg; // Is this a boolean true value? @@ -959,7 +962,7 @@ void Listener::ProcSpec(CSStr str) else if (*str != ',') { // Ignore non-alphabetic characters - while (*str != 0 && !isalpha(*str)) + while (*str != '\0' && !std::isalpha(*str)) { ++str; }