kspalaiologos / bzip3

A better and stronger spiritual successor to BZip2.
GNU Lesser General Public License v3.0
687 stars 38 forks source link

getopt_impl() loops forever when encounters unknown option #38

Closed tansy closed 2 years ago

tansy commented 2 years ago

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.

kspalaiologos commented 2 years ago

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