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
b0563ce3
Unverified
Commit
b0563ce3
authored
Mar 24, 2020
by
Alexander Alekhin
Committed by
GitHub
Mar 24, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16895 from alalek:fix_16823
parents
ef395c38
673eb2b0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
7 deletions
+75
-7
persistence.cpp
modules/core/src/persistence.cpp
+14
-7
test_io.cpp
modules/core/test/test_io.cpp
+61
-0
No files found.
modules/core/src/persistence.cpp
View file @
b0563ce3
...
...
@@ -407,14 +407,13 @@ public:
else
if
(
fmt
==
FileStorage
::
FORMAT_JSON
)
puts
(
"}
\n
"
);
}
closeFile
();
if
(
mem_mode
&&
out
)
{
*
out
=
cv
::
String
(
outbuf
.
begin
(),
outbuf
.
end
());
}
init
();
}
closeFile
();
init
();
}
void
analyze_file_name
(
const
std
::
string
&
file_name
,
std
::
vector
<
std
::
string
>&
params
)
...
...
@@ -1825,10 +1824,18 @@ FileStorage::~FileStorage()
bool
FileStorage
::
open
(
const
String
&
filename
,
int
flags
,
const
String
&
encoding
)
{
bool
ok
=
p
->
open
(
filename
.
c_str
(),
flags
,
encoding
.
c_str
());
if
(
ok
)
state
=
FileStorage
::
NAME_EXPECTED
+
FileStorage
::
INSIDE_MAP
;
return
ok
;
try
{
bool
ok
=
p
->
open
(
filename
.
c_str
(),
flags
,
encoding
.
c_str
());
if
(
ok
)
state
=
FileStorage
::
NAME_EXPECTED
+
FileStorage
::
INSIDE_MAP
;
return
ok
;
}
catch
(...)
{
release
();
throw
;
// re-throw
}
}
bool
FileStorage
::
isOpened
()
const
{
return
p
->
is_opened
;
}
...
...
modules/core/test/test_io.cpp
View file @
b0563ce3
...
...
@@ -1711,4 +1711,65 @@ TEST(Core_InputOutput, FileStorage_JSON_VeryLongLines)
}
}
TEST
(
Core_InputOutput
,
FileStorage_empty_16823
)
{
std
::
string
fname
=
tempfile
(
"test_fs_empty.yml"
);
{
// create empty file
std
::
ofstream
f
(
fname
.
c_str
(),
std
::
ios
::
out
);
}
try
{
FileStorage
fs
(
fname
,
FileStorage
::
READ
);
ADD_FAILURE
()
<<
"Exception must be thrown for empty file."
;
}
catch
(
const
cv
::
Exception
&
)
{
// expected way
// closed files can be checked manually through 'strace'
}
catch
(
const
std
::
exception
&
e
)
{
ADD_FAILURE
()
<<
"Unexpected exception: "
<<
e
.
what
();
}
catch
(...)
{
ADD_FAILURE
()
<<
"Unexpected unknown C++ exception"
;
}
EXPECT_EQ
(
0
,
remove
(
fname
.
c_str
()));
}
TEST
(
Core_InputOutput
,
FileStorage_open_empty_16823
)
{
std
::
string
fname
=
tempfile
(
"test_fs_open_empty.yml"
);
{
// create empty file
std
::
ofstream
f
(
fname
.
c_str
(),
std
::
ios
::
out
);
}
FileStorage
fs
;
try
{
fs
.
open
(
fname
,
FileStorage
::
READ
);
ADD_FAILURE
()
<<
"Exception must be thrown for empty file."
;
}
catch
(
const
cv
::
Exception
&
)
{
// expected way
// closed files can be checked manually through 'strace'
}
catch
(
const
std
::
exception
&
e
)
{
ADD_FAILURE
()
<<
"Unexpected exception: "
<<
e
.
what
();
}
catch
(...)
{
ADD_FAILURE
()
<<
"Unexpected unknown C++ exception"
;
}
EXPECT_EQ
(
0
,
remove
(
fname
.
c_str
()));
}
}}
// namespace
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