[sim] Fix stringop truncation warning from GCC 10 (#2945)

If the strncpy() bound is equal to the destination size and the source
string is longer than 256 bytes, strncpy() won't write a null terminator
for the destination string.
This commit is contained in:
Tyler Veness
2020-12-17 21:51:57 -08:00
committed by GitHub
parent 1051a06a76
commit 20fbb5c63b

View File

@@ -557,7 +557,8 @@ void GlfwSystemJoystick::GetData(HALJoystickData* data, bool mapGamepad) const {
// copy into HAL structures
data->desc.isXbox = m_isGamepad ? 1 : 0;
data->desc.type = m_isGamepad ? 21 : 20;
std::strncpy(data->desc.name, m_name, 256);
std::strncpy(data->desc.name, m_name, sizeof(data->desc.name) - 1);
data->desc.name[sizeof(data->desc.name) - 1] = '\0';
data->desc.axisCount = (std::min)(m_axisCount, HAL_kMaxJoystickAxes);
// desc.axisTypes ???
data->desc.buttonCount = (std::min)(m_buttonCount, 32);