authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-02 18:22:08-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-02 18:22:08-04:00
logf87be94f6a4277823eeaab12cd581fd5cedff19b
treefcaa7a53653aa6b2c971c98290da7555113279a9
parentf69d28a0875effbfbd704f3ca7947c95eae05e2f

zig build: copy args for addCommand

avoids making it easy to accidentally use a dangling pointer

1 files changed, 5 insertions(+), 2 deletions(-)

std/build.zig+5-2
...@@ -178,6 +178,7 @@ pub const Builder = struct {...@@ -178,6 +178,7 @@ pub const Builder = struct {
178 return CLibExeObjStep.createObject(self, name, src);178 return CLibExeObjStep.createObject(self, name, src);
179 }179 }
180180
181 /// ::args are copied.
181 pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,182 pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
182 path: []const u8, args: []const []const u8) -> &CommandStep183 path: []const u8, args: []const []const u8) -> &CommandStep
183 {184 {
...@@ -1469,10 +1470,11 @@ pub const CommandStep = struct {...@@ -1469,10 +1470,11 @@ pub const CommandStep = struct {
1469 step: Step,1470 step: Step,
1470 builder: &Builder,1471 builder: &Builder,
1471 exe_path: []const u8,1472 exe_path: []const u8,
1472 args: []const []const u8,1473 args: [][]const u8,
1473 cwd: ?[]const u8,1474 cwd: ?[]const u8,
1474 env_map: &const BufMap,1475 env_map: &const BufMap,
14751476
1477 /// ::args are copied.
1476 pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap,1478 pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
1477 exe_path: []const u8, args: []const []const u8) -> &CommandStep1479 exe_path: []const u8, args: []const []const u8) -> &CommandStep
1478 {1480 {
...@@ -1481,10 +1483,11 @@ pub const CommandStep = struct {...@@ -1481,10 +1483,11 @@ pub const CommandStep = struct {
1481 .builder = builder,1483 .builder = builder,
1482 .step = Step.init(exe_path, builder.allocator, make),1484 .step = Step.init(exe_path, builder.allocator, make),
1483 .exe_path = exe_path,1485 .exe_path = exe_path,
1484 .args = args,1486 .args = %%builder.allocator.alloc([]u8, args.len),
1485 .cwd = cwd,1487 .cwd = cwd,
1486 .env_map = env_map,1488 .env_map = env_map,
1487 };1489 };
1490 mem.copy([]const u8, self.args, args);
1488 return self;1491 return self;
1489 }1492 }
14901493