std::array
or std::vector
CXX-W206643 std::vector<double> m_vRoverXPosition;
44 std::vector<double> m_vRoverYPosition;
45 time_t m_tStuckCheckTime;
46 double m_dStuckCheckLastPosition[2];47 bool m_bInitialized;
48 std::vector<TagDetector*> m_vTagDetectors;
49 statemachine::TimeIntervalBasedStuckDetector m_StuckDetector;
65 std::tm* tLocalTime = std::localtime(&tCurrentTime);
66
67 // Format the current time in a format that can be used as a file name
68 char cCurrentTime[80]; 69 size_t siTimeCharacters;
70 siTimeCharacters = std::strftime(cCurrentTime, sizeof(cCurrentTime), "%Y%m%d-%H%M%S", tLocalTime);
71 if (siTimeCharacters == 0)
Arrays declared using C-style syntax can lead to problems such as buffer overflows, memory leaks, and undefined behavior. Using std::array
or std::vector
provides better memory management and avoids these issues.
To fix this issue, replace the C-style array declaration with std::array
or std::vector
, depending on the requirements of the code.
Additionally, using std::array
or std::vector
provides a more consistent and idiomatic C++ code style, making the code easier to read and maintain.
void foo() {
int arr[5] = {1, 2, 3, 4, 5};
// ...
}
#include <array>
void foo() {
std::array<int, 5> arr = {1, 2, 3, 4, 5};
// ...
}
or
#include <vector>
void foo() {
std::vector<int> arr = {1, 2, 3, 4, 5};
// ...
}
For more information, refer to this link.