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
ea3a5950
Commit
ea3a5950
authored
Dec 03, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13346 from alalek:fix_kw_persistence
parents
cf0be1a0
4e831108
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
persistence.cpp
modules/core/src/persistence.cpp
+12
-5
persistence.hpp
modules/core/src/persistence.hpp
+12
-2
No files found.
modules/core/src/persistence.cpp
View file @
ea3a5950
...
@@ -114,9 +114,11 @@ char* floatToString( char* buf, float value, bool halfprecision, bool explicitZe
...
@@ -114,9 +114,11 @@ char* floatToString( char* buf, float value, bool halfprecision, bool explicitZe
}
}
else
else
{
{
static
const
char
*
fmt
=
halfprecision
?
"%.4e"
:
"%.8e"
;
char
*
ptr
=
buf
;
char
*
ptr
=
buf
;
sprintf
(
buf
,
fmt
,
value
);
if
(
halfprecision
)
sprintf
(
buf
,
"%.4e"
,
value
);
else
sprintf
(
buf
,
"%.8e"
,
value
);
if
(
*
ptr
==
'+'
||
*
ptr
==
'-'
)
if
(
*
ptr
==
'+'
||
*
ptr
==
'-'
)
ptr
++
;
ptr
++
;
for
(
;
cv_isdigit
(
*
ptr
);
ptr
++
)
for
(
;
cv_isdigit
(
*
ptr
);
ptr
++
)
...
@@ -350,6 +352,7 @@ public:
...
@@ -350,6 +352,7 @@ public:
void
init
()
void
init
()
{
{
flags
=
0
;
buffer
.
clear
();
buffer
.
clear
();
bufofs
=
0
;
bufofs
=
0
;
state
=
UNDEFINED
;
state
=
UNDEFINED
;
...
@@ -358,6 +361,7 @@ public:
...
@@ -358,6 +361,7 @@ public:
write_mode
=
false
;
write_mode
=
false
;
mem_mode
=
false
;
mem_mode
=
false
;
space
=
0
;
space
=
0
;
wrap_margin
=
71
;
fmt
=
0
;
fmt
=
0
;
file
=
0
;
file
=
0
;
gzfile
=
0
;
gzfile
=
0
;
...
@@ -615,7 +619,8 @@ public:
...
@@ -615,7 +619,8 @@ public:
for
(;;)
for
(;;)
{
{
int
line_offset
=
(
int
)
ftell
(
file
);
int
line_offset
=
(
int
)
ftell
(
file
);
char
*
ptr0
=
gets
(
&
xml_buf_
[
0
],
xml_buf_size
),
*
ptr
;
const
char
*
ptr0
=
this
->
gets
(
&
xml_buf_
[
0
],
xml_buf_size
);
const
char
*
ptr
=
NULL
;
if
(
!
ptr0
)
if
(
!
ptr0
)
break
;
break
;
ptr
=
ptr0
;
ptr
=
ptr0
;
...
@@ -708,7 +713,7 @@ public:
...
@@ -708,7 +713,7 @@ public:
const
char
*
json_signature
=
"{"
;
const
char
*
json_signature
=
"{"
;
const
char
*
xml_signature
=
"<?xml"
;
const
char
*
xml_signature
=
"<?xml"
;
char
buf
[
16
];
char
buf
[
16
];
gets
(
buf
,
sizeof
(
buf
)
-
2
);
this
->
gets
(
buf
,
sizeof
(
buf
)
-
2
);
char
*
bufPtr
=
cv_skip_BOM
(
buf
);
char
*
bufPtr
=
cv_skip_BOM
(
buf
);
size_t
bufOffset
=
bufPtr
-
buf
;
size_t
bufOffset
=
bufPtr
-
buf
;
...
@@ -861,7 +866,7 @@ public:
...
@@ -861,7 +866,7 @@ public:
char
*
gets
()
char
*
gets
()
{
{
char
*
ptr
=
gets
(
bufferStart
(),
(
int
)(
bufferEnd
()
-
bufferStart
()));
char
*
ptr
=
this
->
gets
(
bufferStart
(),
(
int
)(
bufferEnd
()
-
bufferStart
()));
if
(
!
ptr
)
if
(
!
ptr
)
{
{
ptr
=
bufferStart
();
// FIXIT Why do we need this hack? What is about other parsers JSON/YAML?
ptr
=
bufferStart
();
// FIXIT Why do we need this hack? What is about other parsers JSON/YAML?
...
@@ -1766,11 +1771,13 @@ public:
...
@@ -1766,11 +1771,13 @@ public:
};
};
FileStorage
::
FileStorage
()
FileStorage
::
FileStorage
()
:
state
(
0
)
{
{
p
=
makePtr
<
FileStorage
::
Impl
>
(
this
);
p
=
makePtr
<
FileStorage
::
Impl
>
(
this
);
}
}
FileStorage
::
FileStorage
(
const
String
&
filename
,
int
flags
,
const
String
&
encoding
)
FileStorage
::
FileStorage
(
const
String
&
filename
,
int
flags
,
const
String
&
encoding
)
:
state
(
0
)
{
{
p
=
makePtr
<
FileStorage
::
Impl
>
(
this
);
p
=
makePtr
<
FileStorage
::
Impl
>
(
this
);
bool
ok
=
p
->
open
(
filename
.
c_str
(),
flags
,
encoding
.
c_str
());
bool
ok
=
p
->
open
(
filename
.
c_str
(),
flags
,
encoding
.
c_str
());
...
...
modules/core/src/persistence.hpp
View file @
ea3a5950
...
@@ -96,11 +96,20 @@ int decodeFormat( const char* dt, int* fmt_pairs, int max_len );
...
@@ -96,11 +96,20 @@ int decodeFormat( const char* dt, int* fmt_pairs, int max_len );
int
decodeSimpleFormat
(
const
char
*
dt
);
int
decodeSimpleFormat
(
const
char
*
dt
);
}
}
#ifdef CV_STATIC_ANALYSIS
#define CV_PARSE_ERROR_CPP(errmsg) do { (void)fs; abort(); } while (0)
#else
#define CV_PARSE_ERROR_CPP( errmsg ) \
#define CV_PARSE_ERROR_CPP( errmsg ) \
fs->parseError( CV_Func, (errmsg), __FILE__, __LINE__ )
fs->parseError( CV_Func, (errmsg), __FILE__, __LINE__ )
#endif
#define CV_PERSISTENCE_CHECK_END_OF_BUFFER_BUG_CPP() do { \
CV_DbgAssert(ptr); \
if((ptr)[0] == 0 && (ptr) == fs->bufferEnd() - 1) CV_PARSE_ERROR_CPP("OpenCV persistence doesn't support very long lines"); \
} while (0)
#define CV_PERSISTENCE_CHECK_END_OF_BUFFER_BUG_CPP() \
if((ptr)[0] == 0 && (ptr) == fs->bufferEnd() - 1) CV_PARSE_ERROR_CPP("OpenCV persistence doesn't support very long lines")
class
FileStorageParser
;
class
FileStorageParser
;
class
FileStorageEmitter
;
class
FileStorageEmitter
;
...
@@ -151,6 +160,7 @@ public:
...
@@ -151,6 +160,7 @@ public:
virtual
double
strtod
(
char
*
ptr
,
char
**
endptr
)
=
0
;
virtual
double
strtod
(
char
*
ptr
,
char
**
endptr
)
=
0
;
virtual
char
*
parseBase64
(
char
*
ptr
,
int
indent
,
FileNode
&
collection
)
=
0
;
virtual
char
*
parseBase64
(
char
*
ptr
,
int
indent
,
FileNode
&
collection
)
=
0
;
CV_NORETURN
virtual
void
parseError
(
const
char
*
funcname
,
const
std
::
string
&
msg
,
virtual
void
parseError
(
const
char
*
funcname
,
const
std
::
string
&
msg
,
const
char
*
filename
,
int
lineno
)
=
0
;
const
char
*
filename
,
int
lineno
)
=
0
;
};
};
...
...
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