Infinite loop while parsing option characters
The DCDB source code assumes char
to be signed. This causes issues on platforms with char
being unsigned, such as ARMv8.
This mainly caused issues in getopt
related routines:
% dcdbpusher/dcdbpusher.cpp
int main(int argc, char **argv) {
[..]
char c;
while ((c = getopt(argc, argv, opts)) != -1) {
[..]
}
[..]
}
getopt
returns a signed int
, which is set to -1
once the option characters are exhausted. Given the cast to char
in the code above, on platforms with unsigned char
s, this leads to an infinite loop as -1
is interpreted as 255
.
I encountered three cases:
These issues appeared on a system with the following parameters:
- OS: OpenSUSE Leap 15.5
- Compiler: GCC-13 (13.2.1)
- Platform: ARMv8 aarch64 (Ampere Altra Max)
- Commit:
8327f336be5d41a61c6f78df25048341e85af3f3
(development branch, cloned 2024-01-23)
I will create a merge request with a proposed fix - simply adjusting the variable type from char
to int
. With this change, I was able to resolve this issue on my end.