Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iio_info currently assumes that the argument for an option that is parsed by getopt_long() is in the argv[] following the option and then the combination of option and argument always consumes two argv[] entries. This is not necessarily true though. getopt_long() accepts option and argument in the same argv[] entry. For short options the argument can directly follow the option character and for long options the argument can follow in the same argv[] entry separated by a '=' character. E.g. both -u ip:192.168.1.1 and -uip:192.168.1.1 as well as --uri 192.168.1.1 and --uri=192.168.1.1 are equivalent and all valid. As a result of this iio_info will show undefined behavior when option and argument are passed in the same argv[] entry (E.g. crash with a segmentation fault). To address this properly use the optarg and optind variables that are provided by the getopt() interface. optarg points to the start of the argument for the current option and optind will point to the first non option argv[] entry after all options have been scanned. Signed-off-by: Lars-Peter Clausen <[email protected]>
- Loading branch information