kspalaiologos / bzip3

A better and stronger spiritual successor to BZip2.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getopt_impl() loops forever when encounters unknown option

tansy opened this issue · comments

commented

getopt_impl() loops forever when encounters unknown option

$ ./bzip3 -x
bzip3: illegal option: x
bzip3: illegal option: x
(... ad infinitum)
bzip3: illegal option: x
bzip3: illegal option: x^C

I tried to debug it but couldn't follow the logic of it. Things are not easier by the fact that it uses global variables. And there are variables of the same name (`opt') which seems to confuse gdb. There are other things I don't get, like if (operr && *optstring != ':') @main.c:59, where `*optstring' is first character of `optstring' which is unlikely to be ':'.

I bet you understand it.

Thanks for pointing it out, I forgot the exit() call in getopt_impl when operr=1.
Essentially, the only reason why I am using this and not the GNU getopt or literally any other implementation is the problem with positional arguments. How I use getopt and my custom implementation makes it possible to invoke bzip3 as e.g. bzip3 input.txt output.bz3 -feb 16