Skip to content

std: Don't parse argv as a String #20100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/libstd/rt/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() }
target_os = "freebsd",
target_os = "dragonfly"))]
mod imp {
use core::prelude::*;
use prelude::*;

use boxed::Box;
use vec::Vec;
use string::String;
use mem;
use slice;

use sync::{StaticMutex, MUTEX_INIT};

Expand Down Expand Up @@ -98,7 +96,12 @@ mod imp {

unsafe fn load_argc_and_argv(argc: int, argv: *const *const u8) -> Vec<Vec<u8>> {
Vec::from_fn(argc as uint, |i| {
String::from_raw_buf(*argv.offset(i as int)).into_bytes()
let arg = *argv.offset(i as int);
let mut len = 0u;
while *arg.offset(len as int) != 0 {
len += 1u;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this use CString, instead of duplicating that logic?

slice::from_raw_buf(&arg, len).to_vec()
})
}

Expand Down
19 changes: 19 additions & 0 deletions src/test/run-pass/issue-20091.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::io::Command;
use std::os;

fn main() {
if os::args().len() == 1 {
assert!(Command::new(os::self_exe_name().unwrap()).arg(b"\xff")
.status().unwrap().success())
}
}