The Microsoft Corporation has recently published, for free, access the source code of the CoreCLR engine, which is a key component of .NET Core. We couldn’t help but pay attention to this event. The wider a project’s audience is, the worse defects found in the code will seem, won’t they? Despite Microsoft themselves being the authors of the product, there are still some issues to examine and think over in their code – just like in any other large project.
coreclr
Do not compare ‘this’ to nullptr anymore
The fragment is taken from CoreCLR project. This dangerous code is detected by the following diagnostic: V704 ‘this == nullptr’ expression should be avoided – this expression is always false on newer compilers, because ‘this’ pointer can never be NULL.
Continue reading
Avoid using multiple small #ifdef blocks
The fragment is taken from CoreCLR project. The error is detected by the following diagnostic: V522 Dereferencing of the null pointer ‘hp’ might take place.
Larger than 0 does not mean 1
The following code fragment is taken from CoreCLR project. The code has an error that analyzer diagnoses in the following way: V698 Expression ‘memcmp(….) == -1’ is incorrect. This function can return not only the value ‘-1’, but any negative value. Consider using ‘memcmp(….) < 0’ instead. Continue reading