From a40d308d6aa8e1b9a64d8b210698928f00de5d0a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 19 Feb 2021 10:36:26 +0000 Subject: [PATCH] samples(va): fix build warnings, use cv::format() --- samples/va_intel/display.cpp.inc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/samples/va_intel/display.cpp.inc b/samples/va_intel/display.cpp.inc index ecfa0324a2..7570cfe653 100644 --- a/samples/va_intel/display.cpp.inc +++ b/samples/va_intel/display.cpp.inc @@ -10,6 +10,8 @@ #include # include +#include "opencv2/core.hpp" // cv::format() + namespace va { bool openDisplay(); @@ -70,10 +72,9 @@ static unsigned readId(const char* devName, const char* idName) { long int id = 0; - char fileName[256]; - snprintf(fileName, sizeof(fileName), "%s/%s/%s", VA_INTEL_PCI_DIR, devName, idName); + std::string fileName = cv::format("%s/%s/%s", VA_INTEL_PCI_DIR, devName, idName); - FILE* file = fopen(fileName, "r"); + FILE* file = fopen(fileName.c_str(), "r"); if (file) { char str[16] = ""; @@ -100,9 +101,8 @@ static int findAdapter(unsigned desiredVendorId) unsigned vendorId = readId(name, "vendor"); if (vendorId == desiredVendorId) { - char subdirName[256]; - snprintf(subdirName, sizeof(subdirName), "%s/%s/%s", VA_INTEL_PCI_DIR, name, "drm"); - Directory subdir(subdirName); + std::string subdirName = cv::format("%s/%s/%s", VA_INTEL_PCI_DIR, name, "drm"); + Directory subdir(subdirName.c_str()); for (int j = 0; j < subdir.count(); ++j) { if (!strncmp(subdir[j]->d_name, "card", 4)) @@ -130,18 +130,12 @@ public: numbers[1] = adapterIndex; for (int i = 0; i < NUM_NODES; ++i) { - int sz = sizeof(VA_INTEL_DRI_DIR) + strlen(names[i]) + 3; - paths[i] = new char [sz]; - snprintf(paths[i], sz, "%s%s%d", VA_INTEL_DRI_DIR, names[i], numbers[i]); + paths[i] = cv::format("%s%s%d", VA_INTEL_DRI_DIR, names[i], numbers[i]); } } ~NodeInfo() { - for (int i = 0; i < NUM_NODES; ++i) - { - delete paths[i]; - paths[i] = 0; - } + // nothing } int count() const { @@ -149,10 +143,10 @@ public: } const char* path(int index) const { - return ((index >= 0) && (index < NUM_NODES)) ? paths[index] : 0; + return ((index >= 0) && (index < NUM_NODES)) ? paths[index].c_str() : 0; } private: - char* paths[NUM_NODES]; + std::string paths[NUM_NODES]; }; static bool openDeviceIntel();