From 66f5d701bd7058767bbcaf340f7b7c1caacca329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Wed, 11 Jun 2025 15:35:40 +0200 Subject: [PATCH] shell: fix alignment issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é --- include/zephyr/shell/shell.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/zephyr/shell/shell.h b/include/zephyr/shell/shell.h index 92c3091b6cd..71508f01406 100644 --- a/include/zephyr/shell/shell.h +++ b/include/zephyr/shell/shell.h @@ -17,6 +17,7 @@ #include #include #include +#include #if defined CONFIG_SHELL_GETOPT #include @@ -273,7 +274,8 @@ static inline bool shell_help_is_structured(const char *help) { const struct shell_cmd_help *structured = (const struct shell_cmd_help *)help; - return structured != NULL && structured->magic == SHELL_STRUCTURED_HELP_MAGIC; + return structured != NULL && IS_PTR_ALIGNED(structured, struct shell_cmd_help) && + structured->magic == SHELL_STRUCTURED_HELP_MAGIC; } #if defined(CONFIG_SHELL_HELP) || defined(__DOXYGEN__)