Skip to content

Commit 167d3f9

Browse files
author
Steven Cartmell
committed
HAL CRC: Return early when calling compute with null or 0 size buffer
1 parent df93c01 commit 167d3f9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

hal/crc_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void hal_crc_compute_partial_start(const uint32_t polynomial);
114114
* To obtain the final result of the CRC calculation hal_crc_get_result() is
115115
* called to apply the final transformations to the data.
116116
*
117+
* If the function is passed an undefined pointer, or the size of the buffer is
118+
* specified to be 0, this function will do nothing and return.
119+
*
117120
* This function can be call multiple times in succession, this can be used
118121
* to calculate the CRC result of streamed data.
119122
*

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/mbed_crc_api.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,21 @@ void hal_crc_compute_partial_start(const uint32_t polynomial)
7373
}
7474
default:
7575
MBED_ASSERT("Configuring Mbed CRC with unsupported polynomial");
76-
break;
76+
77+
return;
7778
}
7879

7980
CRC_Init(CRC0, &config);
8081
}
8182

8283
void hal_crc_compute_partial(const uint8_t *data, const size_t size)
8384
{
85+
if (data == NULL)
86+
return;
87+
88+
if (size == 0)
89+
return;
90+
8491
CRC_WriteData(CRC0, data, size);
8592
}
8693

0 commit comments

Comments
 (0)