1
0
Fork 0
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:
ser1zw 2015-01-02 02:25:12 +09:00
parent 13a8113c48
commit 32ff552078
2 changed files with 4 additions and 2 deletions

View file

@ -193,6 +193,9 @@ rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
rb_scan_args(argc, argv, "12", &images, &accumulate, &mask);
Check_Type(images, T_ARRAY);
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);
VALUE* images_ptr = RARRAY_PTR(images);
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) {
raise_cverror(e);
}
return self;
}

View file

@ -74,7 +74,7 @@ class TestCvHistogram < OpenCVTestCase
assert_raise(TypeError) {
@hist1.calc_hist([img], true, DUMMY_OBJ)
}
assert_raise(CvStsBadArg) {
assert_raise(ArgumentError) {
@hist1.calc_hist([])
}
end