SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
C

C static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your C code

  • All rules 420
  • Vulnerability14
  • Bug111
  • Security Hotspot19
  • Code Smell276

  • Quick Fix 27
Filtered: 4 rules found
since-c++11
    Impact
      Clean code attribute
        1. A single L in a literal suffix should only be used for long values

           Code Smell
        2. Functions which do not return should be declared as "noreturn"

           Code Smell
        3. Local variables should not be volatile

           Code Smell
        4. Dynamic memory shall be managed automatically

           Code Smell

        Dynamic memory shall be managed automatically

        adaptability - focused
        maintainability
        Code Smell
        • pitfall
        • since-c++11
        • misra-c++2023
        • misra-required

        Why is this an issue?

        More Info

        This rule is part of MISRA C++:2023.

        Usage of this content is governed by Sonar’s terms and conditions. Redistribution is prohibited.

        Rule 21.6.2 - Dynamic memory shall be managed automatically

        [expr.delete]

        Category: Required

        Analysis: Decidable,Single Translation Unit

        Amplification

        A program shall not take the address of or use:

        • Any non-placement form of new or delete;
        • Any of the functions malloc, calloc, realloc, aligned_alloc, free;
        • Any member function named allocate or deallocate enclosed by namespace std;
        • std::unique_ptr::release.

        Rationale

        The use of dynamic memory requires the tracking of any memory resources that are allocated to ensure that they are released appropriately (no memory leaks, no double frees, use of a matching deallocation function). This is likely to be error prone (possibly leading to undefined behaviour) if it is not managed automatically using facilities such as std::make_unique or std::vector.

        In addition, C-style allocation is not type safe and does not invoke constructors or destructors.

        Note: the use of placement new, which is non-allocating, is restricted by M23_329: MISRA C++ 2023 Rule 21.6.3.

        Example

        class A { /* ... */ };
        
        auto p1 = static_cast< A * >( malloc( sizeof( A ) ) );  // Non-compliant
        auto p2 = new A;                                        // Non-compliant
        auto p3 = std::make_unique< A >();                      // Compliant
        auto p4 = p3.release();                                 // Non-compliant
        
        
        void f1( std::pmr::memory_resource & mr, A * p )
        {
          void * iptr = mr.allocate( sizeof( A ) );             // Non-compliant
        
          delete p;   // Non-compliant - undefined behaviour if p was allocated using new[]
        }
        

        Copyright The MISRA Consortium Limited © 2023

          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI

        © 2025 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use