Skip to content
This repository was archived by the owner on Dec 3, 2021. It is now read-only.

Commit 2fb60d0

Browse files
committed
modified CvMat#snake_image to check sizes of alpha, beta, gamma when coeff_usage == CV_ARRAY
1 parent 684692a commit 2fb60d0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

ext/cvmat.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4826,14 +4826,19 @@ rb_snake_image(int argc, VALUE *argv, VALUE self)
48264826
IplImage stub;
48274827
int i;
48284828
if (coeff == CV_VALUE) {
4829-
a = ALLOCA_N(float, 1);
4830-
a[0] = (float)NUM2DBL(alpha);
4831-
b = ALLOCA_N(float, 1);
4832-
b[0] = (float)NUM2DBL(beta);
4833-
c = ALLOCA_N(float, 1);
4834-
c[0] = (float)NUM2DBL(gamma);
4829+
float buff_a, buff_b, buff_c;
4830+
buff_a = (float)NUM2DBL(alpha);
4831+
buff_b = (float)NUM2DBL(beta);
4832+
buff_c = (float)NUM2DBL(gamma);
4833+
a = &buff_a;
4834+
b = &buff_b;
4835+
c = &buff_c;
48354836
}
48364837
else { // CV_ARRAY
4838+
if ((RARRAY_LEN(alpha) != length) ||
4839+
(RARRAY_LEN(beta) != length) ||
4840+
(RARRAY_LEN(gamma) != length))
4841+
rb_raise(rb_eArgError, "alpha, beta, gamma should be same size of points");
48374842
a = ALLOCA_N(float, length);
48384843
b = ALLOCA_N(float, length);
48394844
c = ALLOCA_N(float, length);

test/test_cvmat_imageprocessing.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,10 @@ def test_snake_image
16301630
assert_raise(TypeError) {
16311631
mat.snake_image(points, alpha, arr_beta, gamma, size, term_criteria)
16321632
}
1633+
1634+
assert_raise(ArgumentError) {
1635+
mat.snake_image(points, arr_alpha[0 .. num_points / 2], arr_beta, arr_gamma, size, term_criteria)
1636+
}
16331637
end
16341638
end
16351639

0 commit comments

Comments
 (0)