|  | @@ -39,37 +39,24 @@ FILE_LICENCE ( GPL2_OR_LATER );
 | 
		
	
		
			
			| 39 | 39 |   * Fill in image command line
 | 
		
	
		
			
			| 40 | 40 |   *
 | 
		
	
		
			
			| 41 | 41 |   * @v image		Image
 | 
		
	
		
			
			| 42 |  | - * @v nargs		Argument count
 | 
		
	
		
			
			| 43 | 42 |   * @v args		Argument list
 | 
		
	
		
			
			| 44 | 43 |   * @ret rc		Return status code
 | 
		
	
		
			
			| 45 | 44 |   */
 | 
		
	
		
			
			| 46 |  | -static int imgfill_cmdline ( struct image *image, unsigned int nargs, 
 | 
		
	
		
			
			| 47 |  | -			     char **args ) {
 | 
		
	
		
			
			| 48 |  | -	size_t len = 0;
 | 
		
	
		
			
			| 49 |  | -	unsigned int i;
 | 
		
	
		
			
			| 50 |  | -
 | 
		
	
		
			
			| 51 |  | -	/* Clear command line if no arguments given */
 | 
		
	
		
			
			| 52 |  | -	if ( ! nargs )
 | 
		
	
		
			
			| 53 |  | -		return image_set_cmdline ( image, NULL );
 | 
		
	
		
			
			| 54 |  | -
 | 
		
	
		
			
			| 55 |  | -	/* Determine total length of command line */
 | 
		
	
		
			
			| 56 |  | -	for ( i = 0 ; i < nargs ; i++ )
 | 
		
	
		
			
			| 57 |  | -		len += ( strlen ( args[i] ) + 1 /* space or NUL */ );
 | 
		
	
		
			
			| 58 |  | -
 | 
		
	
		
			
			| 59 |  | -	{
 | 
		
	
		
			
			| 60 |  | -		char buf[len];
 | 
		
	
		
			
			| 61 |  | -		char *ptr = buf;
 | 
		
	
		
			
			| 62 |  | -
 | 
		
	
		
			
			| 63 |  | -		/* Assemble command line */
 | 
		
	
		
			
			| 64 |  | -		buf[0] = '\0';
 | 
		
	
		
			
			| 65 |  | -		for ( i = 0 ; i < nargs ; i++ ) {
 | 
		
	
		
			
			| 66 |  | -			ptr += sprintf ( ptr, "%s%s", ( i ? " " : "" ),
 | 
		
	
		
			
			| 67 |  | -					 args[i] );
 | 
		
	
		
			
			| 68 |  | -		}
 | 
		
	
		
			
			| 69 |  | -		assert ( ptr < ( buf + len ) );
 | 
		
	
		
			
			|  | 45 | +static int imgfill_cmdline ( struct image *image, char **args ) {
 | 
		
	
		
			
			|  | 46 | +	char *cmdline = NULL;
 | 
		
	
		
			
			|  | 47 | +	int rc;
 | 
		
	
		
			
			| 70 | 48 |  
 | 
		
	
		
			
			| 71 |  | -		return image_set_cmdline ( image, buf );
 | 
		
	
		
			
			|  | 49 | +	/* Construct command line (if arguments are present) */
 | 
		
	
		
			
			|  | 50 | +	if ( *args ) {
 | 
		
	
		
			
			|  | 51 | +		cmdline = concat_args ( args );
 | 
		
	
		
			
			|  | 52 | +		if ( ! cmdline )
 | 
		
	
		
			
			|  | 53 | +			return -ENOMEM;
 | 
		
	
		
			
			| 72 | 54 |  	}
 | 
		
	
		
			
			|  | 55 | +
 | 
		
	
		
			
			|  | 56 | +	/* Apply command line */
 | 
		
	
		
			
			|  | 57 | +	rc = image_set_cmdline ( image, cmdline );
 | 
		
	
		
			
			|  | 58 | +	free ( cmdline );
 | 
		
	
		
			
			|  | 59 | +	return rc;
 | 
		
	
		
			
			| 73 | 60 |  }
 | 
		
	
		
			
			| 74 | 61 |  
 | 
		
	
		
			
			| 75 | 62 |  /** "imgfetch" options */
 | 
		
	
	
		
			
			|  | @@ -127,8 +114,7 @@ static int imgfetch_core_exec ( int argc, char **argv,
 | 
		
	
		
			
			| 127 | 114 |  		return rc;
 | 
		
	
		
			
			| 128 | 115 |  
 | 
		
	
		
			
			| 129 | 116 |  	/* Fill in command line */
 | 
		
	
		
			
			| 130 |  | -	if ( ( rc = imgfill_cmdline ( image, ( argc - optind - 1 ),
 | 
		
	
		
			
			| 131 |  | -				      &argv[ optind + 1 ] ) ) != 0 )
 | 
		
	
		
			
			|  | 117 | +	if ( ( rc = imgfill_cmdline ( image, &argv[ optind + 1 ] ) ) != 0 )
 | 
		
	
		
			
			| 132 | 118 |  		return rc;
 | 
		
	
		
			
			| 133 | 119 |  
 | 
		
	
		
			
			| 134 | 120 |  	/* Fetch the image */
 | 
		
	
	
		
			
			|  | @@ -255,8 +241,7 @@ static int imgargs_exec ( int argc, char **argv ) {
 | 
		
	
		
			
			| 255 | 241 |  		return rc;
 | 
		
	
		
			
			| 256 | 242 |  
 | 
		
	
		
			
			| 257 | 243 |  	/* Fill in command line */
 | 
		
	
		
			
			| 258 |  | -	if ( ( rc = imgfill_cmdline ( image, ( argc - optind - 1 ),
 | 
		
	
		
			
			| 259 |  | -				      &argv[ optind + 1 ] ) ) != 0 )
 | 
		
	
		
			
			|  | 244 | +	if ( ( rc = imgfill_cmdline ( image, &argv[ optind + 1 ] ) ) != 0 )
 | 
		
	
		
			
			| 260 | 245 |  		return rc;
 | 
		
	
		
			
			| 261 | 246 |  
 | 
		
	
		
			
			| 262 | 247 |  	return 0;
 |