D3-VI

Harden
Variable Initialization

Definition

Setting variables to a known value before use.

How it Works

Initializing variables upon declaration ensures that the variable has a known quantity before use.

Considerations

Default behavior when declaring variables varies by language.

This is particularly important in programming languages that do not initialize variables to a default value upon declaration. In these instances, the value that a variable will contain after declaration is indeterminate which can cause issues. In fact, that value could be different each time the program is ran.

Note: This resource should not be considered a definitive or exhaustive coding guideline.

Artifact Relationships

This defensive technique relates to specific digital artifacts.

hardens
Variable Initialization
Subroutine

References

Reference - Integer Initialization - GNU C Manual Reference - Variable Initialization - CWE-457