diff --git a/apps/createsamples/utility.cpp b/apps/createsamples/utility.cpp index 5176f14836..c64995481c 100644 --- a/apps/createsamples/utility.cpp +++ b/apps/createsamples/utility.cpp @@ -1167,7 +1167,7 @@ void cvCreateTestSamples( const char* infoname, } else { - filename++; + filename++; // character after last / or \ } count = MIN( count, cvbgdata->count ); @@ -1199,8 +1199,8 @@ void cvCreateTestSamples( const char* infoname, 1, 0.0, 0.0, &data ); - sprintf( filename, "%04d_%04d_%04d_%04d_%04d.jpg", - (i + 1), x, y, width, height ); + snprintf( filename, sizeof(fullname) - (filename - fullname), "%04d_%04d_%04d_%04d_%04d.jpg", + (i + 1), x, y, width, height ); if( info ) { diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index fbc4959253..2a1ed7887a 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -489,7 +489,7 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, int kercn = haveMask || haveScalar ? cn : ocl::predictOptimalVectorWidth(_src1, _src2, _dst); int scalarcn = kercn == 3 ? 4 : kercn, rowsPerWI = d.isIntel() ? 4 : 1; - char cvtstr[4][32], opts[1024]; + char cvtstr[4][50], opts[1024]; snprintf(opts, sizeof(opts), "-D %s%s -D %s -D srcT1=%s -D srcT1_C1=%s -D srcT2=%s -D srcT2_C1=%s " "-D dstT=%s -D DEPTH_dst=%d -D dstT_C1=%s -D workT=%s -D workST=%s -D scaleT=%s -D wdepth=%d -D convertToWT1=%s " "-D convertToWT2=%s -D convertToDT=%s%s -D cn=%d -D rowsPerWI=%d -D convertFromU=%s", @@ -1098,7 +1098,7 @@ static bool ocl_compare(InputArray _src1, InputArray _src2, OutputArray _dst, in int scalarcn = kercn == 3 ? 4 : kercn; const char * const operationMap[] = { "==", ">", ">=", "<", "<=", "!=" }; - char cvt[40]; + char cvt[50]; String opts = format("-D %s -D srcT1=%s -D dstT=%s -D DEPTH_dst=%d -D workT=srcT1 -D cn=%d" " -D convertToDT=%s -D OP_CMP -D CMP_OPERATOR=%s -D srcT1_C1=%s" diff --git a/modules/core/src/matmul.dispatch.cpp b/modules/core/src/matmul.dispatch.cpp index 52200f097c..5a38f64eb8 100644 --- a/modules/core/src/matmul.dispatch.cpp +++ b/modules/core/src/matmul.dispatch.cpp @@ -1041,7 +1041,7 @@ static bool ocl_dot( InputArray _src1, InputArray _src2, double & res ) wgs2_aligned <<= 1; wgs2_aligned >>= 1; - char cvt[40]; + char cvt[50]; ocl::Kernel k("reduce", ocl::core::reduce_oclsrc, format("-D srcT=%s -D srcT1=%s -D dstT=%s -D dstTK=%s -D ddepth=%d -D convertToDT=%s -D OP_DOT " "-D WGS=%d -D WGS2_ALIGNED=%d%s%s%s -D kercn=%d", diff --git a/modules/core/src/matrix_operations.cpp b/modules/core/src/matrix_operations.cpp index f9a50cd0ee..f5cafbd279 100644 --- a/modules/core/src/matrix_operations.cpp +++ b/modules/core/src/matrix_operations.cpp @@ -633,7 +633,7 @@ static bool ocl_reduce(InputArray _src, OutputArray _dst, static const size_t maxItemInGroupCount = 16; tileHeight = min(tileHeight, defDev.localMemSize() / buf_cols / CV_ELEM_SIZE(CV_MAKETYPE(wdepth, cn)) / maxItemInGroupCount); } - char cvt[3][40]; + char cvt[3][50]; cv::String build_opt = format("-D OP_REDUCE_PRE -D BUF_COLS=%d -D TILE_HEIGHT=%zu -D %s -D dim=1" " -D cn=%d -D ddepth=%d" " -D srcT=%s -D bufT=%s -D dstT=%s" @@ -667,7 +667,7 @@ static bool ocl_reduce(InputArray _src, OutputArray _dst, } else { - char cvt[2][40]; + char cvt[2][50]; cv::String build_opt = format("-D %s -D dim=%d -D cn=%d -D ddepth=%d" " -D srcT=%s -D dstT=%s -D dstT0=%s -D convertToWT=%s" " -D convertToDT=%s -D convertToDT0=%s%s", diff --git a/modules/core/src/mean.dispatch.cpp b/modules/core/src/mean.dispatch.cpp index 7a8f9413fc..62198d38bf 100644 --- a/modules/core/src/mean.dispatch.cpp +++ b/modules/core/src/mean.dispatch.cpp @@ -227,7 +227,7 @@ static bool ocl_meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv if ( (!doubleSupport && depth == CV_64F) ) return false; - char cvt[2][40]; + char cvt[2][50]; String opts = format("-D srcT=%s -D srcT1=%s -D dstT=%s -D dstT1=%s -D sqddepth=%d" " -D sqdstT=%s -D sqdstT1=%s -D convertToSDT=%s -D cn=%d%s%s" " -D convertToDT=%s -D WGS=%d -D WGS2_ALIGNED=%d%s%s", diff --git a/modules/core/src/minmax.cpp b/modules/core/src/minmax.cpp index f738a87e4f..e03f939d07 100644 --- a/modules/core/src/minmax.cpp +++ b/modules/core/src/minmax.cpp @@ -1029,7 +1029,7 @@ bool ocl_minMaxIdx( InputArray _src, double* minVal, double* maxVal, int* minLoc needMaxLoc = true; } - char cvt[2][40]; + char cvt[2][50]; String opts = format("-D DEPTH_%d -D srcT1=%s%s -D WGS=%d -D srcT=%s" " -D WGS2_ALIGNED=%d%s%s%s -D kercn=%d%s%s%s%s" " -D dstT1=%s -D dstT=%s -D convertToDT=%s%s%s%s%s -D wdepth=%d -D convertFromU=%s" diff --git a/modules/core/src/norm.cpp b/modules/core/src/norm.cpp index 4df25f4957..dc22b73722 100644 --- a/modules/core/src/norm.cpp +++ b/modules/core/src/norm.cpp @@ -1319,7 +1319,7 @@ static bool ocl_normalize( InputArray _src, InputOutputArray _dst, InputArray _m if ((sdepth == CV_64F || ddepth == CV_64F) && !doubleSupport) return false; - char cvt[2][40]; + char cvt[2][50]; String opts = format("-D srcT=%s -D dstT=%s -D convertToWT=%s -D cn=%d -D rowsPerWI=%d" " -D convertToDT=%s -D workT=%s%s%s%s -D srcT1=%s -D dstT1=%s", ocl::typeToStr(stype), ocl::typeToStr(dtype), diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 51acc68879..e4d9f52da9 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -6983,7 +6983,7 @@ const char* typeToStr(int type) { "uchar", "uchar2", "uchar3", "uchar4", 0, 0, 0, "uchar8", 0, 0, 0, 0, 0, 0, 0, "uchar16", "char", "char2", "char3", "char4", 0, 0, 0, "char8", 0, 0, 0, 0, 0, 0, 0, "char16", - "ushort", "ushort2", "ushort3", "ushort4",0, 0, 0, "ushort8", 0, 0, 0, 0, 0, 0, 0, "ushort16", + "ushort", "ushort2", "ushort3", "ushort4", 0, 0, 0, "ushort8", 0, 0, 0, 0, 0, 0, 0, "ushort16", "short", "short2", "short3", "short4", 0, 0, 0, "short8", 0, 0, 0, 0, 0, 0, 0, "short16", "int", "int2", "int3", "int4", 0, 0, 0, "int8", 0, 0, 0, 0, 0, 0, 0, "int16", "float", "float2", "float3", "float4", 0, 0, 0, "float8", 0, 0, 0, 0, 0, 0, 0, "float16", @@ -6992,7 +6992,7 @@ const char* typeToStr(int type) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int cn = CV_MAT_CN(type), depth = CV_MAT_DEPTH(type); - const char* result = cn > 16 ? 0 : tab[depth*16 + cn-1]; + const char* result = cn > 16 ? nullptr : tab[depth*16 + cn-1]; CV_Assert(result); return result; } @@ -7003,7 +7003,7 @@ const char* memopTypeToStr(int type) { "uchar", "uchar2", "uchar3", "uchar4", 0, 0, 0, "uchar8", 0, 0, 0, 0, 0, 0, 0, "uchar16", "char", "char2", "char3", "char4", 0, 0, 0, "char8", 0, 0, 0, 0, 0, 0, 0, "char16", - "ushort", "ushort2", "ushort3", "ushort4",0, 0, 0, "ushort8", 0, 0, 0, 0, 0, 0, 0, "ushort16", + "ushort", "ushort2", "ushort3", "ushort4", 0, 0, 0, "ushort8", 0, 0, 0, 0, 0, 0, 0, "ushort16", "short", "short2", "short3", "short4", 0, 0, 0, "short8", 0, 0, 0, 0, 0, 0, 0, "short16", "int", "int2", "int3", "int4", 0, 0, 0, "int8", 0, 0, 0, 0, 0, 0, 0, "int16", "int", "int2", "int3", "int4", 0, 0, 0, "int8", 0, 0, 0, 0, 0, 0, 0, "int16", @@ -7012,7 +7012,7 @@ const char* memopTypeToStr(int type) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int cn = CV_MAT_CN(type), depth = CV_MAT_DEPTH(type); - const char* result = cn > 16 ? 0 : tab[depth*16 + cn-1]; + const char* result = cn > 16 ? nullptr : tab[depth*16 + cn-1]; CV_Assert(result); return result; } @@ -7039,6 +7039,9 @@ const char* vecopTypeToStr(int type) const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf) { + // Since the size of buf is not given, we assume 50 because that's what all callers use. + constexpr size_t buf_max = 50; + if( sdepth == ddepth ) return "noconvert"; const char *typestr = typeToStr(CV_MAKETYPE(ddepth, cn)); @@ -7047,12 +7050,12 @@ const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf) (ddepth == CV_16S && sdepth <= CV_8S) || (ddepth == CV_16U && sdepth == CV_8U)) { - sprintf(buf, "convert_%s", typestr); + snprintf(buf, buf_max, "convert_%s", typestr); } else if( sdepth >= CV_32F ) - sprintf(buf, "convert_%s%s_rte", typestr, (ddepth < CV_32S ? "_sat" : "")); + snprintf(buf, buf_max, "convert_%s%s_rte", typestr, (ddepth < CV_32S ? "_sat" : "")); else - sprintf(buf, "convert_%s_sat", typestr); + snprintf(buf, buf_max, "convert_%s_sat", typestr); return buf; } diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 59f843d5bc..0d64bab094 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -161,14 +161,21 @@ static int symbolToType(char c) return static_cast(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; diff --git a/modules/core/src/persistence.hpp b/modules/core/src/persistence.hpp index fb7f5acf45..4b579303fa 100644 --- a/modules/core/src/persistence.hpp +++ b/modules/core/src/persistence.hpp @@ -91,7 +91,8 @@ char* doubleToString( char* buf, size_t bufSize, double value, bool explicitZero int calcStructSize( const char* dt, int initial_size ); int calcElemSize( const char* dt, int initial_size ); -char* encodeFormat( int elem_type, char* dt ); +CV_DEPRECATED char* encodeFormat( int elem_type, char* dt ); +char* encodeFormat( int elem_type, char* dt, size_t dt_len ); int decodeFormat( const char* dt, int* fmt_pairs, int max_len ); int decodeSimpleFormat( const char* dt ); } diff --git a/modules/core/src/persistence_types.cpp b/modules/core/src/persistence_types.cpp index eeebdafe75..cd4fad05fb 100644 --- a/modules/core/src/persistence_types.cpp +++ b/modules/core/src/persistence_types.cpp @@ -10,14 +10,14 @@ namespace cv void write( FileStorage& fs, const String& name, const Mat& m ) { - char dt[16]; + char dt[22]; if( m.dims <= 2 ) { fs.startWriteStruct(name, FileNode::MAP, String("opencv-matrix")); fs << "rows" << m.rows; fs << "cols" << m.cols; - fs << "dt" << fs::encodeFormat( m.type(), dt ); + fs << "dt" << fs::encodeFormat( m.type(), dt, sizeof(dt) ); fs << "data" << "[:"; for( int i = 0; i < m.rows; i++ ) fs.writeRaw(dt, m.ptr(i), m.cols*m.elemSize()); @@ -30,7 +30,7 @@ void write( FileStorage& fs, const String& name, const Mat& m ) fs << "sizes" << "[:"; fs.writeRaw( "i", m.size.p, m.dims*sizeof(int) ); fs << "]"; - fs << "dt" << fs::encodeFormat( m.type(), dt ); + fs << "dt" << fs::encodeFormat( m.type(), dt, sizeof(dt) ); fs << "data" << "[:"; const Mat* arrays[] = {&m, 0}; uchar* ptrs[1] = {}; @@ -63,7 +63,7 @@ struct SparseNodeCmp void write( FileStorage& fs, const String& name, const SparseMat& m ) { - char dt[16]; + char dt[22]; fs.startWriteStruct(name, FileNode::MAP, String("opencv-sparse-matrix")); fs << "sizes" << "[:"; @@ -71,7 +71,7 @@ void write( FileStorage& fs, const String& name, const SparseMat& m ) if( dims > 0 ) fs.writeRaw("i", m.hdr->size, dims*sizeof(int) ); fs << "]"; - fs << "dt" << fs::encodeFormat( m.type(), dt ); + fs << "dt" << fs::encodeFormat( m.type(), dt, sizeof(dt) ); fs << "data" << "[:"; size_t i = 0, n = m.nzcount(); diff --git a/modules/core/src/persistence_xml.cpp b/modules/core/src/persistence_xml.cpp index 2264d16baa..caba4f5bf0 100644 --- a/modules/core/src/persistence_xml.cpp +++ b/modules/core/src/persistence_xml.cpp @@ -208,7 +208,7 @@ public: } else { - sprintf( data, "#x%02x", (uchar)c ); + snprintf( data, sizeof(buf) - (data - buf), "#x%02x", (uchar)c ); data += 4; } *data++ = ';'; diff --git a/modules/core/src/persistence_yml.cpp b/modules/core/src/persistence_yml.cpp index c8c7c7a892..e4f53c353e 100644 --- a/modules/core/src/persistence_yml.cpp +++ b/modules/core/src/persistence_yml.cpp @@ -152,7 +152,7 @@ public: *data++ = 't'; else { - sprintf( data, "x%02x", c ); + snprintf( data, sizeof(buf) - (data - buf), "x%02x", c ); data += 3; } } diff --git a/modules/core/src/sum.dispatch.cpp b/modules/core/src/sum.dispatch.cpp index 20caca9f04..b01a7a2bd7 100644 --- a/modules/core/src/sum.dispatch.cpp +++ b/modules/core/src/sum.dispatch.cpp @@ -62,7 +62,7 @@ bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask, wgs2_aligned >>= 1; static const char * const opMap[3] = { "OP_SUM", "OP_SUM_ABS", "OP_SUM_SQR" }; - char cvt[2][40]; + char cvt[2][50]; String opts = format("-D srcT=%s -D srcT1=%s -D dstT=%s -D dstTK=%s -D dstT1=%s -D ddepth=%d -D cn=%d" " -D convertToDT=%s -D %s -D WGS=%d -D WGS2_ALIGNED=%d%s%s%s%s -D kercn=%d%s%s%s -D convertFromU=%s", ocl::typeToStr(CV_MAKE_TYPE(depth, mcn)), ocl::typeToStr(depth), diff --git a/modules/core/src/umatrix.cpp b/modules/core/src/umatrix.cpp index 846d406eca..ba958e646c 100644 --- a/modules/core/src/umatrix.cpp +++ b/modules/core/src/umatrix.cpp @@ -1259,7 +1259,7 @@ void UMat::convertTo(OutputArray _dst, int _type, double alpha, double beta) con { int wdepth = std::max(CV_32F, sdepth), rowsPerWI = 4; - char cvt[2][40]; + char cvt[2][50]; ocl::Kernel k("convertTo", ocl::core::convert_oclsrc, format("-D srcT=%s -D WT=%s -D dstT=%s -D convertToWT=%s -D convertToDT=%s%s%s", ocl::typeToStr(sdepth), ocl::typeToStr(wdepth), ocl::typeToStr(ddepth), diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 9f4711a816..e39b16a1e5 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -497,7 +497,7 @@ static string idx2string(const int* idx, int dims) char* ptr = buf; for( int k = 0; k < dims; k++ ) { - sprintf(ptr, "%4d ", idx[k]); + snprintf(ptr, sizeof(buf) - (ptr - buf), "%4d ", idx[k]); ptr += strlen(ptr); } ptr[-1] = '\0'; diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index aad5b7db67..d2de2abeca 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -2030,7 +2030,7 @@ static void icvUpdateTrackbar(CvTrackbar& trackbar, int pos) memcpy(pos_text, trackbar.name.c_str(), name_len + 1); } - sprintf(pos_text + strlen(pos_text), "%s: %d\n", suffix, pos); + snprintf(pos_text + strlen(pos_text), sizeof(pos_text) - strlen(pos_text), "%s: %d\n", suffix, pos); SetWindowText(trackbar.buddy, pos_text); } } diff --git a/modules/imgcodecs/src/grfmt_pam.cpp b/modules/imgcodecs/src/grfmt_pam.cpp index 1c8f8476a5..979a31ca91 100644 --- a/modules/imgcodecs/src/grfmt_pam.cpp +++ b/modules/imgcodecs/src/grfmt_pam.cpp @@ -695,14 +695,14 @@ bool PAMEncoder::write( const Mat& img, const std::vector& params ) /* write header */ tmp = 0; - tmp += sprintf( buffer, "P7\n"); - tmp += sprintf( buffer + tmp, "WIDTH %d\n", width); - tmp += sprintf( buffer + tmp, "HEIGHT %d\n", height); - tmp += sprintf( buffer + tmp, "DEPTH %d\n", img.channels()); - tmp += sprintf( buffer + tmp, "MAXVAL %d\n", (1 << img.elemSize1()*8) - 1); + tmp += snprintf( buffer, bufsize, "P7\n"); + tmp += snprintf( buffer + tmp, bufsize - tmp, "WIDTH %d\n", width); + tmp += snprintf( buffer + tmp, bufsize - tmp, "HEIGHT %d\n", height); + tmp += snprintf( buffer + tmp, bufsize - tmp, "DEPTH %d\n", img.channels()); + tmp += snprintf( buffer + tmp, bufsize - tmp, "MAXVAL %d\n", (1 << img.elemSize1()*8) - 1); if (fmt) - tmp += sprintf( buffer + tmp, "TUPLTYPE %s\n", fmt->name ); - sprintf( buffer + tmp, "ENDHDR\n" ); + tmp += snprintf( buffer + tmp, bufsize - tmp, "TUPLTYPE %s\n", fmt->name ); + snprintf( buffer + tmp, bufsize - tmp, "ENDHDR\n" ); strm.putBytes( buffer, (int)strlen(buffer) ); /* write data */ diff --git a/modules/imgcodecs/src/grfmt_pxm.cpp b/modules/imgcodecs/src/grfmt_pxm.cpp index c18ac7a1e2..8da2348728 100644 --- a/modules/imgcodecs/src/grfmt_pxm.cpp +++ b/modules/imgcodecs/src/grfmt_pxm.cpp @@ -467,12 +467,12 @@ bool PxMEncoder::write(const Mat& img, const std::vector& params) const int code = ((mode == PXM_TYPE_PBM) ? 1 : (mode == PXM_TYPE_PGM) ? 2 : 3) + (isBinary ? 3 : 0); - int header_sz = sprintf(buffer, "P%c\n%d %d\n", + int header_sz = snprintf(buffer, bufferSize, "P%c\n%d %d\n", (char)('0' + code), width, height); CV_Assert(header_sz > 0); if (mode != PXM_TYPE_PBM) { - int sz = sprintf(&buffer[header_sz], "%d\n", (1 << depth) - 1); + int sz = snprintf(&buffer[header_sz], bufferSize - header_sz, "%d\n", (1 << depth) - 1); CV_Assert(sz > 0); header_sz += sz; } @@ -560,11 +560,11 @@ bool PxMEncoder::write(const Mat& img, const std::vector& params) { for( x = 0; x < width*channels; x += channels ) { - sprintf( ptr, "% 4d", data[x + 2] ); + snprintf( ptr, bufferSize - (ptr - buffer), "% 4d", data[x + 2] ); ptr += 4; - sprintf( ptr, "% 4d", data[x + 1] ); + snprintf( ptr, bufferSize - (ptr - buffer), "% 4d", data[x + 1] ); ptr += 4; - sprintf( ptr, "% 4d", data[x] ); + snprintf( ptr, bufferSize - (ptr - buffer), "% 4d", data[x] ); ptr += 4; *ptr++ = ' '; *ptr++ = ' '; @@ -574,11 +574,11 @@ bool PxMEncoder::write(const Mat& img, const std::vector& params) { for( x = 0; x < width*channels; x += channels ) { - sprintf( ptr, "% 6d", ((const ushort *)data)[x + 2] ); + snprintf( ptr, bufferSize - (ptr - buffer), "% 6d", ((const ushort *)data)[x + 2] ); ptr += 6; - sprintf( ptr, "% 6d", ((const ushort *)data)[x + 1] ); + snprintf( ptr, bufferSize - (ptr - buffer), "% 6d", ((const ushort *)data)[x + 1] ); ptr += 6; - sprintf( ptr, "% 6d", ((const ushort *)data)[x] ); + snprintf( ptr, bufferSize - (ptr - buffer), "% 6d", ((const ushort *)data)[x] ); ptr += 6; *ptr++ = ' '; *ptr++ = ' '; @@ -591,7 +591,7 @@ bool PxMEncoder::write(const Mat& img, const std::vector& params) { for( x = 0; x < width; x++ ) { - sprintf( ptr, "% 4d", data[x] ); + snprintf( ptr, bufferSize - (ptr - buffer), "% 4d", data[x] ); ptr += 4; } } @@ -599,7 +599,7 @@ bool PxMEncoder::write(const Mat& img, const std::vector& params) { for( x = 0; x < width; x++ ) { - sprintf( ptr, "% 6d", ((const ushort *)data)[x] ); + snprintf( ptr, bufferSize - (ptr - buffer), "% 6d", ((const ushort *)data)[x] ); ptr += 6; } } diff --git a/modules/imgproc/src/accum.cpp b/modules/imgproc/src/accum.cpp index fbd5223c13..3ef958e0cb 100644 --- a/modules/imgproc/src/accum.cpp +++ b/modules/imgproc/src/accum.cpp @@ -126,7 +126,7 @@ static bool ocl_accumulate( InputArray _src, InputArray _src2, InputOutputArray const char * const opMap[4] = { "ACCUMULATE", "ACCUMULATE_SQUARE", "ACCUMULATE_PRODUCT", "ACCUMULATE_WEIGHTED" }; - char cvt[40]; + char cvt[50]; ocl::Kernel k("accumulate", ocl::imgproc::accumulate_oclsrc, format("-D %s%s -D srcT1=%s -D cn=%d -D dstT1=%s%s -D rowsPerWI=%d -D convertToDT=%s", opMap[op_type], haveMask ? " -D HAVE_MASK" : "", diff --git a/modules/imgproc/src/bilateral_filter.dispatch.cpp b/modules/imgproc/src/bilateral_filter.dispatch.cpp index ed0e71bbab..b3c8388448 100644 --- a/modules/imgproc/src/bilateral_filter.dispatch.cpp +++ b/modules/imgproc/src/bilateral_filter.dispatch.cpp @@ -111,7 +111,7 @@ static bool ocl_bilateralFilter_8u(InputArray _src, OutputArray _dst, int d, space_ofs[maxk++] = (int)(i * temp.step + j * cn); } - char cvt[3][40]; + char cvt[3][50]; String cnstr = cn > 1 ? format("%d", cn) : ""; String kernelName("bilateral"); size_t sizeDiv = 1; diff --git a/modules/imgproc/src/blend.cpp b/modules/imgproc/src/blend.cpp index e0ee9ec0c5..2ed28cea2b 100644 --- a/modules/imgproc/src/blend.cpp +++ b/modules/imgproc/src/blend.cpp @@ -350,7 +350,7 @@ static bool ocl_blendLinear( InputArray _src1, InputArray _src2, InputArray _wei { int type = _src1.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); - char cvt[30]; + char cvt[50]; ocl::Kernel k("blendLinear", ocl::imgproc::blend_linear_oclsrc, format("-D T=%s -D cn=%d -D convertToT=%s", ocl::typeToStr(depth), cn, ocl::convertTypeStr(CV_32F, depth, 1, cvt))); diff --git a/modules/imgproc/src/box_filter.dispatch.cpp b/modules/imgproc/src/box_filter.dispatch.cpp index 698f2ae2fb..0856d9e545 100644 --- a/modules/imgproc/src/box_filter.dispatch.cpp +++ b/modules/imgproc/src/box_filter.dispatch.cpp @@ -195,7 +195,7 @@ static bool ocl_boxFilter( InputArray _src, OutputArray _dst, int ddepth, const int wgRound = 256; globalsize[0] = roundUp(globalsize[0], wgRound); - char build_options[1024], cvt[2][40]; + char build_options[1024], cvt[2][50]; snprintf(build_options, sizeof(build_options), "-D cn=%d " "-D ANCHOR_X=%d -D ANCHOR_Y=%d -D KERNEL_SIZE_X=%d -D KERNEL_SIZE_Y=%d " "-D PX_LOAD_VEC_SIZE=%d -D PX_LOAD_NUM_PX=%d " diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index d845de33f1..e64d1c469c 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -183,7 +183,7 @@ static bool ocl_Canny(InputArray _src, const UMat& dx_, const UMat& dy_, OutputA Non maxima suppression Double thresholding */ - char cvt[40]; + char cvt[50]; ocl::Kernel with_sobel("stage1_with_sobel", ocl::imgproc::canny_oclsrc, format("-D WITH_SOBEL -D cn=%d -D TYPE=%s -D convert_floatN=%s -D floatN=%s -D GRP_SIZEX=%d -D GRP_SIZEY=%d%s", cn, ocl::memopTypeToStr(_src.depth()), diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index fb7e7786f5..419d867ae8 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -578,7 +578,7 @@ static bool ocl_Laplacian5(InputArray _src, OutputArray _dst, size_t lt2[2] = { tileSizeX, tileSizeY}; size_t gt2[2] = { lt2[0] * (1 + (size.width - 1) / lt2[0]), lt2[1] }; - char cvt[2][40]; + char cvt[2][50]; const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", "BORDER_WRAP", "BORDER_REFLECT_101" }; @@ -624,7 +624,7 @@ static bool ocl_Laplacian5(InputArray _src, OutputArray _dst, if (!doubleSupport && wdepth == CV_64F) return false; - char cvt[2][40]; + char cvt[2][50]; ocl::Kernel k("sumConvert", ocl::imgproc::laplacian5_oclsrc, format("-D ONLY_SUM_CONVERT " "-D srcT=%s -D WT=%s -D dstT=%s -D coeffT=%s -D wdepth=%d " diff --git a/modules/imgproc/src/filter.dispatch.cpp b/modules/imgproc/src/filter.dispatch.cpp index 53b8bb42c4..850fb31126 100644 --- a/modules/imgproc/src/filter.dispatch.cpp +++ b/modules/imgproc/src/filter.dispatch.cpp @@ -590,7 +590,7 @@ static bool ocl_filter2D( InputArray _src, OutputArray _dst, int ddepth, size_t tryWorkItems = device.maxWorkGroupSize(); if (device.isIntel() && 128 < tryWorkItems) tryWorkItems = 128; - char cvt[2][40]; + char cvt[2][50]; // For smaller filter kernels, there is a special kernel that is more // efficient than the general one. @@ -764,7 +764,7 @@ static bool ocl_sepRowFilter2D(const UMat & src, UMat & buf, const Mat & kernelX extra_extrapolation |= src.cols < (int)((-radiusX + globalsize[0] + 8 * localsize[0] + 3) >> 1) + 1; extra_extrapolation |= src.cols < radiusX; - char cvt[40]; + char cvt[50]; cv::String build_options = cv::format("-D RADIUSX=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s -D %s -D %s" " -D srcT=%s -D dstT=%s -D convertToDstT=%s -D srcT1=%s -D dstT1=%s%s%s", radiusX, (int)localsize[0], (int)localsize[1], cn, btype, @@ -825,7 +825,7 @@ static bool ocl_sepColFilter2D(const UMat & buf, UMat & dst, const Mat & kernelY globalsize[1] = DIVUP(sz.height, localsize[1]) * localsize[1]; globalsize[0] = DIVUP(sz.width, localsize[0]) * localsize[0]; - char cvt[2][40]; + char cvt[2][50]; int floatT = std::max(CV_32F, bdepth); cv::String build_options = cv::format("-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d" " -D srcT=%s -D dstT=%s -D convertToFloatT=%s -D floatT=%s -D convertToDstT=%s" @@ -891,7 +891,7 @@ static bool ocl_sepFilter2D_SinglePass(InputArray _src, OutputArray _dst, size_t lt2[2] = { optimizedSepFilterLocalWidth, optimizedSepFilterLocalHeight }; size_t gt2[2] = { lt2[0] * (1 + (size.width - 1) / lt2[0]), lt2[1]}; - char cvt[2][40]; + char cvt[2][50]; const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", "BORDER_WRAP", "BORDER_REFLECT_101" }; diff --git a/modules/imgproc/src/histogram.cpp b/modules/imgproc/src/histogram.cpp index 84a2734eae..9cdd6b945f 100644 --- a/modules/imgproc/src/histogram.cpp +++ b/modules/imgproc/src/histogram.cpp @@ -1232,7 +1232,7 @@ static bool ocl_calcHist1(InputArray _src, OutputArray _hist, int ddepth = CV_32 return false; wgs = std::min(ocl::Device::getDefault().maxWorkGroupSize(), BINS); - char cvt[40]; + char cvt[50]; ocl::Kernel k2("merge_histogram", ocl::imgproc::histogram_oclsrc, format("-D BINS=%d -D HISTS_COUNT=%d -D WGS=%d -D convertToHT=%s -D HT=%s", BINS, compunits, (int)wgs, ocl::convertTypeStr(CV_32S, ddepth, 1, cvt), diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index c36c8cebf5..efb56dd95f 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -1340,7 +1340,7 @@ static bool ocl_remap(InputArray _src, OutputArray _dst, InputArray _map1, Input if (interpolation != INTER_NEAREST) { - char cvt[3][40]; + char cvt[3][50]; int wdepth = std::max(CV_32F, depth); buildOptions = buildOptions + format(" -D WT=%s -D convertToT=%s -D convertToWT=%s" diff --git a/modules/imgproc/src/morph.dispatch.cpp b/modules/imgproc/src/morph.dispatch.cpp index 45ae3994d9..5c296dffe4 100644 --- a/modules/imgproc/src/morph.dispatch.cpp +++ b/modules/imgproc/src/morph.dispatch.cpp @@ -617,7 +617,7 @@ static bool ocl_morphSmall( InputArray _src, OutputArray _dst, InputArray _kerne wdepth = CV_32S; wtype = CV_MAKETYPE(wdepth, cn); } - char cvt[2][40]; + char cvt[2][50]; const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", 0, "BORDER_REFLECT_101" }; diff --git a/modules/imgproc/src/resize.cpp b/modules/imgproc/src/resize.cpp index f388587f9c..8ab2b206ca 100644 --- a/modules/imgproc/src/resize.cpp +++ b/modules/imgproc/src/resize.cpp @@ -3305,7 +3305,7 @@ static bool ocl_resize( InputArray _src, OutputArray _dst, Size dsize, if (useSampler) { int wdepth = std::max(depth, CV_32S); - char buf[2][32]; + char buf[2][50]; cv::String compileOpts = format("-D USE_SAMPLER -D depth=%d -D T=%s -D T1=%s " "-D convertToDT=%s -D cn=%d", depth, ocl::typeToStr(type), ocl::typeToStr(depth), @@ -3327,7 +3327,7 @@ static bool ocl_resize( InputArray _src, OutputArray _dst, Size dsize, if (interpolation == INTER_LINEAR && !useSampler) { - char buf[2][32]; + char buf[2][50]; // integer path is slower because of CPU part, so it's disabled if (depth == CV_8U && ((void)0, 0)) @@ -3419,7 +3419,7 @@ static bool ocl_resize( InputArray _src, OutputArray _dst, Size dsize, int wdepth = std::max(depth, is_area_fast ? CV_32S : CV_32F); int wtype = CV_MAKE_TYPE(wdepth, cn); - char cvt[2][40]; + char cvt[2][50]; String buildOption = format("-D INTER_AREA -D T=%s -D T1=%s -D WTV=%s -D convertToWTV=%s -D cn=%d", ocl::typeToStr(type), ocl::typeToStr(depth), ocl::typeToStr(wtype), ocl::convertTypeStr(depth, wdepth, cn, cvt[0]), cn); diff --git a/modules/imgproc/src/templmatch.cpp b/modules/imgproc/src/templmatch.cpp index 6b192d775f..edf214385e 100644 --- a/modules/imgproc/src/templmatch.cpp +++ b/modules/imgproc/src/templmatch.cpp @@ -87,7 +87,7 @@ static bool sumTemplate(InputArray _src, UMat & result) wgs2_aligned <<= 1; wgs2_aligned >>= 1; - char cvt[40]; + char cvt[50]; ocl::Kernel k("calcSum", ocl::imgproc::match_template_oclsrc, format("-D CALC_SUM -D T=%s -D T1=%s -D WT=%s -D cn=%d -D convertToWT=%s -D WGS=%d -D WGS2_ALIGNED=%d", ocl::typeToStr(type), ocl::typeToStr(depth), ocl::typeToStr(wtype), cn, @@ -268,8 +268,8 @@ static bool matchTemplateNaive_CCORR(InputArray _image, InputArray _templ, Outpu wtype1 = CV_MAKE_TYPE(wdepth, rated_cn); } - char cvt[40]; - char cvt1[40]; + char cvt[50]; + char cvt1[50]; const char* convertToWT1 = ocl::convertTypeStr(depth, wdepth, cn, cvt); const char* convertToWT = ocl::convertTypeStr(depth, wdepth, rated_cn, cvt1); @@ -349,7 +349,7 @@ static bool matchTemplateNaive_SQDIFF(InputArray _image, InputArray _templ, Outp int type = _image.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); int wdepth = CV_32F, wtype = CV_MAKE_TYPE(wdepth, cn); - char cvt[40]; + char cvt[50]; ocl::Kernel k("matchTemplate_Naive_SQDIFF", ocl::imgproc::match_template_oclsrc, format("-D SQDIFF -D T=%s -D T1=%s -D WT=%s -D convertToWT=%s -D cn=%d", ocl::typeToStr(type), ocl::typeToStr(depth), ocl::typeToStr(wtype), ocl::convertTypeStr(depth, wdepth, cn, cvt), cn)); diff --git a/modules/photo/src/fast_nlmeans_denoising_opencl.hpp b/modules/photo/src/fast_nlmeans_denoising_opencl.hpp index cb3327d392..0788a47964 100644 --- a/modules/photo/src/fast_nlmeans_denoising_opencl.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_opencl.hpp @@ -57,7 +57,7 @@ static bool ocl_calcAlmostDist2Weight(UMat & almostDist2Weight, almostDist2Weight.create(1, almostMaxDist, CV_32SC(hn == 3 ? 4 : hn)); - char buf[40]; + char buf[50]; ocl::Kernel k("calcAlmostDist2Weight", ocl::photo::nlmeans_oclsrc, format("-D OP_CALC_WEIGHTS -D FT=%s -D w_t=%s" " -D wlut_t=%s -D convert_wlut_t=%s%s%s",