From b107af3ada920f6902ee4cbed08858013ea60177 Mon Sep 17 00:00:00 2001 From: Joshua Landau Date: Thu, 11 Jun 2015 14:23:51 +0100 Subject: Comment for #26196. Fixes #26196. Alternatively we could explicitly check and complain (eg. panic), but I don't see the value-add. --- src/libstd/sys/windows/os.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libstd/sys') diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 5cfc2010424..522831a62b6 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -311,6 +311,7 @@ impl ExactSizeIterator for Args { impl Drop for Args { fn drop(&mut self) { + // NULL-safe unsafe { c::LocalFree(self.cur as *mut c_void); } } } @@ -321,6 +322,8 @@ pub fn args() -> Args { let lpCmdLine = c::GetCommandLineW(); let szArgList = c::CommandLineToArgvW(lpCmdLine, &mut nArgs); + // cur may be NULL if CommandLineToArgvW failed, + // in which case the range is empty to prevent reads Args { cur: szArgList, range: 0..(nArgs as isize) } } } -- cgit 1.4.1-3-g733a5 From 2148567821b0e3ff63e13b652b9b645263b70cb0 Mon Sep 17 00:00:00 2001 From: Joshua Landau Date: Thu, 11 Jun 2015 18:10:25 +0100 Subject: Changed patch wording --- src/libstd/sys/windows/os.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/libstd/sys') diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 522831a62b6..8a8cf9e7c53 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -311,7 +311,8 @@ impl ExactSizeIterator for Args { impl Drop for Args { fn drop(&mut self) { - // NULL-safe + // self.cur can be null if CommandLineToArgvW previously failed, + // but LocalFree ignores NULL pointers unsafe { c::LocalFree(self.cur as *mut c_void); } } } @@ -322,8 +323,9 @@ pub fn args() -> Args { let lpCmdLine = c::GetCommandLineW(); let szArgList = c::CommandLineToArgvW(lpCmdLine, &mut nArgs); - // cur may be NULL if CommandLineToArgvW failed, - // in which case the range is empty to prevent reads + // szArcList can be NULL if CommandLinToArgvW failed, + // but in that case nArgs is 0 so we won't actually + // try to read a null pointer Args { cur: szArgList, range: 0..(nArgs as isize) } } } -- cgit 1.4.1-3-g733a5