From 4c8501796877e66b0487d776431c92ee8141f6b6 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 12 Jun 2008 02:12:10 +0100 Subject: [PATCH] [cmdline] Remove arbitrary limit on the length of image command lines --- src/hci/commands/image_cmd.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/hci/commands/image_cmd.c b/src/hci/commands/image_cmd.c index 44689dd2..23843a7e 100644 --- a/src/hci/commands/image_cmd.c +++ b/src/hci/commands/image_cmd.c @@ -49,16 +49,25 @@ enum image_action { */ static int imgfill_cmdline ( struct image *image, unsigned int nargs, char **args ) { - char buf[256]; - size_t used = 0; + size_t len; + unsigned int i; - memset ( buf, 0, sizeof ( buf ) ); - while ( ( used < sizeof ( buf ) ) && nargs-- ) { - used += snprintf ( &buf[used], ( sizeof ( buf ) - used ), - " %s", *(args++) ); + /* Determine total length of command line */ + len = 1; /* NUL */ + for ( i = 0 ; i < nargs ; i++ ) + len += ( 1 /* space */ + strlen ( args[i] ) ); + + { + char buf[len]; + char *ptr = buf; + + /* Assemble command line */ + for ( i = 0 ; i < nargs ; i++ ) + ptr += sprintf ( ptr, " %s", args[i] ); + assert ( ptr == ( buf + len - 1 ) ); + + return image_set_cmdline ( image, &buf[1] ); } - - return image_set_cmdline ( image, &buf[1] ); } /**