浏览代码

[cmdline] Remove arbitrary limit on the length of image command lines

tags/v0.9.4
Michael Brown 16 年前
父节点
当前提交
4c85017968
共有 1 个文件被更改,包括 17 次插入8 次删除
  1. 17
    8
      src/hci/commands/image_cmd.c

+ 17
- 8
src/hci/commands/image_cmd.c 查看文件

@@ -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
 /**

正在加载...
取消
保存