mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
fix segfault of CvHistogram#calc_hist with an empty array
This commit is contained in:
parent
13a8113c48
commit
32ff552078
2 changed files with 4 additions and 2 deletions
|
@ -193,6 +193,9 @@ rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
|
||||||
rb_scan_args(argc, argv, "12", &images, &accumulate, &mask);
|
rb_scan_args(argc, argv, "12", &images, &accumulate, &mask);
|
||||||
Check_Type(images, T_ARRAY);
|
Check_Type(images, T_ARRAY);
|
||||||
int num_images = RARRAY_LEN(images);
|
int num_images = RARRAY_LEN(images);
|
||||||
|
if (num_images == 0) {
|
||||||
|
rb_raise(rb_eArgError, "One or more arrays are required.");
|
||||||
|
}
|
||||||
IplImage** img = ALLOCA_N(IplImage*, num_images);
|
IplImage** img = ALLOCA_N(IplImage*, num_images);
|
||||||
VALUE* images_ptr = RARRAY_PTR(images);
|
VALUE* images_ptr = RARRAY_PTR(images);
|
||||||
for (int i = 0; i < num_images; i++) {
|
for (int i = 0; i < num_images; i++) {
|
||||||
|
@ -205,7 +208,6 @@ rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
|
||||||
catch (cv::Exception& e) {
|
catch (cv::Exception& e) {
|
||||||
raise_cverror(e);
|
raise_cverror(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TestCvHistogram < OpenCVTestCase
|
||||||
assert_raise(TypeError) {
|
assert_raise(TypeError) {
|
||||||
@hist1.calc_hist([img], true, DUMMY_OBJ)
|
@hist1.calc_hist([img], true, DUMMY_OBJ)
|
||||||
}
|
}
|
||||||
assert_raise(CvStsBadArg) {
|
assert_raise(ArgumentError) {
|
||||||
@hist1.calc_hist([])
|
@hist1.calc_hist([])
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue