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
0831b436
Commit
0831b436
authored
May 22, 2017
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8771 from alalek:fix_snprintf
parents
235f2cc7
16ea72e6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
5 deletions
+27
-5
system.cpp
modules/core/src/system.cpp
+27
-5
No files found.
modules/core/src/system.cpp
View file @
0831b436
...
...
@@ -751,8 +751,12 @@ String format( const char* fmt, ... )
{
va_list
va
;
va_start
(
va
,
fmt
);
int
bsize
=
static_cast
<
int
>
(
buf
.
size
()),
len
=
vsnprintf
((
char
*
)
buf
,
bsize
,
fmt
,
va
);
int
bsize
=
static_cast
<
int
>
(
buf
.
size
());
#if defined _MSC_VER && __cplusplus < 201103L
int
len
=
_vsnprintf_s
((
char
*
)
buf
,
bsize
,
_TRUNCATE
,
fmt
,
va
);
#else
int
len
=
vsnprintf
((
char
*
)
buf
,
bsize
,
fmt
,
va
);
#endif
va_end
(
va
);
if
(
len
<
0
||
len
>=
bsize
)
...
...
@@ -760,6 +764,7 @@ String format( const char* fmt, ... )
buf
.
resize
(
std
::
max
(
bsize
<<
1
,
len
+
1
));
continue
;
}
buf
[
bsize
-
1
]
=
0
;
return
String
((
char
*
)
buf
,
len
);
}
}
...
...
@@ -851,6 +856,22 @@ bool setBreakOnError(bool value)
return
prevVal
;
}
static
bool
cv_snprintf
(
char
*
buf
,
int
len
,
const
char
*
fmt
,
...)
{
va_list
va
;
va_start
(
va
,
fmt
);
#if defined _MSC_VER && __cplusplus < 201103L
int
res
=
_vsnprintf_s
((
char
*
)
buf
,
len
-
1
,
_TRUNCATE
,
fmt
,
va
);
va_end
(
va
);
buf
[
len
-
1
]
=
0
;
return
res
>=
0
&&
res
<
len
-
1
;
#else
int
res
=
vsnprintf
((
char
*
)
buf
,
len
,
fmt
,
va
);
va_end
(
va
);
return
res
>=
0
&&
res
<
len
;
#endif
}
void
error
(
const
Exception
&
exc
)
{
if
(
customErrorCallback
!=
0
)
...
...
@@ -861,10 +882,10 @@ void error( const Exception& exc )
const
char
*
errorStr
=
cvErrorStr
(
exc
.
code
);
char
buf
[
1
<<
12
];
snprintf
(
buf
,
sizeof
(
buf
),
"OpenCV Error: %s (%s) in %s, file %s, line %d"
,
cv_snprintf
(
buf
,
sizeof
(
buf
),
"OpenCV Error: %s (%s) in %s, file %s, line %d"
,
errorStr
,
exc
.
err
.
c_str
(),
exc
.
func
.
size
()
>
0
?
exc
.
func
.
c_str
()
:
"unknown function"
,
exc
.
file
.
c_str
(),
exc
.
line
);
exc
.
func
.
c_str
()
:
"unknown function"
,
exc
.
file
.
c_str
(),
exc
.
line
);
fprintf
(
stderr
,
"%s
\n
"
,
buf
);
fflush
(
stderr
);
# ifdef __ANDROID__
...
...
@@ -886,6 +907,7 @@ void error(int _code, const String& _err, const char* _func, const char* _file,
error
(
cv
::
Exception
(
_code
,
_err
,
_func
,
_file
,
_line
));
}
ErrorCallback
redirectError
(
ErrorCallback
errCallback
,
void
*
userdata
,
void
**
prevUserdata
)
{
...
...
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