Static Analysis Problem Type Reference

Uninitialized read of a bitfield

A bitfield of struct object is read without having been previously written.

This diagnostic is emitted when a bitfield of struct object allocated locally (on stack) or dynamically is not set before it is read. For local variables, the storage lifetime begins at the entry point to the block where the variable was declared (usually the subroutine itself). For dynamically allocated storage, the storage lifetime begins at the allocation point. An uninitialized read is possible if the program can execute along a path from the beginning of the storage lifetime to the indicated reference that does not encounter any assignment to that storage. This error indicates that at least one such possible execution path was found.

Sometimes the execution path that was identified cannot actually be executed. In this case, the error may be incorrect. However, there may be another path that can be executed that also performs an uninitialized read. Before dismissing this error as a false positive, make sure that no bad execution paths exist.

ID

Code Location

Description

1

Uninitialized read

The place where the variable was read

Example


int main(int argc, const char* argv[])
{
    struct {
        int data: 31;
        int flag: 1;
    } s;
 
    if (argc > 1) {
        s.flag = 1;
        s.data = argc;
    }
    return s.data; // oops: possible uninitialized read of a bitfield
}