News  [SoftwareSite

Latest News
Older News
RSS Feed
 
Complete Projects
Useful Classes
Top Downloads
Message Board
AllAPI.net
 
Send Comments
Software License
Mentalis.org Buttons
Donate
 
Forums -> Security Library Forum
 
Careless usage of ArgumentNullException  
by kaalikas [kaalikas at gmail dot com]
posted on 2005/04/24

Don't throw ArgumentNullException in overloaded functions that merely forward the call to the "real" function with additional default parameters.
This prevents inlining of otherwise perfect inline candidates and doesn't add any value/information because the "real" function throws the ArgumentNullException anyway.

For example: Certificate.CreateFromCerFile(byte[] file) throws ArgumentNullException and Certificate.CreateFromCerFile(byte[] file, int offset, int size) also throws ArgumentNullException.

by kaalikas [kaalikas at gmail dot com]
posted on 2005/04/24

Sorry, this was a bad example...

SecureSocket.Send(byte[] buffer, int size, SocketFlags socketFlags) and SecureSocket.Send(byte[] buffer, int offset, int size, SocketFlags socketFlags) is an example where the former function doesn't need to throw ArgumentNullException.

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2005/04/24

As you probably noticed after you wrote your first post, most of these parameters checks are necessary to avoid a null reference exceptions.
As far as I can see are SecureSocket.Send with that particular signature and SecureSocket.Receive with the same signature the only two methods that should be modified.

Also keep in mind that
1) both methods are virtual, so they will never be inlined
2) a block of code that throws exceptions can still be inlined, as long as there are no catch blocks

by kaalikas [kaalikas at gmail dot com]
posted on 2005/04/25

Yeah, it turns out these two were the only ones - somehow I happened to look right at these functions first :D

Some other things that should improve performance: using Buffer.BlockCopy instead of Array.Copy; encapsulating handles in small leaf nodes (to avoid promoting large objects because of finalization) and replacing finalizers with dispose methods that close the handles to allow deterministic closing of handles and avoid finalizitaion (for example CertificateStore class could use this change)

by kaalikas [kaalikas at gmail dot com]
posted on 2005/04/25

I noticed that pinned GCHandles and Marshal.Copy are used in places where Buffer.BlockCopy would suffice.
For example in RIPEMD160Managed.HashCore function.

 

Copyright © 2002-2007, The Mentalis.org Team. All rights reserved.
This site is located at http://www.mentalis.org/
Send comments to the webmaster.