From 6bdc29395da567421a93a6d794eecec768a67502 Mon Sep 17 00:00:00 2001 From: Michael Kaplan Date: Fri, 24 Nov 2017 11:05:28 +0100 Subject: [PATCH] CpuUid: buffer size assertion added Added note in hal that a value higher than 0 is expected from the target implementation for the cpu_uid_get_length() function. Added MBED_ASSERT for checking cpu_uid_get_length() return value in the driver. --- drivers/CpuUid.cpp | 1 + hal/cpu_uid_api.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/CpuUid.cpp b/drivers/CpuUid.cpp index da5b9459f2..950afc80f9 100644 --- a/drivers/CpuUid.cpp +++ b/drivers/CpuUid.cpp @@ -26,6 +26,7 @@ const char CpuUid::_hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', CpuUid::CpuUid() : _data(NULL) { _size = cpu_uid_get_length(); + MBED_ASSERT(_size > 0); if (0 < _size) { _data = new uint8_t[_size]; diff --git a/hal/cpu_uid_api.h b/hal/cpu_uid_api.h index 1ff24ce17c..06d90573fd 100644 --- a/hal/cpu_uid_api.h +++ b/hal/cpu_uid_api.h @@ -37,7 +37,10 @@ extern "C" { * * @return Number of uid bytes * - * @note Shall be used to get the needed size of the byte buffer + * @note + * Shall be used by the driver to get the needed size of the byte buffer. + * Target implementation must return a value higher than 0 or the driver will assert. + * */ int cpu_uid_get_length(void);