Skip to content

Commit 2993e79

Browse files
committed
ipa: rpi: imx500: Fix stringop-truncation warning
This warning is issued by the compiler because the strncpy copies across the whole string array, leaving no place for the nul terminator. Fix it by copying sizeof(str) - 1 elements. Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
1 parent 983ffa7 commit 2993e79

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ipa/rpi/cam_helper/cam_helper_imx500.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void CamHelperImx500::parseInferenceData(libcamera::Span<const uint8_t> buffer,
246246
exported.height = inputTensorInfo.height;
247247
exported.numChannels = inputTensorInfo.channels;
248248
strncpy(exported.networkName, inputTensorInfo.networkName.c_str(),
249-
sizeof(exported.networkName));
249+
sizeof(exported.networkName) - 1);
250250
exported.networkName[sizeof(exported.networkName) - 1] = '\0';
251251
metadata.set("cnn.input_tensor_info", exported);
252252
metadata.set("cnn.input_tensor", std::move(inputTensorInfo.data));
@@ -279,7 +279,7 @@ void CamHelperImx500::parseInferenceData(libcamera::Span<const uint8_t> buffer,
279279
<< "IMX500 output tensor info export failed, numTensors > MaxNumTensors";
280280
}
281281
strncpy(exported.networkName, outputTensorInfo.networkName.c_str(),
282-
sizeof(exported.networkName));
282+
sizeof(exported.networkName) - 1);
283283
exported.networkName[sizeof(exported.networkName) - 1] = '\0';
284284
metadata.set("cnn.output_tensor_info", exported);
285285
metadata.set("cnn.output_tensor", std::move(outputTensorInfo.data));

0 commit comments

Comments
 (0)