HAL CRC: Return early when calling compute with null or 0 size buffer

pull/6708/head
Steven Cartmell 2018-04-30 11:21:45 +01:00
parent df93c0151c
commit 167d3f9a1e
2 changed files with 11 additions and 1 deletions

View File

@ -114,6 +114,9 @@ void hal_crc_compute_partial_start(const uint32_t polynomial);
* To obtain the final result of the CRC calculation hal_crc_get_result() is * To obtain the final result of the CRC calculation hal_crc_get_result() is
* called to apply the final transformations to the data. * called to apply the final transformations to the data.
* *
* If the function is passed an undefined pointer, or the size of the buffer is
* specified to be 0, this function will do nothing and return.
*
* This function can be call multiple times in succession, this can be used * This function can be call multiple times in succession, this can be used
* to calculate the CRC result of streamed data. * to calculate the CRC result of streamed data.
* *

View File

@ -73,7 +73,8 @@ void hal_crc_compute_partial_start(const uint32_t polynomial)
} }
default: default:
MBED_ASSERT("Configuring Mbed CRC with unsupported polynomial"); MBED_ASSERT("Configuring Mbed CRC with unsupported polynomial");
break;
return;
} }
CRC_Init(CRC0, &config); CRC_Init(CRC0, &config);
@ -81,6 +82,12 @@ void hal_crc_compute_partial_start(const uint32_t polynomial)
void hal_crc_compute_partial(const uint8_t *data, const size_t size) void hal_crc_compute_partial(const uint8_t *data, const size_t size)
{ {
if (data == NULL)
return;
if (size == 0)
return;
CRC_WriteData(CRC0, data, size); CRC_WriteData(CRC0, data, size);
} }