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

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 6d8708184ee9926d6e3ff58987c8ad4aaf7130cf
Author: Matteo Golin <[email protected]>
AuthorDate: Wed May 27 19:52:02 2026 -0400

    apps/nxinit: Fix service length error
    
    Would not compile due to typo in macro describing service name length.
    
    Change ensures that:
    * We do not malloc an extra `len` bytes since this is already allocated
      as part of the struct
    * The name string always has a null terminating byte
    
    Signed-off-by: Matteo Golin <[email protected]>
    
    FIx
---
 system/nxinit/service.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/system/nxinit/service.c b/system/nxinit/service.c
index 847b1a31d..7f582e6e4 100644
--- a/system/nxinit/service.c
+++ b/system/nxinit/service.c
@@ -206,9 +206,12 @@ static int option_class(FAR struct service_manager_s *sm,
 {
   FAR struct service_s *s = list_last_entry(&sm->services, struct service_s,
                                             node);
-  size_t len = strlen(argv[1]) + 1;
+  size_t len;
   FAR struct service_class_s *c;
 
+  len = strlen(argv[1]) + 1;
+  len = (len >= NXINIT_SERVICE_NAME_MAX) ? NXINIT_SERVICE_NAME_MAX : len;
+
   list_for_every_entry(&s->classes, c, struct service_class_s, node)
     {
       if (!strcmp(c->name, argv[1]))
@@ -217,15 +220,15 @@ static int option_class(FAR struct service_manager_s *sm,
         }
     }
 
-  c = malloc(sizeof(*c) + len);
+  c = malloc(sizeof(*c));
   if (c == NULL)
     {
       init_err("Alloc class");
       return -errno;
     }
 
-  len = (len >= MAX_NXINIT_SERVICE_NAME) ? MAX_NXINIT_SERVICE_NAME : len;
   memcpy(c->name, argv[1], len);
+  c->name[len] = '\0'; /* Always ensure null termination */
   list_add_tail(&s->classes, &c->node);
   return 0;
 }

Reply via email to