diff options
| author | bors <bors@rust-lang.org> | 2014-02-20 00:36:53 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-20 00:36:53 -0800 |
| commit | f76628d3904454241e41acb033f6ececfdd08b4c (patch) | |
| tree | 209bc56e103f1518329622b8390d17c84ed5f84e /src/libstd | |
| parent | b5e35736b0d62386081ccfb054fe44ae676a091b (diff) | |
| parent | 9347096d54a983d47996c5f8020dbec04fea81fa (diff) | |
| download | rust-f76628d3904454241e41acb033f6ececfdd08b4c.tar.gz rust-f76628d3904454241e41acb033f6ececfdd08b4c.zip | |
auto merge of #12396 : alexcrichton/rust/windows-env-var, r=huonw
On windows, the GetEnvironmentVariable function will return the necessary buffer size if the buffer provided was too small. This case previously fell through the checks inside of fill_utf16_buf_and_decode, tripping an assertion in the `slice` method. This adds an extra case for when the return value is >= the buffer size, in which case we assume the return value as the new buffer size and try again. Closes #12376
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/os.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 74e2fceb6ca..458e31fd86f 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -113,13 +113,15 @@ pub mod win32 { let mut done = false; while !done { let mut buf = vec::from_elem(n as uint, 0u16); - let k = f(buf.as_mut_ptr(), TMPBUF_SZ as DWORD); + let k = f(buf.as_mut_ptr(), n); if k == (0 as DWORD) { done = true; } else if k == n && libc::GetLastError() == libc::ERROR_INSUFFICIENT_BUFFER as DWORD { n *= (2 as DWORD); + } else if k >= n { + n = k; } else { done = true; } @@ -1495,6 +1497,16 @@ mod tests { } #[test] + fn test_env_set_get_huge() { + let n = make_rand_name(); + let s = "x".repeat(10000); + setenv(n, s); + assert_eq!(getenv(n), Some(s)); + unsetenv(n); + assert_eq!(getenv(n), None); + } + + #[test] fn test_env_setenv() { let n = make_rand_name(); |
