Skip to content

Commit 91af527

Browse files
nikomatsakisNick Desaulniers
authored and
Nick Desaulniers
committed
Fix windows build error. buf is borrowed by the call to
`as_mut_buf()` and so we must invoke `slice()` outside of that call.
1 parent 5d62a4a commit 91af527

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/libcore/os.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,24 @@ pub mod win32 {
108108
let mut res = None;
109109
let mut done = false;
110110
while !done {
111-
let mut buf = vec::from_elem(n as uint, 0u16);
111+
let mut k: DWORD = 0;
112+
let buf = vec::cast_to_mut(vec::from_elem(n as uint, 0u16));
112113
do vec::as_mut_buf(buf) |b, _sz| {
113-
let k : DWORD = f(b, TMPBUF_SZ as DWORD);
114+
k = f(b, TMPBUF_SZ as DWORD);
114115
if k == (0 as DWORD) {
115116
done = true;
116117
} else if (k == n &&
117118
libc::GetLastError() ==
118119
libc::ERROR_INSUFFICIENT_BUFFER as DWORD) {
119120
n *= (2 as DWORD);
120121
} else {
121-
let sub = vec::slice(buf, 0u, k as uint);
122-
res = option::Some(str::from_utf16(sub));
123122
done = true;
124123
}
125124
}
125+
if k != 0 && done {
126+
let sub = vec::slice(buf, 0u, k as uint);
127+
res = option::Some(str::from_utf16(sub));
128+
}
126129
}
127130
return res;
128131
}

0 commit comments

Comments
 (0)