From e15ce241626caf4b06606b16706b1c7a78636303 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 18 Feb 2014 23:34:44 +1100 Subject: [PATCH] std::os: pass the correct buffer size to windows calls. Previously this was not passing the increased buffer size to the closure (which normally contains a windows API call), so something that was classed as too large for the buffer on the first call would be always classed as too large, and would cause the program to loop infinitely (or until OOM, since it was allocating double the memory at each step). --- src/libstd/os.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 719ed62d03d0a..7f0e5851a417f 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -112,7 +112,7 @@ 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 && @@ -1497,6 +1497,14 @@ mod tests { assert!(e.contains(&(n, ~"VALUE"))); } + #[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)); + } + #[test] fn test() { assert!((!Path::new("test-path").is_absolute()));