From 73cddc81de423cc44943169aaf737ebd59d99ac7 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Fri, 16 Jan 2015 12:11:05 -0800 Subject: [PATCH 1/2] In setRect(), don't return a pointer to stack memory Noticed a compiler warning for this during build, and the code looks like the sort of thing that may often work accidentally, but is not at all guaranteed to work. This is the simplest fix I could imagine; keep the logic about whether to return NULL or not in setRect(), but pass it a reference to some memory in the caller's stack frame to use for the result. This fixes the warning, but I haven't had a chance to verify functionality. --- src/Matrix.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index 4cad417..fbee02c 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -7,7 +7,7 @@ v8::Persistent Matrix::constructor; cv::Scalar setColor(Local objColor); cv::Point setPoint(Local objPoint); -cv::Rect* setRect(Local objRect); +cv::Rect* setRect(Local objRect, cv::Rect &result); void Matrix::Init(Handle target) { @@ -1310,7 +1310,7 @@ cv::Point setPoint(Local objPoint) { return cv::Point( objPoint->Get(0)->IntegerValue(), objPoint->Get(1)->IntegerValue() ); } -cv::Rect* setRect(Local objRect) { +cv::Rect* setRect(Local objRect, cv::Rect &result) { if(!objRect->IsArray() || !objRect->Get(0)->IsArray() || !objRect->Get(0)->IsArray() ){ printf("error"); @@ -1319,14 +1319,13 @@ cv::Rect* setRect(Local objRect) { Local point = objRect->Get(0)->ToObject(); Local size = objRect->Get(1)->ToObject(); - cv::Rect ret; - ret.x = point->Get(0)->IntegerValue(); - ret.y = point->Get(1)->IntegerValue(); - ret.width = size->Get(0)->IntegerValue(); - ret.height = size->Get(1)->IntegerValue(); + result.x = point->Get(0)->IntegerValue(); + result.y = point->Get(1)->IntegerValue(); + result.width = size->Get(0)->IntegerValue(); + result.height = size->Get(1)->IntegerValue(); - return (cv::Rect*) &ret; + return &result; } @@ -1714,10 +1713,11 @@ NAN_METHOD(Matrix::FloodFill){ Local obj = args[0]->ToObject(); + cv::Rect rect; int ret = cv::floodFill(self->mat, setPoint(obj->Get(NanNew("seedPoint"))->ToObject()) , setColor(obj->Get(NanNew("newColor"))->ToObject()) - , obj->Get(NanNew("rect"))->IsUndefined() ? 0 : setRect(obj->Get(NanNew("rect"))->ToObject()) + , obj->Get(NanNew("rect"))->IsUndefined() ? 0 : setRect(obj->Get(NanNew("rect"))->ToObject(), rect) , setColor(obj->Get(NanNew("loDiff"))->ToObject()) , setColor(obj->Get(NanNew("upDiff"))->ToObject()) , 4 ); From 85c3a90db71d8498c3728e3b4244da0fd20f6737 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Fri, 16 Jan 2015 12:13:45 -0800 Subject: [PATCH 2/2] Fix compile errors with ambiguous signedness in NanNew param This fixes two instances of a compile error I'd been getting with OpenCV 2.4.9 (via Homebrew) on Mac OS: ../node_modules/nan/nan_new.h:184:10: error: call to 'New' is ambiguous return NanIntern::Factory::New(arg0); ^~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/Matrix.cc:453:51: note: in instantiation of function template specialization 'NanNew' requested here v8::Handle constructorArgs[3] = {buf, NanNew(vec.size()), NanNew(0)}; ^ ../node_modules/nan/nan_new.h:86:26: note: candidate function static inline return_t New(int32_t value); ^ ../node_modules/nan/nan_new.h:87:26: note: candidate function static inline return_t New(uint32_t value); --- src/Matrix.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index fbee02c..91faa07 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -452,7 +452,7 @@ NAN_METHOD(Matrix::ToBuffer){ v8::Local globalObj = NanGetCurrentContext()->Global(); v8::Local bufferConstructor = v8::Local::Cast(globalObj->Get(NanNew("Buffer"))); - v8::Handle constructorArgs[3] = {buf, NanNew(vec.size()), NanNew(0)}; + v8::Handle constructorArgs[3] = {buf, NanNew((unsigned)vec.size()), NanNew(0)}; v8::Local actualBuffer = bufferConstructor->NewInstance(3, constructorArgs); NanReturnValue(actualBuffer); @@ -485,7 +485,7 @@ class AsyncToBufferWorker : public NanAsyncWorker { v8::Local globalObj = NanGetCurrentContext()->Global(); v8::Local bufferConstructor = v8::Local::Cast(globalObj->Get(NanNew("Buffer"))); - v8::Handle constructorArgs[3] = {buf, NanNew(res.size()), NanNew(0)}; + v8::Handle constructorArgs[3] = {buf, NanNew((unsigned)res.size()), NanNew(0)}; v8::Local actualBuffer = bufferConstructor->NewInstance(3, constructorArgs);