iotjs icon indicating copy to clipboard operation
iotjs copied to clipboard

Size of script code buffer

Open ruben-ayrapetyan opened this issue 11 years ago • 5 comments

Hello.

Code buffer size argument of jerry_api_eval in JHANDLER_FUNCTION(Compile, handler) and JHANDLER_FUNCTION(CompileNativePtr, handler) is calculated incorrectly : sizeof (code) equals to size of pointer, not buffer size.

Maybe, this could be fixed with the following:

diff --git a/src/iotjs_module_process.cpp b/src/iotjs_module_process.cpp
index 282bc09..bd73a3f 100644
--- a/src/iotjs_module_process.cpp
+++ b/src/iotjs_module_process.cpp
@@ -87,7 +87,7 @@ JHANDLER_FUNCTION(Compile, handler){

   char* code = handler.GetArg(0)->GetCString();
   JRawValueType ret_val;
-  jerry_api_eval(code,sizeof(code),true,false,&ret_val);
+  jerry_api_eval(code,strlen(code),true,false,&ret_val);
   JObject::ReleaseCString(code);

   JObject ret(&ret_val);
@@ -116,7 +116,7 @@ JHANDLER_FUNCTION(CompileNativePtr, handler){
   strcat(code,wrapper[1]);

   JRawValueType ret_val;
-  jerry_api_eval(code,sizeof(code),true,false,&ret_val);
+  jerry_api_eval(code,len,true,false,&ret_val);
   JObject::ReleaseCString(code);

   JObject ret(&ret_val);

ruben-ayrapetyan avatar May 29 '15 08:05 ruben-ayrapetyan

@ruben-ayrapetyan Thanks for pointing it out.

ILyoan avatar May 31 '15 13:05 ILyoan

@ruben-ayrapetyan Thank you. I will fix it

chunseoklee avatar Jun 01 '15 01:06 chunseoklee

Is #47 probably relevant to this?

ILyoan avatar Jun 01 '15 05:06 ILyoan

I dont think so. It seems like second argument of jerry_api_eval function is not used in jerry_api_eval. Especially ecma_new_ecma_string(source_p, source_size); function inside jerry_api_eval do not use source_size parameter

chunseoklee avatar Jun 01 '15 09:06 chunseoklee

@chunseoklee Thanks Close this issue as #60 landed.

ILyoan avatar Jun 01 '15 09:06 ILyoan