Skip to content

Commit 76a14f2

Browse files
author
Kyle Kearney
committed
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.
1 parent 7b0c38a commit 76a14f2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/cy_spi_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ void spi_frequency(spi_t *obj, int hz)
140140
int spi_master_write(spi_t *obj, int value)
141141
{
142142
struct spi_s *spi = cy_get_spi(obj);
143-
int received;
143+
uint8_t received;
144144

145-
if (CY_RSLT_SUCCESS != cyhal_spi_transfer(&(spi->hal_spi), (const uint8_t *)&value, 1, (uint8_t *)&received, 1, 0xff)) {
145+
if (CY_RSLT_SUCCESS != cyhal_spi_transfer(&(spi->hal_spi), (const uint8_t *)&value, 1, &received, 1, 0xff)) {
146146
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_transfer");
147147
}
148148
return received;

0 commit comments

Comments
 (0)