beagleboard / bonescript

Scripting tools for the BeagleBoard and BeagleBone
http://beagleboard.org
MIT License
32 stars 9 forks source link

i2cReadByte() Segmentation Fault #56

Open mzwtjp opened 5 years ago

mzwtjp commented 5 years ago

I am using i2c module from bonescript, on PocketBeagle. I am seeing sometimes readByte(i2cReadByte in BoneScript) causes Segmentation Fault in its native code.

I printf debugged and by following change the problem seems to be gone. The issue happens when you have read error (-1 is returned from i2c_smbus_read_byte()).

Note sure this is bonescript issue or i2c module issue.

--- i2c.cc.orig 2018-11-05 13:31:01.892701107 +0000
+++ i2c.cc.new  2018-11-08 08:41:40.050789179 +0000
@@ -127,7 +127,7 @@ void Read(const Nan::FunctionCallbackInf
 void ReadByte(const Nan::FunctionCallbackInfo<v8::Value>& info) {
   Nan::HandleScope scope;

-  Local<Value> data; 
+  Local<Value> data = Nan::New<Value>(Nan::Null());
   Local<Value> err = Nan::New<Value>(Nan::Null());

   int32_t res = i2c_smbus_read_byte(fd);
@@ -292,4 +292,4 @@ void Init(Handle<Object> exports) {

 }
rzr commented 5 years ago

May this patch be forwarded upstream ?