Skip to content

Commit

Permalink
ffspart, libflash: Fix stack size warnings
Browse files Browse the repository at this point in the history
libflash/file.c: In function 'file_erase':
    libflash/file.c:134:1: error: the frame size of 4128 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
     }
     ^

and

    ffspart.c: In function ‘main’:
    ffspart.c:529:1: error: the frame size of 4864 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
     }
     ^

In both cases, mark the local variables as static to avoid the stack.

The static approach is valid for file.c as the buffer is always filled
with `~0`. Given it's now going to be in .bss due to static we have to
still perform the memset(), but racing memset()s in this fashion won't
be harmful, just wasteful.

For ffspart.c's main(), there are bigger problems if that needs to be
re-entrant.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
amboar authored and stewartsmith committed Feb 22, 2019
1 parent 0dec1de commit 3852a94
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion external/ffspart/ffspart.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ static void print_help(const char *pname)

int main(int argc, char *argv[])
{
char *pnor = NULL, *input = NULL, line[MAX_LINE];
static char line[MAX_LINE];

char *pnor = NULL, *input = NULL;
bool toc_created = false, bad_input = false, allow_empty = false;
uint32_t block_size = 0, block_count = 0;
struct ffs_hdr *tocs[MAX_TOCS] = { 0 };
Expand Down
2 changes: 1 addition & 1 deletion libflash/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static int file_write(struct blocklevel_device *bl, uint64_t dst, const void *sr
*/
static int file_erase(struct blocklevel_device *bl, uint64_t dst, uint64_t len)
{
char buf[4096];
static char buf[4096];
int i = 0;
int rc;

Expand Down

0 comments on commit 3852a94

Please sign in to comment.