ACK: [PATCH] lib: fwts_args: clean up some scan-build warnings
ivanhu
ivan.hu at canonical.com
Wed Jun 8 07:07:00 UTC 2016
On 2016年06月04日 23:40, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> clang's scan-build is reporting some warnings on some
> potentially bad code, while I don't think these are a
> problem, it is wise to add some null pointer checks to
> be totally safe.
>
> fixes scan-build warnings:
> fwts_args.c:180:10: warning: Null pointer passed as
> an argument to a 'nonnull' parameter
> fwts_args.c:187:10: warning: Null pointer argument in
> call to string comparison function
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/lib/src/fwts_args.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index d4fa46a..57bff59 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -175,16 +175,20 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
> bool found = false;
>
> if (c != 0) {
> - for (i=0; i<options_table->num_options; i++) {
> - char *short_name = options_table->options[i].short_name;
> - if (index(short_name, c) != NULL) {
> + for (i = 0; i < options_table->num_options; i++) {
> + const char *short_name = options_table->options[i].short_name;
> +
> + if (short_name && index(short_name, c) != NULL) {
> found = true;
> break;
> }
> }
> } else { /* c is zero for long option cases but we need the right optarg_handler set */
> - for (i=0; i<options_table->num_options; i++) {
> - if (strcmp(options_table->options[i].long_name,long_options[option_index].name) == 0) {
> + for (i = 0; i < options_table->num_options; i++) {
> + const char *long_name = options_table->options[i].long_name;
> + const char *name = long_options[option_index].name;
> +
> + if (long_name && name && !strcmp(long_name, name)) {
> translated_long_option_index = i;
> found = true;
> break;
>
Acked-by: Ivan Hu <ivan.hu at canonical.com>
More information about the fwts-devel
mailing list