Closed
Description
The following code results in corrupt output: (Ubuntu 12.04 LTS, rust master pulled 25th Feb)
let arr : ~[&str] = std::os::args()[1].split_str("::").collect();
std::io::println("first " + arr[0]);
std::io::println("first again " + arr[0]);
$ rustc isolate_issue.rs
$ ./isolate_issue "foo::bar"
first fir
first again
Ashish Myles noted that an earlier version of rust failed to compile this code, giving an error about the reference to the return value of std::os::args() not being valid for the duration of its use.
https://mail.mozilla.org/pipermail/rust-dev/2014-February/008796.html
Pulling 'args' into a separate local variable works:
let args = std::os::args();
let arr : ~[&str] = args[1].split_str("::").collect();
std::io::println("first " + arr[0]);
std::io::println("first again " + arr[0]);
$ ./isolate_issue "foo::bar"
first foo
first again foo
Metadata
Metadata
Assignees
Labels
No labels