This is an automated email from the ASF dual-hosted git repository.

kasjer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 1431593f7 shell: Fix LINK_TABLE start pointer alignment in shell 
module tables
1431593f7 is described below

commit 1431593f7a2c46c71edd9d3b4e4d11db7ee037bb
Author: Emma Stensland <[email protected]>
AuthorDate: Mon Jul 20 13:39:06 2026 -0600

    shell: Fix LINK_TABLE start pointer alignment in shell module tables
    
    In Mynewt, linker tables are used to group structs together.
    However, if the linker doesn't perfectly align the start of the
    section to the struct's size boundary, C pointer arithmetic
    miscalculates the array bounds. This manually aligns the pointer.
---
 sys/shell/src/shell.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/sys/shell/src/shell.c b/sys/shell/src/shell.c
index 476b58669..21db74baa 100644
--- a/sys/shell/src/shell.c
+++ b/sys/shell/src/shell.c
@@ -31,19 +31,30 @@
 
 #define SHELL_PROMPT "shell"
 
+static const struct shell_cmd *
+shell_mod_std_commands(const struct shell_mod_std *std_mod)
+{
+    uintptr_t addr = (uintptr_t)std_mod->commands;
+    uintptr_t aligned = (addr + sizeof(struct shell_cmd) - 1) &
+                        ~(uintptr_t)(sizeof(struct shell_cmd) - 1);
+
+    return (const struct shell_cmd *)aligned;
+}
+
 static size_t
 shell_mod_std_count(shell_mod_t mod)
 {
     const struct shell_mod_std *std_mod = (const struct shell_mod_std *)mod;
-    return std_mod->commands_end - std_mod->commands;
+    return std_mod->commands_end - shell_mod_std_commands(std_mod);
 }
 
 static shell_cmd_t
 shell_mod_std_get(shell_mod_t mod, size_t ix)
 {
     const struct shell_mod_std *std_mod = (const struct shell_mod_std *)mod;
-    size_t limit = std_mod->commands_end - std_mod->commands;
-    return ix < limit ? &std_mod->commands[ix] : NULL;
+    const struct shell_cmd *commands = shell_mod_std_commands(std_mod);
+    size_t limit = std_mod->commands_end - commands;
+    return ix < limit ? &commands[ix] : NULL;
 }
 
 const struct shell_mod_ops shell_mod_std_ops = {

Reply via email to