Skip to content

Commit

Permalink
Use lib_get_tempbuffer Saving stack
Browse files Browse the repository at this point in the history
Signed-off-by: zhangshoukui <[email protected]>
  • Loading branch information
Zhangshoukui committed Jan 16, 2025
1 parent 14fa7d2 commit 4c2e0cb
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions nshlib/nsh_mmcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <nuttx/config.h>

#include <stdio.h>
#include <string.h>

#include "nsh.h"
Expand Down Expand Up @@ -58,18 +59,29 @@ int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)

int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
char arg[LINE_MAX] = "";
FAR char *arg;
int ret;
int i;

arg = lib_get_tempbuffer(LINE_MAX);
if (arg == NULL)
{
return -ENOMEM;
}

arg[0] = '\0';

if (argc == 1)
{
strlcpy(arg, "used", LINE_MAX);
}
else if (argc >= 2 && (strcmp(argv[1], "-h") == 0 ||
strcmp(argv[1], "help") == 0))
{
return nsh_catfile(vtbl, argv[0],
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
ret = nsh_catfile(vtbl, argv[0],
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
lib_put_tempbuffer(arg);
return ret;
}
else
{
Expand All @@ -83,8 +95,10 @@ int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
}
}

return nsh_writefile(vtbl, argv[0], arg, strlen(arg),
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
ret = nsh_writefile(vtbl, argv[0], arg, strlen(arg),
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
lib_put_tempbuffer(arg);
return ret;
}

#endif /* !CONFIG_NSH_DISABLE_MEMDUMP && NSH_HAVE_WRITEFILE */

0 comments on commit 4c2e0cb

Please sign in to comment.