mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
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 <matteo.golin@gmail.com> FIx
This commit is contained in:
parent
241096a87b
commit
6d8708184e
1 changed files with 6 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue