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 {
178178 return CLibExeObjStep.createObject(self, name, src);
179179 }
180180
181 /// ::args are copied.
181182 pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
182183 path: []const u8, args: []const []const u8) -> &CommandStep
183184 {
......@@ -1469,10 +1470,11 @@ pub const CommandStep = struct {
14691470 step: Step,
14701471 builder: &Builder,
14711472 exe_path: []const u8,
1472 args: []const []const u8,
1473 args: [][]const u8,
14731474 cwd: ?[]const u8,
14741475 env_map: &const BufMap,
14751476
1477 /// ::args are copied.
14761478 pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
14771479 exe_path: []const u8, args: []const []const u8) -> &CommandStep
14781480 {
......@@ -1481,10 +1483,11 @@ pub const CommandStep = struct {
14811483 .builder = builder,
14821484 .step = Step.init(exe_path, builder.allocator, make),
14831485 .exe_path = exe_path,
1484 .args = args,
1486 .args = %%builder.allocator.alloc([]u8, args.len),
14851487 .cwd = cwd,
14861488 .env_map = env_map,
14871489 };
1490 mem.copy([]const u8, self.args, args);
14881491 return self;
14891492 }
14901493