Skip to content

Commit a40d308

Browse files
committed
samples(va): fix build warnings, use cv::format()
1 parent 3dd55d2 commit a40d308

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

samples/va_intel/display.cpp.inc

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <va/va.h>
1111
# include <va/va_drm.h>
1212

13+
#include "opencv2/core.hpp" // cv::format()
14+
1315
namespace va {
1416

1517
bool openDisplay();
@@ -70,10 +72,9 @@ static unsigned readId(const char* devName, const char* idName)
7072
{
7173
long int id = 0;
7274

73-
char fileName[256];
74-
snprintf(fileName, sizeof(fileName), "%s/%s/%s", VA_INTEL_PCI_DIR, devName, idName);
75+
std::string fileName = cv::format("%s/%s/%s", VA_INTEL_PCI_DIR, devName, idName);
7576

76-
FILE* file = fopen(fileName, "r");
77+
FILE* file = fopen(fileName.c_str(), "r");
7778
if (file)
7879
{
7980
char str[16] = "";
@@ -100,9 +101,8 @@ static int findAdapter(unsigned desiredVendorId)
100101
unsigned vendorId = readId(name, "vendor");
101102
if (vendorId == desiredVendorId)
102103
{
103-
char subdirName[256];
104-
snprintf(subdirName, sizeof(subdirName), "%s/%s/%s", VA_INTEL_PCI_DIR, name, "drm");
105-
Directory subdir(subdirName);
104+
std::string subdirName = cv::format("%s/%s/%s", VA_INTEL_PCI_DIR, name, "drm");
105+
Directory subdir(subdirName.c_str());
106106
for (int j = 0; j < subdir.count(); ++j)
107107
{
108108
if (!strncmp(subdir[j]->d_name, "card", 4))
@@ -130,29 +130,23 @@ public:
130130
numbers[1] = adapterIndex;
131131
for (int i = 0; i < NUM_NODES; ++i)
132132
{
133-
int sz = sizeof(VA_INTEL_DRI_DIR) + strlen(names[i]) + 3;
134-
paths[i] = new char [sz];
135-
snprintf(paths[i], sz, "%s%s%d", VA_INTEL_DRI_DIR, names[i], numbers[i]);
133+
paths[i] = cv::format("%s%s%d", VA_INTEL_DRI_DIR, names[i], numbers[i]);
136134
}
137135
}
138136
~NodeInfo()
139137
{
140-
for (int i = 0; i < NUM_NODES; ++i)
141-
{
142-
delete paths[i];
143-
paths[i] = 0;
144-
}
138+
// nothing
145139
}
146140
int count() const
147141
{
148142
return NUM_NODES;
149143
}
150144
const char* path(int index) const
151145
{
152-
return ((index >= 0) && (index < NUM_NODES)) ? paths[index] : 0;
146+
return ((index >= 0) && (index < NUM_NODES)) ? paths[index].c_str() : 0;
153147
}
154148
private:
155-
char* paths[NUM_NODES];
149+
std::string paths[NUM_NODES];
156150
};
157151

158152
static bool openDeviceIntel();

0 commit comments

Comments
 (0)