diff --git a/apps/traincascade/boost.cpp b/apps/traincascade/boost.cpp index ee0486ec90..8f0d394a0e 100644 --- a/apps/traincascade/boost.cpp +++ b/apps/traincascade/boost.cpp @@ -1677,7 +1677,7 @@ void CvCascadeBoost::write( FileStorage &fs, const Mat& featureMap ) const fs << CC_WEAK_CLASSIFIERS << "["; for( int wi = 0; wi < weak->total; wi++) { - /*sprintf( cmnt, "tree %i", wi ); + /*snprintf( cmnt, sizeof(cmnt), "tree %i", wi ); cvWriteComment( fs, cmnt, 0 );*/ weakTree = *((CvCascadeBoostTree**) cvGetSeqElem( weak, wi )); weakTree->write( fs, featureMap ); diff --git a/apps/traincascade/cascadeclassifier.cpp b/apps/traincascade/cascadeclassifier.cpp index 5a83746bc4..d43625d879 100644 --- a/apps/traincascade/cascadeclassifier.cpp +++ b/apps/traincascade/cascadeclassifier.cpp @@ -253,7 +253,7 @@ bool CvCascadeClassifier::train( const string _cascadeDirName, } // save current stage char buf[32]; - sprintf(buf, "%s%d", "stage", i ); + snprintf(buf, sizeof(buf), "%s%d", "stage", i ); string stageFilename = dirName + buf + ".xml"; FileStorage fs( stageFilename, FileStorage::WRITE ); if ( !fs.isOpened() ) @@ -369,7 +369,7 @@ void CvCascadeClassifier::writeStages( FileStorage &fs, const Mat& featureMap ) for( vector< Ptr >::const_iterator it = stageClassifiers.begin(); it != stageClassifiers.end();++it, ++i ) { - sprintf( cmnt, "stage %d", i ); + snprintf( cmnt, sizeof(cmnt), "stage %d", i ); cvWriteComment( fs.fs, cmnt, 0 ); fs << "{"; (*it)->write( fs, featureMap ); @@ -460,7 +460,7 @@ void CvCascadeClassifier::save( const string filename, bool baseFormat ) for( size_t si = 0; si < stageClassifiers.size(); si++ ) { fs << "{"; //stage - /*sprintf( buf, "stage %d", si ); + /*snprintf( buf, sizeof(buf), "stage %d", si ); CV_CALL( cvWriteComment( fs, buf, 1 ) );*/ weak = stageClassifiers[si]->get_weak_predictors(); fs << ICV_HAAR_TREES_NAME << "["; @@ -471,7 +471,7 @@ void CvCascadeClassifier::save( const string filename, bool baseFormat ) CvCascadeBoostTree* tree = *((CvCascadeBoostTree**) cvGetSeqElem( weak, wi )); fs << "["; - /*sprintf( buf, "tree %d", wi ); + /*snprintf( buf, sizeof(buf), "tree %d", wi ); CV_CALL( cvWriteComment( fs, buf, 1 ) );*/ const CvDTreeNode* tempNode; @@ -535,10 +535,10 @@ bool CvCascadeClassifier::load( const string cascadeDirName ) featureEvaluator->init( featureParams, numPos + numNeg, cascadeParams.winSize ); fs.release(); - char buf[16] = {0}; + char buf[5+10+1] = {0}; for ( int si = 0; si < numStages; si++ ) { - sprintf( buf, "%s%d", "stage", si); + snprintf( buf, sizeof(buf), "%s%d", "stage", si); fs.open( cascadeDirName + buf + ".xml", FileStorage::READ ); node = fs.getFirstTopLevelNode(); if ( !fs.isOpened() ) diff --git a/apps/traincascade/old_ml_inner_functions.cpp b/apps/traincascade/old_ml_inner_functions.cpp index 5858a4014a..3657c7f8b5 100644 --- a/apps/traincascade/old_ml_inner_functions.cpp +++ b/apps/traincascade/old_ml_inner_functions.cpp @@ -520,7 +520,7 @@ cvPreprocessCategoricalResponses( const CvMat* responses, if( ri != rf ) { char buf[100]; - sprintf( buf, "response #%d is not integral", idx ); + snprintf( buf, sizeof(buf), "response #%d is not integral", idx ); CV_ERROR( CV_StsBadArg, buf ); } dst[i] = ri; diff --git a/apps/traincascade/old_ml_tree.cpp b/apps/traincascade/old_ml_tree.cpp index cfba9ec952..96ea93351d 100644 --- a/apps/traincascade/old_ml_tree.cpp +++ b/apps/traincascade/old_ml_tree.cpp @@ -442,7 +442,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag, val = cvRound(t); if( fabs(t - val) > FLT_EPSILON ) { - sprintf( err, "%d-th value of %d-th (categorical) " + snprintf( err, sizeof(err), "%d-th value of %d-th (categorical) " "variable is not an integer", i, vi ); CV_ERROR( CV_StsBadArg, err ); } @@ -450,7 +450,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag, if( val == INT_MAX ) { - sprintf( err, "%d-th value of %d-th (categorical) " + snprintf( err, sizeof(err), "%d-th value of %d-th (categorical) " "variable is too large", i, vi ); CV_ERROR( CV_StsBadArg, err ); } @@ -557,7 +557,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag, if( fabs(val) >= ord_nan ) { - sprintf( err, "%d-th value of %d-th (ordered) " + snprintf( err, sizeof(err), "%d-th value of %d-th (ordered) " "variable (=%g) is too large", i, vi, val ); CV_ERROR( CV_StsBadArg, err ); } diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 96bfb25290..604b13101d 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -92,7 +92,7 @@ static bool ocl_binary_op(InputArray _src1, InputArray _src2, OutputArray _dst, const int dstType1 = CV_MAKETYPE(dstDepth, 1); const int scalarType = CV_MAKETYPE(srcdepth, scalarcn); - sprintf(opts, "-D %s%s -D %s%s -D dstT=%s -D DEPTH_dst=%d -D dstT_C1=%s -D workST=%s -D cn=%d -D rowsPerWI=%d", + snprintf(opts, sizeof(opts), "-D %s%s -D %s%s -D dstT=%s -D DEPTH_dst=%d -D dstT_C1=%s -D workST=%s -D cn=%d -D rowsPerWI=%d", haveMask ? "MASK_" : "", haveScalar ? "UNARY_OP" : "BINARY_OP", oclop2str[oclop], doubleSupport ? " -D DOUBLE_SUPPORT" : "", bitwise ? ocl::memopTypeToStr(dstType) : ocl::typeToStr(dstType), @@ -490,7 +490,7 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, int scalarcn = kercn == 3 ? 4 : kercn, rowsPerWI = d.isIntel() ? 4 : 1; char cvtstr[4][32], opts[1024]; - sprintf(opts, "-D %s%s -D %s -D srcT1=%s -D srcT1_C1=%s -D srcT2=%s -D srcT2_C1=%s " + 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", (haveMask ? "MASK_" : ""), (haveScalar ? "UNARY_OP" : "BINARY_OP"), diff --git a/modules/core/src/out.cpp b/modules/core/src/out.cpp index aad8429e2d..8a7d7e1636 100644 --- a/modules/core/src/out.cpp +++ b/modules/core/src/out.cpp @@ -70,14 +70,14 @@ namespace cv char braces[5]; void (FormattedImpl::*valueToStr)(); - void valueToStr8u() { sprintf(buf, "%3d", (int)mtx.ptr(row, col)[cn]); } - void valueToStr8s() { sprintf(buf, "%3d", (int)mtx.ptr(row, col)[cn]); } - void valueToStr16u() { sprintf(buf, "%d", (int)mtx.ptr(row, col)[cn]); } - void valueToStr16s() { sprintf(buf, "%d", (int)mtx.ptr(row, col)[cn]); } - void valueToStr32s() { sprintf(buf, "%d", mtx.ptr(row, col)[cn]); } - void valueToStr32f() { sprintf(buf, floatFormat, mtx.ptr(row, col)[cn]); } - void valueToStr64f() { sprintf(buf, floatFormat, mtx.ptr(row, col)[cn]); } - void valueToStr16f() { sprintf(buf, floatFormat, (float)mtx.ptr(row, col)[cn]); } + void valueToStr8u() { snprintf(buf, sizeof(buf), "%3d", (int)mtx.ptr(row, col)[cn]); } + void valueToStr8s() { snprintf(buf, sizeof(buf), "%3d", (int)mtx.ptr(row, col)[cn]); } + void valueToStr16u() { snprintf(buf, sizeof(buf), "%d", (int)mtx.ptr(row, col)[cn]); } + void valueToStr16s() { snprintf(buf, sizeof(buf), "%d", (int)mtx.ptr(row, col)[cn]); } + void valueToStr32s() { snprintf(buf, sizeof(buf), "%d", mtx.ptr(row, col)[cn]); } + void valueToStr32f() { snprintf(buf, sizeof(buf), floatFormat, mtx.ptr(row, col)[cn]); } + void valueToStr64f() { snprintf(buf, sizeof(buf), floatFormat, mtx.ptr(row, col)[cn]); } + void valueToStr16f() { snprintf(buf, sizeof(buf), floatFormat, (float)mtx.ptr(row, col)[cn]); } void valueToStrOther() { buf[0] = 0; } public: @@ -151,10 +151,10 @@ namespace cv } else row = 0; - sprintf(buf, "\n(:, :, %d) = \n", cn+1); + snprintf(buf, sizeof(buf), "\n(:, :, %d) = \n", cn+1); return buf; } - sprintf(buf, "(:, :, %d) = \n", cn+1); + snprintf(buf, sizeof(buf), "(:, :, %d) = \n", cn+1); return buf; case STATE_EPILOGUE: state = STATE_FINISHED; diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 09435b5850..59f843d5bc 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -56,7 +56,7 @@ char* itoa( int _val, char* buffer, int /*radix*/ ) return ptr; } -char* doubleToString( char* buf, double value, bool explicitZero ) +char* doubleToString( char* buf, size_t bufSize, double value, bool explicitZero ) { Cv64suf val; unsigned ieee754_hi; @@ -70,15 +70,15 @@ char* doubleToString( char* buf, double value, bool explicitZero ) if( ivalue == value ) { if( explicitZero ) - sprintf( buf, "%d.0", ivalue ); + snprintf( buf, bufSize, "%d.0", ivalue ); else - sprintf( buf, "%d.", ivalue ); + snprintf( buf, bufSize, "%d.", ivalue ); } else { static const char* fmt = "%.16e"; char* ptr = buf; - sprintf( buf, fmt, value ); + snprintf( buf, bufSize, fmt, value ); if( *ptr == '+' || *ptr == '-' ) ptr++; for( ; cv_isdigit(*ptr); ptr++ ) @@ -99,7 +99,7 @@ char* doubleToString( char* buf, double value, bool explicitZero ) return buf; } -char* floatToString( char* buf, float value, bool halfprecision, bool explicitZero ) +char* floatToString( char* buf, size_t bufSize, float value, bool halfprecision, bool explicitZero ) { Cv32suf val; unsigned ieee754; @@ -112,17 +112,17 @@ char* floatToString( char* buf, float value, bool halfprecision, bool explicitZe if( ivalue == value ) { if( explicitZero ) - sprintf( buf, "%d.0", ivalue ); + snprintf( buf, bufSize, "%d.0", ivalue ); else - sprintf( buf, "%d.", ivalue ); + snprintf( buf, bufSize, "%d.", ivalue ); } else { char* ptr = buf; if (halfprecision) - sprintf(buf, "%.4e", value); + snprintf(buf, bufSize, "%.4e", value); else - sprintf(buf, "%.8e", value); + snprintf(buf, bufSize, "%.8e", value); if( *ptr == '+' || *ptr == '-' ) ptr++; for( ; cv_isdigit(*ptr); ptr++ ) @@ -585,7 +585,7 @@ bool FileStorage::Impl::open(const char *filename_or_buf, int _flags, const char CV_Assert(strlen(encoding) < 1000); char buf[1100]; - sprintf(buf, "\n", encoding); + snprintf(buf, sizeof(buf), "\n", encoding); puts(buf); } else puts("\n"); @@ -1107,15 +1107,15 @@ void FileStorage::Impl::writeRawData(const std::string &dt, const void *_data, s data += sizeof(int); break; case CV_32F: - ptr = fs::floatToString(buf, *(float *) data, false, explicitZero); + ptr = fs::floatToString(buf, sizeof(buf), *(float *) data, false, explicitZero); data += sizeof(float); break; case CV_64F: - ptr = fs::doubleToString(buf, *(double *) data, explicitZero); + ptr = fs::doubleToString(buf, sizeof(buf), *(double *) data, explicitZero); data += sizeof(double); break; case CV_16F: /* reference */ - ptr = fs::floatToString(buf, (float) *(float16_t *) data, true, explicitZero); + ptr = fs::floatToString(buf, sizeof(buf), (float) *(float16_t *) data, true, explicitZero); data += sizeof(float16_t); break; default: diff --git a/modules/core/src/persistence.hpp b/modules/core/src/persistence.hpp index 1a9dbecf7c..fb7f5acf45 100644 --- a/modules/core/src/persistence.hpp +++ b/modules/core/src/persistence.hpp @@ -86,8 +86,8 @@ namespace fs { int strcasecmp(const char* str1, const char* str2); char* itoa( int _val, char* buffer, int /*radix*/ ); -char* floatToString( char* buf, float value, bool halfprecision, bool explicitZero ); -char* doubleToString( char* buf, double value, bool explicitZero ); +char* floatToString( char* buf, size_t bufSize, float value, bool halfprecision, bool explicitZero ); +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 ); diff --git a/modules/core/src/persistence_json.cpp b/modules/core/src/persistence_json.cpp index 12a58e80bf..e201215401 100644 --- a/modules/core/src/persistence_json.cpp +++ b/modules/core/src/persistence_json.cpp @@ -84,7 +84,7 @@ public: void write( const char* key, double value ) { char buf[128]; - writeScalar( key, fs::doubleToString( buf, value, true )); + writeScalar( key, fs::doubleToString( buf, sizeof(buf), value, true )); } void write(const char* key, const char* str, bool quote) diff --git a/modules/core/src/persistence_xml.cpp b/modules/core/src/persistence_xml.cpp index f664476fbc..2264d16baa 100644 --- a/modules/core/src/persistence_xml.cpp +++ b/modules/core/src/persistence_xml.cpp @@ -148,7 +148,7 @@ public: void write( const char* key, double value ) { char buf[128]; - writeScalar( key, fs::doubleToString( buf, value, false ) ); + writeScalar( key, fs::doubleToString( buf, sizeof(buf), value, false ) ); } void write(const char* key, const char* str, bool quote) diff --git a/modules/core/src/persistence_yml.cpp b/modules/core/src/persistence_yml.cpp index 5219ee076b..c8c7c7a892 100644 --- a/modules/core/src/persistence_yml.cpp +++ b/modules/core/src/persistence_yml.cpp @@ -40,7 +40,7 @@ public: { /* reset struct flag. in order not to print ']' */ struct_flags = FileNode::SEQ; - sprintf(buf, "!!binary |"); + snprintf(buf, sizeof(buf), "!!binary |"); data = buf; } else if( FileNode::isFlow(struct_flags)) @@ -49,7 +49,7 @@ public: struct_flags |= FileNode::FLOW; if( type_name ) - sprintf( buf, "!!%s %c", type_name, c ); + snprintf( buf, sizeof(buf), "!!%s %c", type_name, c ); else { buf[0] = c; @@ -59,7 +59,7 @@ public: } else if( type_name ) { - sprintf( buf, "!!%s", type_name ); + snprintf( buf, sizeof(buf), "!!%s", type_name ); data = buf; } @@ -110,7 +110,7 @@ public: void write( const char* key, double value ) { char buf[128]; - writeScalar( key, fs::doubleToString( buf, value, false )); + writeScalar( key, fs::doubleToString( buf, sizeof(buf), value, false )); } void write(const char* key, const char* str, bool quote) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 4c79c357b5..cac5cd11f1 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1385,7 +1385,7 @@ CV_IMPL const char* cvErrorStr( int status ) case CV_OpenGlApiCallError : return "OpenGL API call"; }; - sprintf(buf, "Unknown %s code %d", status >= 0 ? "status":"error", status); + snprintf(buf, sizeof(buf), "Unknown %s code %d", status >= 0 ? "status":"error", status); return buf; } diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 04426e58f7..5e1f6d7a8e 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -487,7 +487,7 @@ TEST(Core_InputOutput, FileStorage) cv::FileStorage f(file, cv::FileStorage::WRITE); char arr[66]; - sprintf(arr, "sprintf is hell %d", 666); + snprintf(arr, sizeof(arr), "snprintf is hell %d", 666); EXPECT_NO_THROW(f << arr); } @@ -1765,8 +1765,8 @@ TEST(Core_InputOutput, FileStorage_JSON_VeryLongLines) std::string val; for(int i = 0; i < 52500; i += 100) { - sprintf(key, "KEY%d", i); - sprintf(val0, "VALUE%d", i); + snprintf(key, sizeof(key), "KEY%d", i); + snprintf(val0, sizeof(val0), "VALUE%d", i); fs[key] >> val; ASSERT_EQ(val, val0); } diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 61ba306ba6..68de691260 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -161,7 +161,7 @@ int Core_ReduceTest::checkOp( const Mat& src, int dstType, int opType, const Mat getMatTypeStr( dstType, dstTypeStr ); const char* dimStr = dim == 0 ? "ROWS" : "COLS"; - sprintf( msg, "bad accuracy with srcType = %s, dstType = %s, opType = %s, dim = %s", + snprintf( msg, sizeof(msg), "bad accuracy with srcType = %s, dstType = %s, opType = %s, dim = %s", srcTypeStr.c_str(), dstTypeStr.c_str(), opTypeStr, dimStr ); ts->printf( cvtest::TS::LOG, msg ); return cvtest::TS::FAIL_BAD_ACCURACY; diff --git a/modules/imgproc/src/box_filter.dispatch.cpp b/modules/imgproc/src/box_filter.dispatch.cpp index c9ec693385..698f2ae2fb 100644 --- a/modules/imgproc/src/box_filter.dispatch.cpp +++ b/modules/imgproc/src/box_filter.dispatch.cpp @@ -89,7 +89,7 @@ static bool ocl_boxFilter3x3_8UC1( InputArray _src, OutputArray _dst, int ddepth globalsize[1] = size.height / 2; char build_opts[1024]; - sprintf(build_opts, "-D %s %s", borderMap[borderType], normalize ? "-D NORMALIZE" : ""); + snprintf(build_opts, sizeof(build_opts), "-D %s %s", borderMap[borderType], normalize ? "-D NORMALIZE" : ""); ocl::Kernel kernel("boxFilter3x3_8UC1_cols16_rows2", cv::ocl::imgproc::boxFilter3x3_oclsrc, build_opts); if (kernel.empty()) @@ -196,7 +196,7 @@ static bool ocl_boxFilter( InputArray _src, OutputArray _dst, int ddepth, globalsize[0] = roundUp(globalsize[0], wgRound); char build_options[1024], cvt[2][40]; - sprintf(build_options, "-D cn=%d " + 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 " "-D PX_PER_WI_X=%d -D PX_PER_WI_Y=%d -D PRIV_DATA_WIDTH=%d -D %s -D %s " diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 2d8b59926d..fb7e7786f5 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -384,7 +384,7 @@ static bool ocl_sepFilter3x3_8UC1(InputArray _src, OutputArray _dst, int ddepth, const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", 0, "BORDER_REFLECT_101" }; char build_opts[1024]; - sprintf(build_opts, "-D %s %s%s", borderMap[borderType], + snprintf(build_opts, sizeof(build_opts), "-D %s %s%s", borderMap[borderType], ocl::kernelToStr(kernelX, CV_32F, "KERNEL_MATRIX_X").c_str(), ocl::kernelToStr(kernelY, CV_32F, "KERNEL_MATRIX_Y").c_str()); @@ -684,7 +684,7 @@ static bool ocl_Laplacian3_8UC1(InputArray _src, OutputArray _dst, int ddepth, const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", 0, "BORDER_REFLECT_101" }; char build_opts[1024]; - sprintf(build_opts, "-D %s %s", borderMap[borderType], + snprintf(build_opts, sizeof(build_opts), "-D %s %s", borderMap[borderType], ocl::kernelToStr(kernel, CV_32F, "KERNEL_MATRIX").c_str()); ocl::Kernel k("laplacian3_8UC1_cols16_rows2", cv::ocl::imgproc::laplacian3_oclsrc, build_opts); diff --git a/modules/imgproc/src/filter.dispatch.cpp b/modules/imgproc/src/filter.dispatch.cpp index c9d1bb457c..097dd32055 100644 --- a/modules/imgproc/src/filter.dispatch.cpp +++ b/modules/imgproc/src/filter.dispatch.cpp @@ -637,7 +637,7 @@ static bool ocl_filter2D( InputArray _src, OutputArray _dst, int ddepth, globalsize[0] = ROUNDUP(globalsize[0], wgRound); char build_options[1024]; - sprintf(build_options, "-D cn=%d " + 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 " "-D PX_PER_WI_X=%d -D PX_PER_WI_Y=%d -D PRIV_DATA_WIDTH=%d -D %s -D %s " diff --git a/modules/imgproc/src/smooth.dispatch.cpp b/modules/imgproc/src/smooth.dispatch.cpp index b001a37f89..f593f7bc2d 100644 --- a/modules/imgproc/src/smooth.dispatch.cpp +++ b/modules/imgproc/src/smooth.dispatch.cpp @@ -354,7 +354,7 @@ static bool ocl_GaussianBlur_8UC1(InputArray _src, OutputArray _dst, Size ksize, const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", 0, "BORDER_REFLECT_101" }; char build_opts[1024]; - sprintf(build_opts, "-D %s %s%s", borderMap[borderType & ~BORDER_ISOLATED], + snprintf(build_opts, sizeof(build_opts), "-D %s %s%s", borderMap[borderType & ~BORDER_ISOLATED], ocl::kernelToStr(kernelX, CV_32F, "KERNEL_MATRIX_X").c_str(), ocl::kernelToStr(kernelY, CV_32F, "KERNEL_MATRIX_Y").c_str()); diff --git a/modules/imgproc/test/test_imgwarp_strict.cpp b/modules/imgproc/test/test_imgwarp_strict.cpp index 5ca3d09ec4..eea5e447e9 100644 --- a/modules/imgproc/test/test_imgwarp_strict.cpp +++ b/modules/imgproc/test/test_imgwarp_strict.cpp @@ -48,7 +48,7 @@ void __wrap_printf_func(const char* fmt, ...) va_list args; va_start(args, fmt); char buffer[256]; - vsprintf (buffer, fmt, args); + vsnprintf (buffer, sizeof(buffer), fmt, args); cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, buffer); va_end(args); } diff --git a/modules/python/src2/pycompat.hpp b/modules/python/src2/pycompat.hpp index 18336d4295..ceaee06f49 100644 --- a/modules/python/src2/pycompat.hpp +++ b/modules/python/src2/pycompat.hpp @@ -234,7 +234,7 @@ PyObject* pyopencv_from(const TYPE& src) static PyObject* pyopencv_##CLASS_ID##_repr(PyObject* self) \ { \ char str[1000]; \ - sprintf(str, "< " MODULESTR SCOPE"."#EXPORT_NAME" %p>", self); \ + snprintf(str, sizeof(str), "< " MODULESTR SCOPE"."#EXPORT_NAME" %p>", self); \ return PyString_FromString(str); \ } @@ -294,7 +294,7 @@ PyObject* pyopencv_from(const TYPE& src) static PyObject* pyopencv_##CLASS_ID##_repr(PyObject* self) \ { \ char str[1000]; \ - sprintf(str, "< " MODULESTR SCOPE"."#EXPORT_NAME" %p>", self); \ + snprintf(str, sizeof(str), "< " MODULESTR SCOPE"."#EXPORT_NAME" %p>", self); \ return PyString_FromString(str); \ } \ static PyType_Slot pyopencv_##CLASS_ID##_Slots[] = \ diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index e629c307fb..3539f17646 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -312,7 +312,7 @@ void BaseTest::safe_run( int start_from ) char buf[1 << 16]; const char* delim = exc.err.find('\n') == cv::String::npos ? "" : "\n"; - sprintf( buf, "OpenCV Error:\n\t%s (%s%s) in %s, file %s, line %d", + snprintf( buf, sizeof(buf), "OpenCV Error:\n\t%s (%s%s) in %s, file %s, line %d", errorStr, delim, exc.err.c_str(), exc.func.size() > 0 ? exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line ); ts->printf(TS::LOG, "%s\n", buf); @@ -603,7 +603,7 @@ void TS::set_gtest_status() return SUCCEED(); char seedstr[32]; - sprintf(seedstr, "%08x%08x", (unsigned)(current_test_info.rng_seed>>32), + snprintf(seedstr, sizeof(seedstr), "%08x%08x", (unsigned)(current_test_info.rng_seed>>32), (unsigned)(current_test_info.rng_seed)); string logs = ""; diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 525150894e..d64f52927b 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -29,7 +29,7 @@ string vec2str( const string& sep, const int* v, size_t nelems ) string result = ""; for( size_t i = 0; i < nelems; i++ ) { - sprintf(buf, "%d", v[i]); + snprintf(buf, sizeof(buf), "%d", v[i]); result += string(buf); if( i < nelems - 1 ) result += sep; @@ -2154,15 +2154,15 @@ int cmpEps2( TS* ts, const Mat& a, const Mat& b, double success_err_level, switch( code ) { case CMP_EPS_BIG_DIFF: - sprintf( msg, "%s: Too big difference (=%g > %g)", desc, diff, success_err_level ); + snprintf( msg, sizeof(msg), "%s: Too big difference (=%g > %g)", desc, diff, success_err_level ); code = TS::FAIL_BAD_ACCURACY; break; case CMP_EPS_INVALID_TEST_DATA: - sprintf( msg, "%s: Invalid output", desc ); + snprintf( msg, sizeof(msg), "%s: Invalid output", desc ); code = TS::FAIL_INVALID_OUTPUT; break; case CMP_EPS_INVALID_REF_DATA: - sprintf( msg, "%s: Invalid reference output", desc ); + snprintf( msg, sizeof(msg), "%s: Invalid reference output", desc ); code = TS::FAIL_INVALID_OUTPUT; break; default: diff --git a/modules/video/test/test_optflowpyrlk.cpp b/modules/video/test/test_optflowpyrlk.cpp index a79a0ff4e4..6e0ee3756e 100644 --- a/modules/video/test/test_optflowpyrlk.cpp +++ b/modules/video/test/test_optflowpyrlk.cpp @@ -78,7 +78,7 @@ void CV_OptFlowPyrLKTest::run( int ) for(;;) { - sprintf( filename, "%soptflow/%s", ts->get_data_path().c_str(), "lk_prev.dat" ); + snprintf( filename, sizeof(filename), "%soptflow/%s", ts->get_data_path().c_str(), "lk_prev.dat" ); { FileStorage fs(filename, FileStorage::READ); @@ -91,7 +91,7 @@ void CV_OptFlowPyrLKTest::run( int ) } } - sprintf( filename, "%soptflow/%s", ts->get_data_path().c_str(), "lk_next.dat" ); + snprintf( filename, sizeof(filename), "%soptflow/%s", ts->get_data_path().c_str(), "lk_next.dat" ); { FileStorage fs(filename, FileStorage::READ); @@ -115,7 +115,7 @@ void CV_OptFlowPyrLKTest::run( int ) } /* read first image */ - sprintf( filename, "%soptflow/%s", ts->get_data_path().c_str(), "rock_1.bmp" ); + snprintf( filename, sizeof(filename), "%soptflow/%s", ts->get_data_path().c_str(), "rock_1.bmp" ); imgI = cv::imread( filename, cv::IMREAD_UNCHANGED ); if( imgI.empty() ) @@ -126,7 +126,7 @@ void CV_OptFlowPyrLKTest::run( int ) } /* read second image */ - sprintf( filename, "%soptflow/%s", ts->get_data_path().c_str(), "rock_2.bmp" ); + snprintf( filename, sizeof(filename), "%soptflow/%s", ts->get_data_path().c_str(), "rock_2.bmp" ); imgJ = cv::imread( filename, cv::IMREAD_UNCHANGED ); if( imgJ.empty() ) diff --git a/modules/videoio/src/cap_dshow.cpp b/modules/videoio/src/cap_dshow.cpp index 2f2ff51413..e4de20bcac 100644 --- a/modules/videoio/src/cap_dshow.cpp +++ b/modules/videoio/src/cap_dshow.cpp @@ -88,11 +88,6 @@ Thanks to: */ ///////////////////////////////////////////////////////// -#if defined _MSC_VER && _MSC_VER >= 100 -//'sprintf': name was marked as #pragma deprecated -#pragma warning(disable: 4995) -#endif - #if defined(__clang__) // clang or MSVC clang #pragma clang diagnostic ignored "-Wnon-virtual-dtor" #elif defined(__GNUC__) // MinGW @@ -2304,29 +2299,29 @@ void videoInput::processPixels(unsigned char * src, unsigned char * dst, int wid void videoInput::getMediaSubtypeAsString(GUID type, char * typeAsString){ char tmpStr[8]; - if( type == MEDIASUBTYPE_RGB24) sprintf(tmpStr, "RGB24"); - else if(type == MEDIASUBTYPE_RGB32) sprintf(tmpStr, "RGB32"); - else if(type == MEDIASUBTYPE_RGB555)sprintf(tmpStr, "RGB555"); - else if(type == MEDIASUBTYPE_RGB565)sprintf(tmpStr, "RGB565"); - else if(type == MEDIASUBTYPE_YUY2) sprintf(tmpStr, "YUY2"); - else if(type == MEDIASUBTYPE_YVYU) sprintf(tmpStr, "YVYU"); - else if(type == MEDIASUBTYPE_YUYV) sprintf(tmpStr, "YUYV"); - else if(type == MEDIASUBTYPE_IYUV) sprintf(tmpStr, "IYUV"); - else if(type == MEDIASUBTYPE_UYVY) sprintf(tmpStr, "UYVY"); - else if(type == MEDIASUBTYPE_YV12) sprintf(tmpStr, "YV12"); - else if(type == MEDIASUBTYPE_YVU9) sprintf(tmpStr, "YVU9"); - else if(type == MEDIASUBTYPE_Y411) sprintf(tmpStr, "Y411"); - else if(type == MEDIASUBTYPE_Y41P) sprintf(tmpStr, "Y41P"); - else if(type == MEDIASUBTYPE_Y211) sprintf(tmpStr, "Y211"); - else if(type == MEDIASUBTYPE_AYUV) sprintf(tmpStr, "AYUV"); - else if(type == MEDIASUBTYPE_MJPG) sprintf(tmpStr, "MJPG"); - else if(type == MEDIASUBTYPE_Y800) sprintf(tmpStr, "Y800"); - else if(type == MEDIASUBTYPE_Y8) sprintf(tmpStr, "Y8"); - else if(type == MEDIASUBTYPE_GREY) sprintf(tmpStr, "GREY"); - else if(type == MEDIASUBTYPE_I420) sprintf(tmpStr, "I420"); - else if (type == MEDIASUBTYPE_BY8) sprintf(tmpStr, "BY8"); - else if (type == MEDIASUBTYPE_Y16) sprintf(tmpStr, "Y16"); - else sprintf(tmpStr, "OTHER"); + if( type == MEDIASUBTYPE_RGB24) snprintf(tmpStr, sizeof(tmpStr), "RGB24"); + else if(type == MEDIASUBTYPE_RGB32) snprintf(tmpStr, sizeof(tmpStr), "RGB32"); + else if(type == MEDIASUBTYPE_RGB555)snprintf(tmpStr, sizeof(tmpStr), "RGB555"); + else if(type == MEDIASUBTYPE_RGB565)snprintf(tmpStr, sizeof(tmpStr), "RGB565"); + else if(type == MEDIASUBTYPE_YUY2) snprintf(tmpStr, sizeof(tmpStr), "YUY2"); + else if(type == MEDIASUBTYPE_YVYU) snprintf(tmpStr, sizeof(tmpStr), "YVYU"); + else if(type == MEDIASUBTYPE_YUYV) snprintf(tmpStr, sizeof(tmpStr), "YUYV"); + else if(type == MEDIASUBTYPE_IYUV) snprintf(tmpStr, sizeof(tmpStr), "IYUV"); + else if(type == MEDIASUBTYPE_UYVY) snprintf(tmpStr, sizeof(tmpStr), "UYVY"); + else if(type == MEDIASUBTYPE_YV12) snprintf(tmpStr, sizeof(tmpStr), "YV12"); + else if(type == MEDIASUBTYPE_YVU9) snprintf(tmpStr, sizeof(tmpStr), "YVU9"); + else if(type == MEDIASUBTYPE_Y411) snprintf(tmpStr, sizeof(tmpStr), "Y411"); + else if(type == MEDIASUBTYPE_Y41P) snprintf(tmpStr, sizeof(tmpStr), "Y41P"); + else if(type == MEDIASUBTYPE_Y211) snprintf(tmpStr, sizeof(tmpStr), "Y211"); + else if(type == MEDIASUBTYPE_AYUV) snprintf(tmpStr, sizeof(tmpStr), "AYUV"); + else if(type == MEDIASUBTYPE_MJPG) snprintf(tmpStr, sizeof(tmpStr), "MJPG"); + else if(type == MEDIASUBTYPE_Y800) snprintf(tmpStr, sizeof(tmpStr), "Y800"); + else if(type == MEDIASUBTYPE_Y8) snprintf(tmpStr, sizeof(tmpStr), "Y8"); + else if(type == MEDIASUBTYPE_GREY) snprintf(tmpStr, sizeof(tmpStr), "GREY"); + else if(type == MEDIASUBTYPE_I420) snprintf(tmpStr, sizeof(tmpStr), "I420"); + else if (type == MEDIASUBTYPE_BY8) snprintf(tmpStr, sizeof(tmpStr), "BY8"); + else if (type == MEDIASUBTYPE_Y16) snprintf(tmpStr, sizeof(tmpStr), "Y16"); + else snprintf(tmpStr, sizeof(tmpStr), "OTHER"); memcpy(typeAsString, tmpStr, sizeof(char)*8); } @@ -2352,15 +2347,15 @@ void videoInput::getVideoPropertyAsString(int prop, char * propertyAsString){ char tmpStr[16]; - if ( prop==VideoProcAmp_Brightness) sprintf(tmpStr, "Brightness"); - else if ( prop==VideoProcAmp_Contrast) sprintf(tmpStr, "Contrast"); - else if ( prop==VideoProcAmp_Saturation) sprintf(tmpStr, "Saturation"); - else if ( prop==VideoProcAmp_Hue) sprintf(tmpStr, "Hue"); - else if ( prop==VideoProcAmp_Gain) sprintf(tmpStr, "Gain"); - else if ( prop==VideoProcAmp_Gamma) sprintf(tmpStr, "Gamma"); - else if ( prop==VideoProcAmp_ColorEnable) sprintf(tmpStr, "ColorEnable"); - else if ( prop==VideoProcAmp_Sharpness) sprintf(tmpStr, "Sharpness"); - else sprintf(tmpStr, "%u",prop); + if ( prop==VideoProcAmp_Brightness) snprintf(tmpStr, sizeof(tmpStr), "Brightness"); + else if ( prop==VideoProcAmp_Contrast) snprintf(tmpStr, sizeof(tmpStr), "Contrast"); + else if ( prop==VideoProcAmp_Saturation) snprintf(tmpStr, sizeof(tmpStr), "Saturation"); + else if ( prop==VideoProcAmp_Hue) snprintf(tmpStr, sizeof(tmpStr), "Hue"); + else if ( prop==VideoProcAmp_Gain) snprintf(tmpStr, sizeof(tmpStr), "Gain"); + else if ( prop==VideoProcAmp_Gamma) snprintf(tmpStr, sizeof(tmpStr), "Gamma"); + else if ( prop==VideoProcAmp_ColorEnable) snprintf(tmpStr, sizeof(tmpStr), "ColorEnable"); + else if ( prop==VideoProcAmp_Sharpness) snprintf(tmpStr, sizeof(tmpStr), "Sharpness"); + else snprintf(tmpStr, sizeof(tmpStr), "%u",prop); memcpy(propertyAsString, tmpStr, sizeof(char)*16); } @@ -2455,14 +2450,14 @@ void videoInput::getCameraPropertyAsString(int prop, char * propertyAsString){ char tmpStr[16]; - if ( prop==CameraControl_Pan) sprintf(tmpStr, "Pan"); - else if ( prop==CameraControl_Tilt) sprintf(tmpStr, "Tilt"); - else if ( prop==CameraControl_Roll) sprintf(tmpStr, "Roll"); - else if ( prop==CameraControl_Zoom) sprintf(tmpStr, "Zoom"); - else if ( prop==CameraControl_Exposure) sprintf(tmpStr, "Exposure"); - else if ( prop==CameraControl_Iris) sprintf(tmpStr, "Iris"); - else if ( prop==CameraControl_Focus) sprintf(tmpStr, "Focus"); - else sprintf(tmpStr, "%u",prop); + if ( prop==CameraControl_Pan) snprintf(tmpStr, sizeof(tmpStr), "Pan"); + else if ( prop==CameraControl_Tilt) snprintf(tmpStr, sizeof(tmpStr), "Tilt"); + else if ( prop==CameraControl_Roll) snprintf(tmpStr, sizeof(tmpStr), "Roll"); + else if ( prop==CameraControl_Zoom) snprintf(tmpStr, sizeof(tmpStr), "Zoom"); + else if ( prop==CameraControl_Exposure) snprintf(tmpStr, sizeof(tmpStr), "Exposure"); + else if ( prop==CameraControl_Iris) snprintf(tmpStr, sizeof(tmpStr), "Iris"); + else if ( prop==CameraControl_Focus) snprintf(tmpStr, sizeof(tmpStr), "Focus"); + else snprintf(tmpStr, sizeof(tmpStr), "%u",prop); memcpy(propertyAsString, tmpStr, sizeof(char)*16); } diff --git a/modules/videoio/src/cap_gphoto2.cpp b/modules/videoio/src/cap_gphoto2.cpp index 40fcdc4403..8b3898b2ad 100644 --- a/modules/videoio/src/cap_gphoto2.cpp +++ b/modules/videoio/src/cap_gphoto2.cpp @@ -667,7 +667,7 @@ double DigitalCameraCapture::getProperty(int propertyId) const catch (const GPhoto2Exception & e) { char buf[128] = ""; - sprintf(buf, "cannot get property: %d", propertyId); + snprintf(buf, sizeof(buf), "cannot get property: %d", propertyId); message(WARNING, (const char *) buf, e); return 0; } @@ -810,7 +810,7 @@ bool DigitalCameraCapture::setProperty(int propertyId, double value) catch (const GPhoto2Exception & e) { char buf[128] = ""; - sprintf(buf, "cannot set property: %d to %f", propertyId, value); + snprintf(buf, sizeof(buf), "cannot set property: %d to %f", propertyId, value); message(WARNING, (const char *) buf, e); return false; } diff --git a/modules/videoio/src/cap_ximea.cpp b/modules/videoio/src/cap_ximea.cpp index 7d572a2372..4573953939 100644 --- a/modules/videoio/src/cap_ximea.cpp +++ b/modules/videoio/src/cap_ximea.cpp @@ -1784,7 +1784,7 @@ void CvCaptureCAM_XIMEA::errMsg(const char* msg, int errNum) const #if defined _WIN32 char buf[512]=""; - sprintf( buf, "%s : %d, %s\n", msg, errNum, error_message.c_str()); + snprintf( buf, sizeof(buf), "%s : %d, %s\n", msg, errNum, error_message.c_str()); OutputDebugString(buf); #else fprintf(stderr, "%s : %d, %s\n", msg, errNum, error_message.c_str()); diff --git a/modules/videoio/src/cap_xine.cpp b/modules/videoio/src/cap_xine.cpp index 67de7b9319..08062fe4cf 100644 --- a/modules/videoio/src/cap_xine.cpp +++ b/modules/videoio/src/cap_xine.cpp @@ -111,7 +111,7 @@ class XINECapture : public IVideoCapture char configfile[2048] = {0}; xine = xine_new(); - sprintf(configfile, "%s%s", xine_get_homedir(), "/.xine/config"); + snprintf(configfile, sizeof(configfile), "%s%s", xine_get_homedir(), "/.xine/config"); xine_config_load(xine, configfile); xine_init(xine); xine_engine_set_param(xine, 0, 0); diff --git a/samples/cpp/calibration.cpp b/samples/cpp/calibration.cpp index f1ea78b304..4f2bb8b8b5 100644 --- a/samples/cpp/calibration.cpp +++ b/samples/cpp/calibration.cpp @@ -225,7 +225,7 @@ static void saveCameraParams( const string& filename, if( flags != 0 ) { - sprintf( buf, "flags: %s%s%s%s", + snprintf( buf, sizeof(buf), "flags: %s%s%s%s", flags & CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" : "", flags & CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "", flags & CALIB_FIX_PRINCIPAL_POINT ? "+fix_principal_point" : "", diff --git a/samples/cpp/select3dobj.cpp b/samples/cpp/select3dobj.cpp index f946565cf6..0f19eb2332 100644 --- a/samples/cpp/select3dobj.cpp +++ b/samples/cpp/select3dobj.cpp @@ -469,7 +469,7 @@ int main(int argc, char** argv) outbarename = strrchr(outprefix.c_str(), '/'); const char* tmp = strrchr(outprefix.c_str(), '\\'); char cmd[1000]; - sprintf(cmd, "mkdir %s", outprefix.c_str()); + snprintf(cmd, sizeof(cmd), "mkdir %s", outprefix.c_str()); if( tmp && tmp > outbarename ) outbarename = tmp; if( outbarename ) @@ -568,7 +568,7 @@ int main(int argc, char** argv) char path[1000]; for(;frameIdx < maxFrameIdx;frameIdx++) { - sprintf(path, "%s%04d.jpg", outprefix.c_str(), frameIdx); + snprintf(path, sizeof(path), "%s%04d.jpg", outprefix.c_str(), frameIdx); FILE* f = fopen(path, "rb"); if( !f ) break; diff --git a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp index eeeba0002d..82bbb3743a 100644 --- a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp +++ b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp @@ -60,7 +60,7 @@ int main( void ) //![create_trackbar] char TrackbarName[50]; - sprintf( TrackbarName, "Alpha x %d", alpha_slider_max ); + snprintf( TrackbarName, sizeof(TrackbarName), "Alpha x %d", alpha_slider_max ); createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar ); //![create_trackbar] diff --git a/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp index 12fa051ba3..5d1736a77a 100644 --- a/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp @@ -58,7 +58,7 @@ int main( int argc, char** argv ) /// Create Trackbars for Thresholds char thresh_label[50]; - sprintf( thresh_label, "Thres: %d + input", min_threshold ); + snprintf( thresh_label, sizeof(thresh_label), "Thres: %d + input", min_threshold ); namedWindow( standard_name, WINDOW_AUTOSIZE ); createTrackbar( thresh_label, standard_name, &s_trackbar, max_trackbar, Standard_Hough); diff --git a/samples/cpp/videocapture_starter.cpp b/samples/cpp/videocapture_starter.cpp index 58f1145ed5..8e53104331 100644 --- a/samples/cpp/videocapture_starter.cpp +++ b/samples/cpp/videocapture_starter.cpp @@ -57,7 +57,7 @@ namespace { case 27: //escape key return 0; case ' ': //Save an image - sprintf(filename,"filename%.3d.jpg",n++); + snprintf(filename,sizeof(filename),"filename%.3d.jpg",n++); imwrite(filename,frame); cout << "Saved " << filename << endl; break; diff --git a/samples/directx/d3d9_interop.cpp b/samples/directx/d3d9_interop.cpp index 4806a4078d..c46cf8e9e8 100644 --- a/samples/directx/d3d9_interop.cpp +++ b/samples/directx/d3d9_interop.cpp @@ -258,22 +258,22 @@ public: int y = 0; buf[0] = 0; - sprintf(buf, "mode: %s", m_modeStr[mode].c_str()); + snprintf(buf, sizeof(buf), "mode: %s", m_modeStr[mode].c_str()); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; buf[0] = 0; - sprintf(buf, m_demo_processing ? "blur frame" : "copy frame"); + snprintf(buf, sizeof(buf), m_demo_processing ? "blur frame" : "copy frame"); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; buf[0] = 0; - sprintf(buf, "time: %4.1f msec", time); + snprintf(buf, sizeof(buf), "time: %4.1f msec", time); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; buf[0] = 0; - sprintf(buf, "OpenCL device: %s", oclDevName.c_str()); + snprintf(buf, sizeof(buf), "OpenCL device: %s", oclDevName.c_str()); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); ::SelectObject(hDC, hOldFont); diff --git a/samples/directx/d3d9ex_interop.cpp b/samples/directx/d3d9ex_interop.cpp index 24258e3702..68b864f0eb 100644 --- a/samples/directx/d3d9ex_interop.cpp +++ b/samples/directx/d3d9ex_interop.cpp @@ -259,22 +259,22 @@ public: int y = 0; buf[0] = 0; - sprintf(buf, "mode: %s", m_modeStr[mode].c_str()); + snprintf(buf, sizeof(buf), "mode: %s", m_modeStr[mode].c_str()); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; buf[0] = 0; - sprintf(buf, m_demo_processing ? "blur frame" : "copy frame"); + snprintf(buf, sizeof(buf), m_demo_processing ? "blur frame" : "copy frame"); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; buf[0] = 0; - sprintf(buf, "time: %4.1f msec", time); + snprintf(buf, sizeof(buf), "time: %4.1f msec", time); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); y += tm.tmHeight; buf[0] = 0; - sprintf(buf, "OpenCL device: %s", oclDevName.c_str()); + snprintf(buf, sizeof(buf), "OpenCL device: %s", oclDevName.c_str()); ::TextOut(hDC, 0, y, buf, (int)strlen(buf)); ::SelectObject(hDC, hOldFont);