-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iio_attr 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_attr 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
1 parent
989db5e
commit faa6341
Showing
1 changed file
with
38 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters