diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-04-21 18:12:59 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-04-21 18:12:59 -0600 |
commit | 47159ade11ffc2349f7d695b0d7838ab9d5fa7cf (patch) | |
tree | 40207f90b53572da4ccffd52e181cd3f8f19d836 /apps/nshlib | |
parent | adef15b74515b624c5584458dcfaea6b7619ad2f (diff) | |
download | px4-nuttx-47159ade11ffc2349f7d695b0d7838ab9d5fa7cf.tar.gz px4-nuttx-47159ade11ffc2349f7d695b0d7838ab9d5fa7cf.tar.bz2 px4-nuttx-47159ade11ffc2349f7d695b0d7838ab9d5fa7cf.zip |
NSH library: malloc/free IOBUFFER instead of using stack
Diffstat (limited to 'apps/nshlib')
-rw-r--r-- | apps/nshlib/nsh_dbgcmds.c | 10 | ||||
-rw-r--r-- | apps/nshlib/nsh_fscmds.c | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/apps/nshlib/nsh_dbgcmds.c b/apps/nshlib/nsh_dbgcmds.c index 15ce9498b..9f7ec205e 100644 --- a/apps/nshlib/nsh_dbgcmds.c +++ b/apps/nshlib/nsh_dbgcmds.c @@ -373,7 +373,7 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #ifndef CONFIG_NSH_DISABLE_HEXDUMP int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { - uint8_t buffer[IOBUFFERSIZE]; + FAR uint8_t *buffer; char msg[32]; off_t position; int fd; @@ -394,6 +394,13 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return ERROR; } + buffer = (FAR uint8_t *)malloc(IOBUFFERSIZE); + if(buffer == NULL) + { + nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "malloc", NSH_ERRNO); + return ERROR; + } + #ifdef CONFIG_NSH_CMDOPT_HEXDUMP for (x = 2; x < argc; x++) { @@ -489,6 +496,7 @@ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } (void)close(fd); + free(buffer); return ret; } #endif diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index 860e0b814..14e174243 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -416,7 +416,7 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, FAR const char *filename) { - char buffer[IOBUFFERSIZE]; + FAR char *buffer; int fd; int ret = OK; @@ -429,6 +429,13 @@ static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, return ERROR; } + buffer = (FAR char *)malloc(IOBUFFERSIZE); + if(buffer == NULL) + { + nsh_output(vtbl, g_fmtcmdfailed, cmd, "malloc", NSH_ERRNO); + return ERROR; + } + /* And just dump it byte for byte into stdout */ for (;;) @@ -514,6 +521,7 @@ static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, /* Close the input file and return the result */ (void)close(fd); + free(buffer); return ret; } #endif |