diff mbox series

lib/tst_test: Warn on repeated options

Message ID 20191105120053.9173-1-chrubis@suse.cz
State Accepted
Headers show
Series lib/tst_test: Warn on repeated options | expand

Commit Message

Cyril Hrubis Nov. 5, 2019, noon UTC
The library is not designed in a way that would allow us to pass an
option mutiple times, if such case the last option occurence replaces
all previous ones.

This patch adds a warning in a case that the option pointer is non-NULL,
which means that it has been set at least once already.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
CC: Jan Stancek <jstancek@redhat.com>
---
 lib/tst_test.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Cyril Hrubis Nov. 5, 2019, 1:05 p.m. UTC | #1
Hi!
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> CC: Jan Stancek <jstancek@redhat.com>
> ---
>  lib/tst_test.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index c7b46d0d5..f41baf3cf 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -468,6 +468,9 @@ static void parse_topt(unsigned int topts_len, int opt, char *optarg)
>  	if (i >= topts_len)
>  		tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
>  
> +	if (*toptions[i].arg)
> +		tst_res(TWARN, "Option passed -%c multiple times", opt);

Obviously the -%c and passed should be swapped, I can do that before
pushing if the patch gets ack.
Jan Stancek Nov. 5, 2019, 1:32 p.m. UTC | #2
----- Original Message -----
> Hi!
> > Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> > CC: Jan Stancek <jstancek@redhat.com>
> > ---
> >  lib/tst_test.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/lib/tst_test.c b/lib/tst_test.c
> > index c7b46d0d5..f41baf3cf 100644
> > --- a/lib/tst_test.c
> > +++ b/lib/tst_test.c
> > @@ -468,6 +468,9 @@ static void parse_topt(unsigned int topts_len, int opt,
> > char *optarg)
> >  	if (i >= topts_len)
> >  		tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
> >  
> > +	if (*toptions[i].arg)
> > +		tst_res(TWARN, "Option passed -%c multiple times", opt);
> 
> Obviously the -%c and passed should be swapped, I can do that before
> pushing if the patch gets ack.

Acked-by: Jan Stancek <jstancek@redhat.com>
Cyril Hrubis Nov. 5, 2019, 3:25 p.m. UTC | #3
Hi!
Pushed, thanks.
diff mbox series

Patch

diff --git a/lib/tst_test.c b/lib/tst_test.c
index c7b46d0d5..f41baf3cf 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -468,6 +468,9 @@  static void parse_topt(unsigned int topts_len, int opt, char *optarg)
 	if (i >= topts_len)
 		tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
 
+	if (*toptions[i].arg)
+		tst_res(TWARN, "Option passed -%c multiple times", opt);
+
 	*(toptions[i].arg) = optarg ? optarg : "";
 }