From dfdc98dd9959e8cb0472eecae1b15b839709939e Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Mon, 1 Feb 2016 17:56:15 +0100 Subject: [PATCH] Fix string length computation in iotjs::WrapEval The iotjs::String constructor automatically allocates at least size+1 bytes for the data (that +1 byte for the terminating zero), so there is no need for the +1 on the caller side. Moreover, strcpy can work just as fine as strcat in this case, since caller knows where the first string ends, so there is no need to make strcat figure that out. IoT.js-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu --- src/iotjs_module_process.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/iotjs_module_process.cpp b/src/iotjs_module_process.cpp index 82a5b7fc2f..d51407aded 100644 --- a/src/iotjs_module_process.cpp +++ b/src/iotjs_module_process.cpp @@ -130,10 +130,10 @@ static JResult WrapEval(const char* source) { int len2 = strlen(source); int len3 = strlen(wrapper[1]); - String code("", len1 + len2 + len3 + 1); + String code(NULL, len1 + len2 + len3); strcpy(code.data(), wrapper[0]); - strcat(code.data() + len1, source); - strcat(code.data() + len1 + len2, wrapper[1]); + strcpy(code.data() + len1, source); + strcpy(code.data() + len1 + len2, wrapper[1]); return JObject::Eval(code); }