Skip to contentSkip to conversation

lib/tst_test: Warn on repeated options

PATCH New Cyril Hrubis 2 participants 4 messages Nov 5, 2019 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/tst_test: Warn on repeated options

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.

---
 lib/tst_test.c | 3 +++
 1 file changed, 3 insertions(+)
lib/tst_test.c +3 -0
index c7b46d0d5..f41baf3cf 100644
@@ -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 : "";
 }
 
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/1 lib/tst_test: Warn on repeated options

Hi!

Quoted 11 lines
---
 lib/tst_test.c | 3 +++
 1 file changed, 3 insertions(+)
lib/tst_test.c +0 -0
index c7b46d0d5..f41baf3cf 100644

lib/tst_test.c static void parse_topt(unsigned int topts_len, int opt, char *optarg) · line 472

Quoted 5 lines
lib/tst_test.c +2 -0
@@ -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.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 lib/tst_test: Warn on repeated options

----- Original Message -----

Quoted 16 lines

Hi!

Quoted 15 lines
---
 lib/tst_test.c | 3 +++
 1 file changed, 3 insertions(+)
lib/tst_test.c +0 -0
index c7b46d0d5..f41baf3cf 100644
@@ -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);
 
Quoted 5 lines

lib/tst_test.c static void parse_topt(unsigned int topts_len, int opt, char *optarg) · line 472

Quoted 2 lines
lib/tst_test.c +2 -0
+	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.