|
@@ -49,16 +49,25 @@ enum image_action {
|
49
|
49
|
*/
|
50
|
50
|
static int imgfill_cmdline ( struct image *image, unsigned int nargs,
|
51
|
51
|
char **args ) {
|
52
|
|
- char buf[256];
|
53
|
|
- size_t used = 0;
|
|
52
|
+ size_t len;
|
|
53
|
+ unsigned int i;
|
54
|
54
|
|
55
|
|
- memset ( buf, 0, sizeof ( buf ) );
|
56
|
|
- while ( ( used < sizeof ( buf ) ) && nargs-- ) {
|
57
|
|
- used += snprintf ( &buf[used], ( sizeof ( buf ) - used ),
|
58
|
|
- " %s", *(args++) );
|
59
|
|
- }
|
|
55
|
+ /* Determine total length of command line */
|
|
56
|
+ len = 1; /* NUL */
|
|
57
|
+ for ( i = 0 ; i < nargs ; i++ )
|
|
58
|
+ len += ( 1 /* space */ + strlen ( args[i] ) );
|
|
59
|
+
|
|
60
|
+ {
|
|
61
|
+ char buf[len];
|
|
62
|
+ char *ptr = buf;
|
60
|
63
|
|
61
|
|
- return image_set_cmdline ( image, &buf[1] );
|
|
64
|
+ /* Assemble command line */
|
|
65
|
+ for ( i = 0 ; i < nargs ; i++ )
|
|
66
|
+ ptr += sprintf ( ptr, " %s", args[i] );
|
|
67
|
+ assert ( ptr == ( buf + len - 1 ) );
|
|
68
|
+
|
|
69
|
+ return image_set_cmdline ( image, &buf[1] );
|
|
70
|
+ }
|
62
|
71
|
}
|
63
|
72
|
|
64
|
73
|
/**
|