Skip to content
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

Make some string operations UTF-8 safe #3803

Merged
merged 2 commits into from
Oct 18, 2012
Merged
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
28 changes: 16 additions & 12 deletions src/libcore/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,14 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
}

fn read_all(rd: io::Reader) -> ~str {
let mut buf = ~"";
while !rd.eof() {
let bytes = rd.read_bytes(4096u);
buf += str::from_bytes(bytes);
}
move buf
let buf = io::with_bytes_writer(|wr| {
let mut bytes = [mut 0, ..4096];
while !rd.eof() {
let nread = rd.read(bytes, bytes.len());
wr.write(bytes.view(0, nread));
}
});
str::from_bytes(buf)
}

/**
Expand Down Expand Up @@ -341,13 +343,15 @@ fn writeclose(fd: c_int, s: ~str) {
fn readclose(fd: c_int) -> ~str {
let file = os::fdopen(fd);
let reader = io::FILE_reader(file, false);
let mut buf = ~"";
while !reader.eof() {
let bytes = reader.read_bytes(4096u);
buf += str::from_bytes(bytes);
}
let buf = io::with_bytes_writer(|writer| {
let mut bytes = [mut 0, ..4096];
while !reader.eof() {
let nread = reader.read(bytes, bytes.len());
writer.write(bytes.view(0, nread));
}
});
os::fclose(file);
move buf
str::from_bytes(buf)
}

/// Waits for a process to exit and returns the exit code
Expand Down
14 changes: 8 additions & 6 deletions src/rustdoc/markdown_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ fn readclose(fd: libc::c_int) -> ~str {
// Copied from run::program_output
let file = os::fdopen(fd);
let reader = io::FILE_reader(file, false);
let mut buf = ~"";
while !reader.eof() {
let bytes = reader.read_bytes(4096u);
buf += str::from_bytes(bytes);
}
let buf = io::with_bytes_writer(|writer| {
let mut bytes = [mut 0, ..4096];
while !reader.eof() {
let nread = reader.read(bytes, bytes.len());
writer.write(bytes.view(0, nread));
}
});
os::fclose(file);
return buf;
str::from_bytes(buf)
}

fn generic_writer(+process: fn~(markdown: ~str)) -> Writer {
Expand Down