Skip to content

Commit a666105

Browse files
committed
std: Don't parse argv as a String
Instead, just pass everything through as a Vec<u8> to get worried about later. Closes #20091
1 parent c141f22 commit a666105

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/libstd/rt/args.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() }
4444
target_os = "freebsd",
4545
target_os = "dragonfly"))]
4646
mod imp {
47-
use core::prelude::*;
47+
use prelude::*;
4848

49-
use boxed::Box;
50-
use vec::Vec;
51-
use string::String;
5249
use mem;
50+
use slice;
5351

5452
use sync::{StaticMutex, MUTEX_INIT};
5553

@@ -98,7 +96,12 @@ mod imp {
9896

9997
unsafe fn load_argc_and_argv(argc: int, argv: *const *const u8) -> Vec<Vec<u8>> {
10098
Vec::from_fn(argc as uint, |i| {
101-
String::from_raw_buf(*argv.offset(i as int)).into_bytes()
99+
let arg = *argv.offset(i as int);
100+
let mut len = 0u;
101+
while *arg.offset(len as int) != 0 {
102+
len += 1u;
103+
}
104+
slice::from_raw_buf(&arg, len).to_vec()
102105
})
103106
}
104107

src/test/run-pass/issue-20091.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::io::Command;
12+
use std::os;
13+
14+
fn main() {
15+
if os::args().len() == 1 {
16+
assert!(Command::new(os::self_exe_name().unwrap()).arg(b"\xff")
17+
.status().unwrap().success())
18+
}
19+
}

0 commit comments

Comments
 (0)