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:
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:
building without -DNDEBUG yields the correct behavior:
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:
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
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:
The failure case can be readily observed by compiling Cligen with
-DNDEBUG
and running thecligen_hello
test application. In this case, typinghello<tab><tab><tab>...
causes Cligen to just keep repeating thehello
keyword:building without
-DNDEBUG
yields the correct behavior: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:
https://github.com/clicon/cligen/blob/9e6f5ad5568d3fdbb1f9e0a585bffbff0204c700/cligen_match.c#L238