From f85fc12fc8392c1377fbf4d7eb7a0bd66854b289 Mon Sep 17 00:00:00 2001 From: jaynus Date: Tue, 14 Apr 2015 14:24:50 -0700 Subject: [PATCH] string overflow fix, perf fix for pass-by-ref. --- extensions/breakLine/ace_breakLine.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/extensions/breakLine/ace_breakLine.cpp b/extensions/breakLine/ace_breakLine.cpp index 74a32cc66d..fb5775b861 100644 --- a/extensions/breakLine/ace_breakLine.cpp +++ b/extensions/breakLine/ace_breakLine.cpp @@ -19,13 +19,13 @@ #define MAXCHARACTERS 14 -static char version[] = "1.0"; +static char VERSION[] = "1.0"; extern "C" { __declspec (dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function); }; -std::vector splitString(std::string input) { +std::vector splitString(const std::string & input) { std::istringstream ss(input); std::string token; @@ -38,10 +38,10 @@ std::vector splitString(std::string input) { } std::string addLineBreaks(const std::vector &words) { - std::stringstream sstream; int numChar = 0; int i = 0; + while (i < words.size()) { if (numChar == 0) { sstream << words[i]; @@ -58,6 +58,7 @@ std::string addLineBreaks(const std::vector &words) { } } } + return sstream.str(); } @@ -66,12 +67,10 @@ std::string addLineBreaks(const std::vector &words) { #pragma warning( disable : 4996 ) void __stdcall RVExtension(char *output, int outputSize, const char *function) { - //strncpy(output, function, outputSize); - if (!strcmp(function, "version")) { - strncpy(output, version, outputSize); + strncpy(output, VERSION, outputSize); } else { - strcpy(output, addLineBreaks(splitString(function)).c_str()); + strncpy(output, addLineBreaks(splitString(function)).c_str(), outputSize); output[outputSize - 1] = '\0'; } }