Skip to content

Commit 66f5d70

Browse files
kartbendkalowsk
authored andcommitted
shell: fix alignment issue
Casting a char* to a struct* requires checking alignment as this can fail on platforms requiring strict alignment (ex. Xtensa) Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
1 parent 9b4bebb commit 66f5d70

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/zephyr/shell/shell.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <zephyr/logging/log.h>
1818
#include <zephyr/sys/iterable_sections.h>
1919
#include <zephyr/sys/util.h>
20+
#include <zephyr/toolchain.h>
2021

2122
#if defined CONFIG_SHELL_GETOPT
2223
#include <getopt.h>
@@ -273,7 +274,8 @@ static inline bool shell_help_is_structured(const char *help)
273274
{
274275
const struct shell_cmd_help *structured = (const struct shell_cmd_help *)help;
275276

276-
return structured != NULL && structured->magic == SHELL_STRUCTURED_HELP_MAGIC;
277+
return structured != NULL && IS_PTR_ALIGNED(structured, struct shell_cmd_help) &&
278+
structured->magic == SHELL_STRUCTURED_HELP_MAGIC;
277279
}
278280

279281
#if defined(CONFIG_SHELL_HELP) || defined(__DOXYGEN__)

0 commit comments

Comments
 (0)