C and C++


LANG.STRUCT.INIT.PIARR : Partially Uninitialized Array

Summary

Part, but not all, of an array is initialized, and the initializer is not a string literal or a designated initializer.

Properties

Class Name Partially Uninitialized Array
Significance style
Mnemonic LANG.STRUCT.INIT.PIARR
Categories
MisraC2023 MisraC2023:9.3 Arrays shall not be partially initialized
Misra2012 Misra2012:9.3 Arrays shall not be partially initialized
Misra2004 Misra2004:9.2 Braces shall be used to indicate and match the structure in the non-zero initialisation of arrays and structures
MisraC++2023 MisraC++2023:11.6.1 All variables should be initialized
CWE CWE:1419 Incorrect Initialization of Resource
JSF++ JSF++:144 Braces shall be used to indicate and match the structure in the non-zero initialization of arrays and structures.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Partially Uninitialized Array"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

int arr_partial[100] = {1,2,3}; /* 'Partially Uninitialized Array' warning issued here */      

char arr_partialstr[100] = "hello";                     /* string literal */  

int arr_partialzero[100] = {0};                         /* {0} initializes all elements to 0 */  

int arr_partialdes[100] = {[5]=0, [22]=6};              /* designated initializer */

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.