From 76a14f2ff428be46a3b600ab151f994492731d6e Mon Sep 17 00:00:00 2001 From: Kyle Kearney Date: Wed, 15 Apr 2020 11:13:43 -0700 Subject: [PATCH] Cypress: Fix unitialized memory in spi_master_write 'received' was declared as an int but populated by cyhal_spi_transfer after being cast to to (uint8_t *), which left the upper 3 bytes uninitialized. Instead, declare as uint8_t and let the compiler upcast the value when it is returned. --- targets/TARGET_Cypress/TARGET_PSOC6/cy_spi_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/cy_spi_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/cy_spi_api.c index f6bff0799a..6780ecff39 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/cy_spi_api.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/cy_spi_api.c @@ -140,9 +140,9 @@ void spi_frequency(spi_t *obj, int hz) int spi_master_write(spi_t *obj, int value) { struct spi_s *spi = cy_get_spi(obj); - int received; + uint8_t received; - if (CY_RSLT_SUCCESS != cyhal_spi_transfer(&(spi->hal_spi), (const uint8_t *)&value, 1, (uint8_t *)&received, 1, 0xff)) { + if (CY_RSLT_SUCCESS != cyhal_spi_transfer(&(spi->hal_spi), (const uint8_t *)&value, 1, &received, 1, 0xff)) { MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_transfer"); } return received;