bindesc: Add maximum data size and assertion
Add a Kconfig symbol to limit the maximum size of a descriptor's data, enforced by a build assertion. Signed-off-by: Yonatan Schachter <yonatan.schachter@gmail.com>
This commit is contained in:
parent
5da7ba55aa
commit
fd68fc486c
2 changed files with 28 additions and 12 deletions
|
|
@ -176,7 +176,10 @@ extern "C" {
|
|||
.tag = BINDESC_TAG(STR, id), \
|
||||
.len = (uint16_t)sizeof(value), \
|
||||
.data = value, \
|
||||
}
|
||||
}; \
|
||||
BUILD_ASSERT(sizeof(value) <= CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE, \
|
||||
"Bindesc " STRINGIFY(name) " exceeded maximum size, consider reducing the" \
|
||||
" size or changing CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE. ")
|
||||
|
||||
/**
|
||||
* @brief Define a binary descriptor of type uint.
|
||||
|
|
@ -222,7 +225,11 @@ extern "C" {
|
|||
.tag = BINDESC_TAG(BYTES, id), \
|
||||
.len = (uint16_t)sizeof((uint8_t [])__DEBRACKET value), \
|
||||
.data = __DEBRACKET value, \
|
||||
}
|
||||
}; \
|
||||
BUILD_ASSERT(sizeof((uint8_t [])__DEBRACKET value) <= \
|
||||
CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE, \
|
||||
"Bindesc " STRINGIFY(name) " exceeded maximum size, consider reducing the" \
|
||||
" size or changing CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE. ")
|
||||
|
||||
/**
|
||||
* @brief Get the value of a string binary descriptor
|
||||
|
|
|
|||
|
|
@ -20,6 +20,15 @@ source "subsys/bindesc/Kconfig.version"
|
|||
source "subsys/bindesc/Kconfig.build_time"
|
||||
source "subsys/bindesc/Kconfig.host_info"
|
||||
|
||||
config BINDESC_DEFINE_MAX_DATA_SIZE
|
||||
int "Bindesc max data size"
|
||||
range 4 $(UINT16_MAX)
|
||||
default 128
|
||||
help
|
||||
Determines the maximum size of a binary descriptor's data. The theoretical
|
||||
limit to this value is the maximum value of a uint16_t (65535), in practice
|
||||
it's recommened to keep this value much smaller for easier handling of the data.
|
||||
|
||||
endif # BINDESC_DEFINE
|
||||
|
||||
endif # BINDESC
|
||||
|
|
|
|||
Loading…
Reference in a new issue