Skip to content

[BUG] Uninitialized variable caused the CMCocka test to fail. #8988

@ShriramShastry

Description

@ShriramShastry

Describe the bug
A clear and concise description of what the bug is.
What have you tried to diagnose or workaround this issue?
Please also read https://thesofproject.github.io/latest/contribute/process/bug-tracking.html for further information on submitting bugs.
error: ‘scale_inv’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
To Reproduce
Steps to reproduce the behavior: (e.g. list commands or actions used to reproduce the bug)
Run ./test/test-all-defconfigs.sh
Reproduction Rate
How often does the issue happen ? i.e. 1/10 (once in ten attempts), 1/1000 or all the time.
Does the reproduction rate vary with any other configuration or user action, if so please describe and show the new reproduction rate.
Always
Expected behavior
A clear and concise description of what you expected to happen.
All cmocka test's
Impact
What impact does this issue have on your progress (e.g., annoyance, showstopper)
Cmocka cannot be tested for every configuration.
Environment

  1. Branch name and commit hash of the 2 repositories: sof (firmware/topology) and linux (kernel driver).
    • Kernel: {SHA}
    • SOF: {SHA}
  2. Name of the topology file
    • Topology: {FILE}
  3. Name of the platform(s) on which the bug is observed.
    • Platform: {PLATFORM}

Screenshots or console output
If applicable, add a screenshot (drag-and-drop an image), or console logs
(cut-and-paste text and put a code fence (```) before and after, to help
explain the issue.

An error warning that suggested there might be a problem with the variable scale_inv 
being used before it was initialized was sent to the compilation process. The Q_MULTSR_32X32 macro,
which multiplies two 32-bit numbers, uses scale_inv without first determining whether
it has been initialized, which could lead to undefined behavior. Local variables in C are not
automatically initialized.

Please also include the relevant sections from the firmware log and kernel log in the report (and attach the full logs for complete reference). Kernel log is taken from dmesg and firmware log from sof-logger. See https://thesofproject.github.io/latest/developer_guides/debugability/logger/index.html

only assignment to scale_inv is conditionally done inside an if block

if (i == 0) {
    scale_inv = Q_SHIFT_LEFT(ONE_Q30 / scale, 14, 16);
    fb->scale_log2 = base2_logarithm((uint32_t)scale) - LOG2_2P16;
}

we 've ensure that scale_inv has a deterministic initial value

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions