mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
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.
This commit is contained in:
parent
a5c5c3b4c9
commit
73cddc81de
@ -7,7 +7,7 @@ v8::Persistent<FunctionTemplate> Matrix::constructor;
|
||||
|
||||
cv::Scalar setColor(Local<Object> objColor);
|
||||
cv::Point setPoint(Local<Object> objPoint);
|
||||
cv::Rect* setRect(Local<Object> objRect);
|
||||
cv::Rect* setRect(Local<Object> objRect, cv::Rect &result);
|
||||
|
||||
void
|
||||
Matrix::Init(Handle<Object> target) {
|
||||
@ -1310,7 +1310,7 @@ cv::Point setPoint(Local<Object> objPoint) {
|
||||
return cv::Point( objPoint->Get(0)->IntegerValue(), objPoint->Get(1)->IntegerValue() );
|
||||
}
|
||||
|
||||
cv::Rect* setRect(Local<Object> objRect) {
|
||||
cv::Rect* setRect(Local<Object> 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<Object> objRect) {
|
||||
|
||||
Local<Object> point = objRect->Get(0)->ToObject();
|
||||
Local<Object> 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<Object> obj = args[0]->ToObject();
|
||||
cv::Rect rect;
|
||||
|
||||
int ret = cv::floodFill(self->mat, setPoint(obj->Get(NanNew<String>("seedPoint"))->ToObject())
|
||||
, setColor(obj->Get(NanNew<String>("newColor"))->ToObject())
|
||||
, obj->Get(NanNew<String>("rect"))->IsUndefined() ? 0 : setRect(obj->Get(NanNew<String>("rect"))->ToObject())
|
||||
, obj->Get(NanNew<String>("rect"))->IsUndefined() ? 0 : setRect(obj->Get(NanNew<String>("rect"))->ToObject(), rect)
|
||||
, setColor(obj->Get(NanNew<String>("loDiff"))->ToObject())
|
||||
, setColor(obj->Get(NanNew<String>("upDiff"))->ToObject())
|
||||
, 4 );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user