In this example in the following function the SonarQube requests to apply rule “Pointer and reference parameters should be “const” if the corresponding object is not modified”
We believed that this is not good because the pointed buffer is changed inside the nrfx_spim_xfer().
Other problem is that if we make is const just to make SQ happy, the cmok doesn’t generate the appropriate mocking functions for reading values through pointer because it expects(correctly) the value pointed never changes (TDD testing)
/**
* @brief Transfer up to 255 bytes through SPI
*
* @param[in] device The device with which communication is performed
* @param[in] nb_bytes The number of bytes to transfer
* @param[inout] tx_buffer The buffer containing the bytes to write
* @param[inout] rx_buffer The buffer containing the bytes to read
*/
static void spi_nrf_transfer(const spi_device_cfg_t* const device,
uint8_t nb_bytes,
const uint8_t* const tx_buffer,
uint8_t* const rx_buffer)
// Mark "rx_buffer" as const at every possible pointer level.
{
nrfx_spim_xfer_desc_t nrfx_xfer_desc = {.p_rx_buffer = (uint8_t*)rx_buffer,
.rx_length = nb_bytes,
.p_tx_buffer = tx_buffer,
.tx_length = nb_bytes};
nrfx_spim_xfer(&spi_nrf_nrfx_spim_instances[device->spi_driver->module], &nrfx_xfer_desc, 0);
}
Do you have a way to improve this rule to avoid a code smell in this specific case ?
Best regards,
Jean-Christophe Coulet