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

Compiling with -DNDEBUG results in failure of test applications. #76

Closed
rcmcdonald91 opened this issue Mar 9, 2022 · 2 comments
Closed

Comments

@rcmcdonald91
Copy link
Contributor

rcmcdonald91 commented Mar 9, 2022

I stumbled onto an interesting bug related to the use of asserts() and the -DNDEBUG compiler flag. I have been experimenting with using CMake to build Cligen (you can find that attempt here: https://github.com/theonemcdonald/cligen/tree/cmake).

The CMake default CFLAGS for each build type are as follows:

CMAKE_C_FLAGS_DEBUG: -g
CMAKE_C_FLAGS_RELEASE: -O3 -DNDEBUG
CMAKE_C_FLAGS_RELWITHDEBINFO: -O2 -g -DNDEBUG
CMAKE_C_FLAGS_MINSIZEREL: -Os -DNDEBUG

The failure case can be readily observed by compiling Cligen with -DNDEBUG and running the cligen_hello test application. In this case, typing hello<tab><tab><tab>... causes Cligen to just keep repeating the hello keyword:

image

building without -DNDEBUG yields the correct behavior:

image

The issue appears to be related to an assert() call having undesired side-effects.

After consulting with Olof, we determined this to be a likely culprit that should be explored further:

assert((levels = cligen_cvv_levels(cvt)) >= 0);

cligen_match.c:239:18: warning: variable 'levels' is uninitialized when used here [-Wuninitialized]
    if (level >= levels)
                 ^~~~~~
cligen_match.c:236:15: note: initialize the variable 'levels' to silence this warning
    int levels;
              ^
               = 0
@olofhagsand
Copy link
Member

Should be fixed by the patch, please verify

@rcmcdonald91
Copy link
Contributor Author

Verified. This looks good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants