Avoid unsafe blocks

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: csharp-security/avoid-unsafe

Language: C#

Severity: Notice

Category: Security

Description

Avoid unsafe code blocks as much as possible. While unsafe blocks provide access to some important features of the C# language, you need to avoid using them as much as possible. For example, unsafe code allows developers to use pointers, but pointers and pointers arithmetic can lead to critical security issues. Unsafe code should be avoided or at least clearly identified in a small scope.

Learn More

Non-Compliant Code Examples

using System.IO;
using System.Security.Cryptography;

class MyClass {
    public void myMethod
    {
        unsafe{
            // statements
        }
       
    }
}
using System.IO;
using System.Security.Cryptography;

class MyClass {
    public unsafe void myMethod
    {
       // statements
    }
}

Compliant Code Examples

using System.IO;
using System.Security.Cryptography;

class MyClass {
    public void myMethod
    {
       // statements
    }
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis