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
  • 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 315
  • Vulnerability13
  • Bug76
  • Security Hotspot19
  • Code Smell207

  • Quick Fix 19
Filtered: 111 rules found
based-on-misra
    Impact
      Clean code attribute
        1. "goto" should jump to labels declared later in the same function

           Code Smell
        2. "<time.h>" should not be used

           Code Smell
        3. "atof", "atoi" and "atol" from <stdlib.h> should not be used

           Bug
        4. "<stdio.h>" should not be used in production code

           Code Smell
        5. "<signal.h>" should not be used

           Bug
        6. "errno" should not be used

           Code Smell
        7. Dynamic heap memory allocation should not be used

           Bug
        8. "setjmp" and "longjmp" should not be used

           Code Smell
        9. Reserved identifiers should not be defined or declared

           Code Smell
        10. Lines starting with "#" should contain valid preprocessing directives

           Bug
        11. Only standard forms of the "defined" directive should be used

           Code Smell
        12. Preprocessor operators "#" and "##" should not be used

           Code Smell
        13. Macros used in preprocessor directives should be defined before use

           Bug
        14. Function-like macros should not be invoked without all of their arguments

           Bug
        15. Function-like macros should not be used

           Code Smell
        16. "#undef" should be used with caution

           Code Smell
        17. Macros should not be #define'd or #undef'd within a block

           Code Smell
        18. "#include" directives should be followed by either <filename> or "filename" sequences

           Bug
        19. Non-standard characters should not occur in header file names in "#include" directives

           Bug
        20. Unions should not be used

           Code Smell
        21. Structure and union types should be complete at the end of a translation unit

           Code Smell
        22. The address of an automatic object should not be assigned to another object that may persist after the first object has ceased to exist

           Bug
        23. Object declarations should contain no more than 2 levels of pointer indirection

           Code Smell
        24. Function names should be used either as a call with a parameter list or with the "&" operator

           Code Smell
        25. Function exit paths should have appropriate return values

           Bug
        26. The number of arguments passed to a function should match the number of parameters

           Bug
        27. Functions without parameters should be declared with parameter type "void"

           Code Smell
        28. Parameters in a function prototype should be named

           Code Smell
        29. Recursion should not be used

           Code Smell
        30. Loops should not have more than one "break" or "goto" statement

           Code Smell
        31. The right-hand operands of && and || should not contain side effects

           Code Smell
        32. "continue" should not be used

           Code Smell
        33. "goto" statement should not be used

           Code Smell
        34. Non-empty statements should change control flow or have at least one side-effect

           Bug
        35. Unused type declarations should be removed

           Code Smell
        36. The three expressions of a "for" statement should only be concerned with loop control

           Code Smell
        37. Tests of non-Boolean values against zero should be explicit

           Code Smell
        38. Increment (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expression

           Code Smell
        39. Comma operator should not be used

           Code Smell
        40. Unary minus should not be applied to an unsigned expression

           Bug
        41. Bitwise operators should not be applied to signed operands

           Bug
        42. "enum" values should not be used as operands to built-in operators other than [ ], =, ==, !=, unary &, and the relational operators <, <=, >, >=

           Code Smell
        43. "bool" expressions should not be used as operands to built-in operators other than =, &&, ||, !, ==, !=, unary &, and the conditional operator

           Code Smell
        44. Operands of "&&" and "||" should be primary (C) or postfix (C++) expressions

           Code Smell
        45. Boolean operations should not have numeric operands, and vice versa

           Bug
        46. Objects with integer type should not be converted to objects with pointer type

           Bug
        47. Pointer conversions should be restricted to a safe subset

           Bug
        48. Function pointers should not be converted to any other type

           Bug
        49. Constants of unsigned type should have a "U" suffix

           Code Smell
        50. Results of ~ and << operations on operands of underlying types unsigned char and unsigned short should immediately be cast to the operand's underlying type

           Bug
        51. The value of a complex expression should only be cast to a type that is narrower and of the same signedness as the underlying type of the expression

           Code Smell
        52. Signed and unsigned types should not be mixed in expressions

           Code Smell
        53. "enum" members with implicit values should not collide with other enumerators

           Code Smell
        54. Variables should be initialized before use

           Bug
        55. Braces should be used to indicate and match the structure in the non-zero initialization of arrays and structures

           Code Smell
        56. Array declarations should include an explicit size specification

           Code Smell
        57. Object and function types should be explicitly stated in their declarations and definitions

           Code Smell
        58. Functions should be declared explicitly

           Code Smell
        59. Literal suffix "L" for long integers shall be upper case

           Code Smell
        60. String literals with different prefixes should not be concatenated

           Bug
        61. Bit fields should be declared with appropriate types

           Code Smell
        62. typedefs that indicate size and signedness should be used in place of the basic types

           Code Smell
        63. Appropriate char types should be used for character and integer values

           Code Smell
        64. Identifiers should not be longer than 31 characters

           Code Smell
        65. Digraphs should not be used

           Code Smell
        66. Trigraphs should not be used

           Code Smell
        67. Only escape sequences defined in the ISO C standard should be used

           Bug
        68. All uses of the #pragma directive should be documented

           Code Smell
        69. Source code should only use /* ... */ style comments

           Code Smell
        70. Macro arguments should not contain preprocessing directives

           Bug
        71. Names of well-known C standard library macros and functions should not be used as identifiers

           Code Smell
        72. Relational and subtraction operators should not be used with pointers to different arrays

           Bug
        73. Pointer and reference local variables should be "const" if the corresponding object is not modified

           Code Smell
        74. Unevaluated operands should not have side effects

           Code Smell
        75. User-defined types should not be passed as variadic arguments

           Bug
        76. Keywords shall not be used as macros identifiers

           Code Smell
        77. "default" clauses should be first or last

           Code Smell
        78. Integral operations should not overflow

           Bug
        79. Conditionally executed code should be reachable

           Bug
        80. The "<stdlib.h>" functions "bsearch" and "qsort" should not be used

           Bug
        81. Octal and hexadecimal escape sequences should be terminated

           Code Smell
        82. Flexible array members should not be declared

           Code Smell
        83. Line-splicing should not be used in "//" comments

           Bug
        84. Single-bit named bit fields should not be of a signed type

           Bug
        85. "for" loop counters should not have essentially floating type

           Bug
        86. "goto" statements should not be used to jump into blocks

           Code Smell
        87. "restrict" should not be used

           Code Smell
        88. "static" should not be used for the size of an array parameter

           Code Smell
        89. Pointers should not be cast to integral types

           Bug
        90. All code should be reachable

           Bug
        91. Pre-defined macros should not be defined, redefined or undefined

           Code Smell
        92. Multiple variables should not be declared on the same line

           Code Smell
        93. Octal values should not be used

           Code Smell
        94. "switch" statements should have "default" clauses

           Code Smell
        95. "if" statements should be preferred over "switch" when simpler

           Code Smell
        96. Switch cases should end with an unconditional "break" statement

           Code Smell
        97. "for" loop stop conditions should be invariant

           Code Smell
        98. "if ... else if" constructs should end with "else" clauses

           Code Smell
        99. Sections of code should not be commented out

           Code Smell
        100. Floating point numbers should not be tested for equality

           Bug
        101. Function parameters' initial values should not be ignored

           Bug
        102. "switch" statements should not contain non-case labels

           Code Smell
        103. Control structures should use curly braces

           Code Smell
        104. Unused function parameters should be removed

           Code Smell
        105. Unused functions and methods should be removed

           Code Smell
        106. Assignments should not be made from within conditions

           Code Smell
        107. Variables should not be shadowed

           Code Smell
        108. Empty statements should be removed

           Code Smell
        109. "/*" and "//" should not be used within comments

           Code Smell
        110. Unused labels should be removed

           Code Smell
        111. A function should have a single point of exit at the end of the function

           Code Smell

        Array declarations should include an explicit size specification

        intentionality - clear
        maintainability
        Code Smell
        • based-on-misra
        • cert

        Why is this an issue?

        More Info

        It is possible to declare an array without explicitly specifying its size, but using an explicit size declaration is clearer, and is therefore preferred.

        Noncompliant code example

        int arr1 [ ];  // Noncompliant; nothing specified
        int arr2 [ ] = { [0] = 1, [12] = 36, [4] = 93 }; // Noncompliant; highest index determines size. May be difficult to spot
        int pirate [ ] = { 2, 4, 8, 42, 501, 90210, 7, 1776 }; // Noncompliant; size is implicit, not explicit
        

        Compliant solution

        int arr1 [10];
        int arr2 [13] = { [0] = 1, [12] = 36, [4] = 93 };
        int pirate [10] = { 2, 4, 8, 42, 501, 90210, 7, 1776 }; // Implicitly-assigned size was 8. Desired size was 10.
        
          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
          Developer Edition
          Available Since
          9.1

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use