Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix uninitialized read in tests #889

Merged
merged 2 commits into from
Apr 7, 2021
Merged

fix uninitialized read in tests #889

merged 2 commits into from
Apr 7, 2021

Commits on Feb 4, 2021

  1. initialize variable in tests

    This was detected while running the tests with the `-Wconditional-uninitialized` flag
    
    ```
    ./autogen.sh
    CC=clang CFLAGS="-Wconditional-uninitialized" ./configure
    make check
    ```
    
    The resulting warning is a false positive, but setting the value to -1
    ensures that the CHECK below will fail if recid is never written to.
    PiRK committed Feb 4, 2021
    Configuration menu
    Copy the full SHA
    3d2cf6c View commit details
    Browse the repository at this point in the history
  2. print warnings for conditional-uninitialized

    This compiler flag is available for clang but not gcc.
    
    Test plan:
    
    ```
    autogen.sh
    ./configure
    make check
    CC=clang ./configure
    make check
    ```
    
    If a variable is used uninitialized, the warning should look something
    like:
    ```
      CC       src/tests-tests.o
    src/tests.c:4336:15: warning: variable 'recid' may be uninitialized when used here [-Wconditional-uninitialized]
            CHECK(recid >= 0 && recid < 4);
                  ^~~~~
    ./src/util.h:54:18: note: expanded from macro 'CHECK'
        if (EXPECT(!(cond), 0)) { \
                     ^~~~
    ./src/util.h:41:39: note: expanded from macro 'EXPECT'
                                          ^
    src/tests.c:4327:14: note: initialize the variable 'recid' to silence this warning
        int recid;
                 ^
                  = 0
    1 warning generated.
    ```
    PiRK committed Feb 4, 2021
    Configuration menu
    Copy the full SHA
    99a1cfe View commit details
    Browse the repository at this point in the history