Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
2b4c3576
Commit
2b4c3576
authored
Aug 27, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hdf5: fix atread(string)
no need to append null-terminated symbol
parent
b7fa9697
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
hdf5.cpp
modules/hdf/src/hdf5.cpp
+5
-2
test_hdf5.cpp
modules/hdf/test/test_hdf5.cpp
+21
-3
No files found.
modules/hdf/src/hdf5.cpp
View file @
2b4c3576
...
...
@@ -441,10 +441,13 @@ void HDF5Impl::atread(String* value, const String& atlabel)
CV_Error_
(
Error
::
StsInternal
,
(
"Attribute '%s' is not of string type!"
,
atlabel
.
c_str
()));
}
size_t
size
=
H5Tget_size
(
atype
);
*
value
=
String
(
size
,
0
);
// allocate space
AutoBuffer
<
char
>
buf
(
size
);
hid_t
atype_mem
=
H5Tget_native_type
(
atype
,
H5T_DIR_ASCEND
);
H5Aread
(
attr
,
atype_mem
,
const_cast
<
char
*>
(
value
->
c_str
()));
H5Aread
(
attr
,
atype_mem
,
buf
.
data
());
if
(
size
>
0
&&
buf
[
size
-
1
]
==
'\0'
)
size
--
;
value
->
assign
(
buf
.
data
(),
size
);
H5Tclose
(
atype_mem
);
H5Tclose
(
atype
);
...
...
modules/hdf/test/test_hdf5.cpp
View file @
2b4c3576
...
...
@@ -284,9 +284,27 @@ TEST_F(HDF5_Test, test_attribute_String)
m_hdf_io
->
atwrite
(
attr_value
,
attr_name
);
String
expected_attr_value
;
m_hdf_io
->
atread
(
&
expected_attr_value
,
attr_name
);
EXPECT_EQ
(
attr_value
.
compare
(
expected_attr_value
),
0
);
String
got_attr_value
;
m_hdf_io
->
atread
(
&
got_attr_value
,
attr_name
);
EXPECT_EQ
(
attr_value
,
got_attr_value
);
m_hdf_io
->
close
();
}
TEST_F
(
HDF5_Test
,
test_attribute_String_empty
)
{
reset
();
String
attr_name
=
"test-empty-string"
;
String
attr_value
;
m_hdf_io
=
hdf
::
open
(
m_filename
);
m_hdf_io
->
atwrite
(
attr_value
,
attr_name
);
String
got_attr_value
;
m_hdf_io
->
atread
(
&
got_attr_value
,
attr_name
);
EXPECT_EQ
(
attr_value
,
got_attr_value
);
m_hdf_io
->
close
();
}
...
...
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