Rule Definition
Software featuring known weak coding practices results in unexpected and erroneous behaviour.
Remediation
Rewrite the source code to avoid having incorect type conversions or casts.
Violation Code Sample
class Example {
static void Cast() {
char ch = 'c';
var charToBool = Convert.ToBoolean(ch); // Violation
}
Reference
https://docs.microsoft.com/en-us/dotnet/api/system.convert.toboolean?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.convert.toboolean?view=netframework-4.8#System_Convert_ToBoolean_System_DateTime_ https://docs.microsoft.com/en-us/dotnet/api/system.convert.toboolean?view=netframework-4.8#System_Convert_ToBoolean_System_Char_
Related Technologies
Technical Criterion
CWE-681 - Incorrect Conversion between Numeric Types
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.