Skip to content

Commit 7142157

Browse files
committed
---
yaml --- r: 15425 b: refs/heads/try c: 10236f8 h: refs/heads/master i: 15423: 08de5e2 v: v3
1 parent b7fcd1b commit 7142157

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 59abf93b799a588e07060c7e4efd5f20cdce4293
5+
refs/heads/try: 10236f8cd48ad862c32573411acb4423e441f883
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/str.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,10 +1509,8 @@ let i = str::as_bytes(\"Hello World\") { |bytes| vec::len(bytes) };
15091509
~~~
15101510
"]
15111511
fn as_bytes<T>(s: str, f: fn([u8]) -> T) -> T unsafe {
1512-
let mut v: [u8] = ::unsafe::reinterpret_cast(s);
1513-
let r = f(v);
1514-
::unsafe::forget(v);
1515-
r
1512+
let v: *[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s));
1513+
f(*v)
15161514
}
15171515

15181516
#[doc = "
@@ -2449,6 +2447,14 @@ mod tests {
24492447
assert (c == "AAA");
24502448
}
24512449

2450+
#[test]
2451+
#[ignore(cfg(target_os = "win32"))]
2452+
#[should_fail]
2453+
fn test_as_bytes_fail() {
2454+
// Don't double free
2455+
as_bytes("") {|_bytes| fail }
2456+
}
2457+
24522458
#[test]
24532459
fn test_as_buf() unsafe {
24542460
let a = "Abcdefg";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// error-pattern:explicit failure
2+
// Don't double free the string
3+
use std;
4+
import io::{reader, reader_util};
5+
6+
fn main() {
7+
io::with_str_reader("") { |rdr|
8+
alt rdr.read_char() { '=' { } _ { fail } }
9+
}
10+
}

0 commit comments

Comments
 (0)