Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
96edb270
Commit
96edb270
authored
Jul 16, 2016
by
Rostislav Vasilikhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed memory corruption when normal dist. params have less channels than target matrix; test added
parent
a2921fde
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
rand.cpp
modules/core/src/rand.cpp
+7
-7
test_rand.cpp
modules/core/test/test_rand.cpp
+17
-0
No files found.
modules/core/src/rand.cpp
View file @
96edb270
...
@@ -624,7 +624,7 @@ void RNG::fill( InputOutputArray _mat, int disttype,
...
@@ -624,7 +624,7 @@ void RNG::fill( InputOutputArray _mat, int disttype,
int
ptype
=
depth
==
CV_64F
?
CV_64F
:
CV_32F
;
int
ptype
=
depth
==
CV_64F
?
CV_64F
:
CV_32F
;
int
esz
=
(
int
)
CV_ELEM_SIZE
(
ptype
);
int
esz
=
(
int
)
CV_ELEM_SIZE
(
ptype
);
if
(
_param1
.
isContinuous
()
&&
_param1
.
type
()
==
ptype
)
if
(
_param1
.
isContinuous
()
&&
_param1
.
type
()
==
ptype
&&
n1
>=
cn
)
mean
=
_param1
.
ptr
();
mean
=
_param1
.
ptr
();
else
else
{
{
...
@@ -637,18 +637,18 @@ void RNG::fill( InputOutputArray _mat, int disttype,
...
@@ -637,18 +637,18 @@ void RNG::fill( InputOutputArray _mat, int disttype,
for
(
j
=
n1
*
esz
;
j
<
cn
*
esz
;
j
++
)
for
(
j
=
n1
*
esz
;
j
<
cn
*
esz
;
j
++
)
mean
[
j
]
=
mean
[
j
-
n1
*
esz
];
mean
[
j
]
=
mean
[
j
-
n1
*
esz
];
if
(
_param2
.
isContinuous
()
&&
_param2
.
type
()
==
ptype
)
if
(
_param2
.
isContinuous
()
&&
_param2
.
type
()
==
ptype
&&
n2
>=
cn
)
stddev
=
_param2
.
ptr
();
stddev
=
_param2
.
ptr
();
else
else
{
{
Mat
tmp
(
_param2
.
size
(),
ptype
,
parambuf
+
cn
);
Mat
tmp
(
_param2
.
size
(),
ptype
,
parambuf
+
MAX
(
n1
,
cn
)
);
_param2
.
convertTo
(
tmp
,
ptype
);
_param2
.
convertTo
(
tmp
,
ptype
);
stddev
=
(
uchar
*
)(
parambuf
+
cn
);
stddev
=
(
uchar
*
)(
parambuf
+
MAX
(
n1
,
cn
)
);
}
}
if
(
n
1
<
cn
)
if
(
n
2
<
cn
)
for
(
j
=
n
1
*
esz
;
j
<
cn
*
esz
;
j
++
)
for
(
j
=
n
2
*
esz
;
j
<
cn
*
esz
;
j
++
)
stddev
[
j
]
=
stddev
[
j
-
n
1
*
esz
];
stddev
[
j
]
=
stddev
[
j
-
n
2
*
esz
];
stdmtx
=
_param2
.
rows
==
cn
&&
_param2
.
cols
==
cn
;
stdmtx
=
_param2
.
rows
==
cn
&&
_param2
.
cols
==
cn
;
scaleFunc
=
randnScaleTab
[
depth
];
scaleFunc
=
randnScaleTab
[
depth
];
...
...
modules/core/test/test_rand.cpp
View file @
96edb270
...
@@ -365,3 +365,20 @@ TEST(Core_RNG_MT19937, regression)
...
@@ -365,3 +365,20 @@ TEST(Core_RNG_MT19937, regression)
ASSERT_EQ
(
expected
[
i
],
actual
[
i
]);
ASSERT_EQ
(
expected
[
i
],
actual
[
i
]);
}
}
}
}
TEST
(
Core_Rand
,
Regression_Stack_Corruption
)
{
int
bufsz
=
128
;
//enough for 14 doubles
AutoBuffer
<
uchar
>
buffer
(
bufsz
);
size_t
offset
=
0
;
cv
::
Mat_
<
cv
::
Point2d
>
x
(
2
,
3
,
(
cv
::
Point2d
*
)(
buffer
+
offset
));
offset
+=
x
.
total
()
*
x
.
elemSize
();
double
&
param1
=
*
(
double
*
)(
buffer
+
offset
);
offset
+=
sizeof
(
double
);
double
&
param2
=
*
(
double
*
)(
buffer
+
offset
);
offset
+=
sizeof
(
double
);
param1
=
-
9
;
param2
=
2
;
cv
::
theRNG
().
fill
(
x
,
cv
::
RNG
::
NORMAL
,
param1
,
param2
);
ASSERT_EQ
(
param1
,
-
9
);
ASSERT_EQ
(
param2
,
2
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment