Remove empty try's (#13493)
authorDan Moseley <danmose@microsoft.com>
Tue, 22 Aug 2017 05:25:35 +0000 (22:25 -0700)
committerGitHub <noreply@github.com>
Tue, 22 Aug 2017 05:25:35 +0000 (22:25 -0700)
* Remove empty try's

* Remove some dead comments

* more

12 files changed:
src/mscorlib/shared/System/DateTime.cs
src/mscorlib/shared/System/DateTimeOffset.cs
src/mscorlib/shared/System/IO/FileStream.Windows.cs
src/mscorlib/src/Microsoft/Win32/RegistryKey.cs
src/mscorlib/src/System/Diagnostics/Stacktrace.cs
src/mscorlib/src/System/Environment.cs
src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs
src/mscorlib/src/System/Runtime/InteropServices/CriticalHandle.cs
src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs
src/mscorlib/src/System/Runtime/MemoryFailPoint.cs
src/mscorlib/src/System/Runtime/Reliability/CriticalFinalizerObject.cs
src/mscorlib/src/System/Threading/ThreadPool.cs

index 6467ffa..e72654a 100644 (file)
@@ -1025,11 +1025,7 @@ namespace System
         }
 
         // Returns a DateTime representing the current date and time. The
-        // resolution of the returned value depends on the system timer. For
-        // Windows NT 3.5 and later the timer resolution is approximately 10ms,
-        // for Windows NT 3.1 it is approximately 16ms, and for Windows 95 and 98
-        // it is approximately 55ms.
-        //
+        // resolution of the returned value depends on the system timer.
         public static DateTime Now
         {
             get
index ab35bdb..e3366e2 100644 (file)
@@ -129,11 +129,7 @@ namespace System
         }
 
         // Returns a DateTimeOffset representing the current date and time. The
-        // resolution of the returned value depends on the system timer. For
-        // Windows NT 3.5 and later the timer resolution is approximately 10ms,
-        // for Windows NT 3.1 it is approximately 16ms, and for Windows 95 and 98
-        // it is approximately 55ms.
-        //
+        // resolution of the returned value depends on the system timer.
         public static DateTimeOffset Now
         {
             get
index 9c88502..9159b03 100644 (file)
@@ -742,9 +742,8 @@ namespace System.IO
                 else
                 {
                     // ERROR_INVALID_PARAMETER may be returned for writes
-                    // where the position is too large (i.e. writing at Int64.MaxValue 
-                    // on Win9x) OR for synchronous writes to a handle opened 
-                    // asynchronously.
+                    // where the position is too large or for synchronous writes 
+                    // to a handle opened asynchronously.
                     if (errorCode == ERROR_INVALID_PARAMETER)
                         throw new IOException(SR.IO_FileTooLongOrHandleNotSync);
                     throw Win32Marshal.GetExceptionForWin32Error(errorCode);
index 2228c1f..bef0c38 100644 (file)
@@ -458,9 +458,7 @@ namespace Microsoft.Win32
          * Note that <var>name</var> can be null or "", at which point the
          * unnamed or default value of this Registry key is returned, if any.
          * The default values for RegistryKeys are OS-dependent.  NT doesn't
-         * have them by default, but they can exist and be of any type.  On
-         * Win95, the default value is always an empty key of type REG_SZ.
-         * Win98 supports default values of any type, but defaults to REG_SZ.
+         * have them by default, but they can exist and be of any type. 
          *
          * @param name Name of value to retrieve.
          * @param defaultValue Value to return if <i>name</i> doesn't exist.
index 6a138de..097ed44 100644 (file)
@@ -247,9 +247,6 @@ namespace System.Diagnostics
 
     // Class which represents a description of a stack trace
     // There is no good reason for the methods of this class to be virtual.  
-    // In order to ensure trusted code can trust the data it gets from a 
-    // StackTrace, we use an InheritanceDemand to prevent partially-trusted
-    // subclasses.
     public class StackTrace
     {
         private StackFrame[] frames;
index fe3729f..7cfd4db 100644 (file)
@@ -241,44 +241,38 @@ namespace System
         {
             char[] block = null;
 
-            // Make sure pStrings is not leaked with async exceptions
             RuntimeHelpers.PrepareConstrainedRegions();
+
+            char* pStrings = null;
+
             try
             {
-            }
-            finally
-            {
-                char* pStrings = null;
-
-                try
+                pStrings = Win32Native.GetEnvironmentStrings();
+                if (pStrings == null)
                 {
-                    pStrings = Win32Native.GetEnvironmentStrings();
-                    if (pStrings == null)
-                    {
-                        throw new OutOfMemoryException();
-                    }
+                    throw new OutOfMemoryException();
+                }
 
-                    // Format for GetEnvironmentStrings is:
-                    // [=HiddenVar=value\0]* [Variable=value\0]* \0
-                    // See the description of Environment Blocks in MSDN's
-                    // CreateProcess page (null-terminated array of null-terminated strings).
+                // Format for GetEnvironmentStrings is:
+                // [=HiddenVar=value\0]* [Variable=value\0]* \0
+                // See the description of Environment Blocks in MSDN's
+                // CreateProcess page (null-terminated array of null-terminated strings).
 
-                    // Search for terminating \0\0 (two unicode \0's).
-                    char* p = pStrings;
-                    while (!(*p == '\0' && *(p + 1) == '\0'))
-                        p++;
+                // Search for terminating \0\0 (two unicode \0's).
+                char* p = pStrings;
+                while (!(*p == '\0' && *(p + 1) == '\0'))
+                    p++;
 
-                    int len = (int)(p - pStrings + 1);
-                    block = new char[len];
+                int len = (int)(p - pStrings + 1);
+                block = new char[len];
 
-                    fixed (char* pBlock = block)
-                        string.wstrcpy(pBlock, pStrings, len);
-                }
-                finally
-                {
-                    if (pStrings != null)
-                        Win32Native.FreeEnvironmentStrings(pStrings);
-                }
+                fixed (char* pBlock = block)
+                    string.wstrcpy(pBlock, pStrings, len);
+            }
+            finally
+            {
+                if (pStrings != null)
+                    Win32Native.FreeEnvironmentStrings(pStrings);
             }
 
             return block;
index 6be5578..d201e12 100644 (file)
@@ -57,8 +57,7 @@ namespace System.Reflection
                         // this should be an invocable method, determine the other flags that participate in invocation
                         invocationFlags |= RuntimeMethodHandle.GetSecurityFlags(this);
 
-                        // Check for attempt to create a delegate class, we demand unmanaged
-                        // code permission for this since it's hard to validate the target address.
+                        // Check for attempt to create a delegate class.
                         if (typeof(Delegate).IsAssignableFrom(DeclaringType))
                             invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR;
                     }
index 734a494..11873bc 100644 (file)
@@ -130,13 +130,7 @@ using System.IO;
 
 namespace System.Runtime.InteropServices
 {
-    // This class should not be serializable - it's a handle.  We require unmanaged
-    // code permission to subclass CriticalHandle to prevent people from writing a 
-    // subclass and suddenly being able to run arbitrary native code with the
-    // same signature as CloseHandle.  This is technically a little redundant, but
-    // we'll do this to ensure we've cut off all attack vectors.  Similarly, all
-    // methods have a link demand to ensure untrusted code cannot directly edit
-    // or alter a handle.
+    // This class should not be serializable - it's a handle
     public abstract class CriticalHandle : CriticalFinalizerObject, IDisposable
     {
         // ! Do not add or rearrange fields as the EE depends on this layout.
index 73a3721..e7a3166 100644 (file)
@@ -173,15 +173,10 @@ namespace System.Runtime.InteropServices
 
             pointer = null;
             RuntimeHelpers.PrepareConstrainedRegions();
-            try
-            {
-            }
-            finally
-            {
-                bool junk = false;
-                DangerousAddRef(ref junk);
-                pointer = (byte*)handle;
-            }
+
+            bool junk = false;
+            DangerousAddRef(ref junk);
+            pointer = (byte*)handle;
         }
 
         public void ReleasePointer()
index f9f87bc..430574b 100644 (file)
@@ -241,24 +241,20 @@ namespace System.Runtime
                         // Attempt to grow the OS's page file.  Note that we ignore
                         // any allocation routines from the host intentionally.
                         RuntimeHelpers.PrepareConstrainedRegions();
-                        try
-                        {
-                        }
-                        finally
+
+                        // This shouldn't overflow due to the if clauses above.
+                        UIntPtr numBytes = new UIntPtr(segmentSize);
+                        unsafe
                         {
-                            // This shouldn't overflow due to the if clauses above.
-                            UIntPtr numBytes = new UIntPtr(segmentSize);
-                            unsafe
+                            void* pMemory = Win32Native.VirtualAlloc(null, numBytes, Win32Native.MEM_COMMIT, Win32Native.PAGE_READWRITE);
+                            if (pMemory != null)
                             {
-                                void* pMemory = Win32Native.VirtualAlloc(null, numBytes, Win32Native.MEM_COMMIT, Win32Native.PAGE_READWRITE);
-                                if (pMemory != null)
-                                {
-                                    bool r = Win32Native.VirtualFree(pMemory, UIntPtr.Zero, Win32Native.MEM_RELEASE);
-                                    if (!r)
-                                        __Error.WinIOError();
-                                }
+                                bool r = Win32Native.VirtualFree(pMemory, UIntPtr.Zero, Win32Native.MEM_RELEASE);
+                                if (!r)
+                                    __Error.WinIOError();
                             }
                         }
+
                         continue;
 
                     case 2:
@@ -304,14 +300,9 @@ namespace System.Runtime
                 CheckForFreeAddressSpace(segmentSize, true);
 
             RuntimeHelpers.PrepareConstrainedRegions();
-            try
-            {
-            }
-            finally
-            {
-                SharedStatics.AddMemoryFailPointReservation((long)size);
-                _mustSubtractReservation = true;
-            }
+
+            SharedStatics.AddMemoryFailPointReservation((long)size);
+            _mustSubtractReservation = true;
 #endif
         }
 
@@ -414,14 +405,9 @@ namespace System.Runtime
             if (_mustSubtractReservation)
             {
                 RuntimeHelpers.PrepareConstrainedRegions();
-                try
-                {
-                }
-                finally
-                {
-                    SharedStatics.AddMemoryFailPointReservation(-((long)_reservedMemory));
-                    _mustSubtractReservation = false;
-                }
+
+                SharedStatics.AddMemoryFailPointReservation(-((long)_reservedMemory));
+                _mustSubtractReservation = false;
             }
 
             /*
index 6d6d6f3..cbb9562 100644 (file)
@@ -11,7 +11,6 @@
 ** (i.e. the finalizer is guaranteed to run, won't be aborted by the host and is
 ** run after the finalizers of other objects collected at the same time).
 **
-** You must possess UnmanagedCode permission in order to derive from this class.
 **
 ** 
 ===========================================================*/
index 369bcb0..e457f15 100644 (file)
@@ -790,16 +790,11 @@ namespace System.Threading
         {
             // needed for DangerousAddRef
             RuntimeHelpers.PrepareConstrainedRegions();
-            try
+
+            m_internalWaitObject = waitObject;
+            if (waitObject != null)
             {
-            }
-            finally
-            {
-                m_internalWaitObject = waitObject;
-                if (waitObject != null)
-                {
-                    m_internalWaitObject.SafeWaitHandle.DangerousAddRef(ref bReleaseNeeded);
-                }
+                m_internalWaitObject.SafeWaitHandle.DangerousAddRef(ref bReleaseNeeded);
             }
         }
 
@@ -810,47 +805,43 @@ namespace System.Threading
             bool result = false;
             // needed for DangerousRelease
             RuntimeHelpers.PrepareConstrainedRegions();
-            try
-            {
-            }
-            finally
+
+            // lock(this) cannot be used reliably in Cer since thin lock could be
+            // promoted to syncblock and that is not a guaranteed operation
+            bool bLockTaken = false;
+            do
             {
-                // lock(this) cannot be used reliably in Cer since thin lock could be
-                // promoted to syncblock and that is not a guaranteed operation
-                bool bLockTaken = false;
-                do
+                if (Interlocked.CompareExchange(ref m_lock, 1, 0) == 0)
                 {
-                    if (Interlocked.CompareExchange(ref m_lock, 1, 0) == 0)
+                    bLockTaken = true;
+                    try
                     {
-                        bLockTaken = true;
-                        try
+                        if (ValidHandle())
                         {
-                            if (ValidHandle())
+                            result = UnregisterWaitNative(GetHandle(), waitObject == null ? null : waitObject.SafeWaitHandle);
+                            if (result == true)
                             {
-                                result = UnregisterWaitNative(GetHandle(), waitObject == null ? null : waitObject.SafeWaitHandle);
-                                if (result == true)
+                                if (bReleaseNeeded)
                                 {
-                                    if (bReleaseNeeded)
-                                    {
-                                        m_internalWaitObject.SafeWaitHandle.DangerousRelease();
-                                        bReleaseNeeded = false;
-                                    }
-                                    // if result not true don't release/suppress here so finalizer can make another attempt
-                                    SetHandle(InvalidHandle);
-                                    m_internalWaitObject = null;
-                                    GC.SuppressFinalize(this);
+                                    m_internalWaitObject.SafeWaitHandle.DangerousRelease();
+                                    bReleaseNeeded = false;
                                 }
+                                // if result not true don't release/suppress here so finalizer can make another attempt
+                                SetHandle(InvalidHandle);
+                                m_internalWaitObject = null;
+                                GC.SuppressFinalize(this);
                             }
                         }
-                        finally
-                        {
-                            m_lock = 0;
-                        }
                     }
-                    Thread.SpinWait(1);     // yield to processor
+                    finally
+                    {
+                        m_lock = 0;
+                    }
                 }
-                while (!bLockTaken);
+                Thread.SpinWait(1);     // yield to processor
             }
+            while (!bLockTaken);
+
             return result;
         }