1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 07:13:02 +04:00

Merge pull request #23055 from seanm:sprintf2

* Replaced most remaining sprintf with snprintf
* Deprecated encodeFormat and introduced new method that takes the buffer length
* Also increased buffer size at call sites to be a little bigger, in case int is 64 bit
This commit is contained in:
Sean McBride
2023-04-18 02:22:59 -04:00
committed by GitHub
parent 8512deb3cc
commit 47bea69322
32 changed files with 82 additions and 71 deletions
+9 -2
View File
@@ -161,14 +161,21 @@ static int symbolToType(char c)
return static_cast<int>(pos - symbols);
}
char* encodeFormat(int elem_type, char* dt)
char* encodeFormat(int elem_type, char* dt, size_t dt_len)
{
int cn = (elem_type == CV_SEQ_ELTYPE_PTR/*CV_USRTYPE1*/) ? 1 : CV_MAT_CN(elem_type);
char symbol = (elem_type == CV_SEQ_ELTYPE_PTR/*CV_USRTYPE1*/) ? 'r' : typeSymbol(CV_MAT_DEPTH(elem_type));
sprintf(dt, "%d%c", cn, symbol);
snprintf(dt, dt_len, "%d%c", cn, symbol);
return dt + (cn == 1 ? 1 : 0);
}
// Deprecated due to size of dt buffer being unknowable.
char* encodeFormat(int elem_type, char* dt)
{
constexpr size_t max = 20+1+1; // UINT64_MAX + one char + nul termination.
return encodeFormat(elem_type, dt, max);
}
int decodeFormat( const char* dt, int* fmt_pairs, int max_len )
{
int fmt_pair_count = 0;