diff --git a/ext/opencv/cvhistogram.cpp b/ext/opencv/cvhistogram.cpp index 6e3ca33..1c2449e 100644 --- a/ext/opencv/cvhistogram.cpp +++ b/ext/opencv/cvhistogram.cpp @@ -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; } diff --git a/test/test_cvhistogram.rb b/test/test_cvhistogram.rb index 8734d4e..aa58353 100755 --- a/test/test_cvhistogram.rb +++ b/test/test_cvhistogram.rb @@ -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