summaryrefslogtreecommitdiffstats
path: root/lib/tests/test_opts2.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-15 16:09:40 +0200
committerGitHub <noreply@github.com>2025-09-15 16:09:40 +0200
commit601a48a63e745817cf2a4c7f3ca526e393dd3fb8 (patch)
treeed011d8f2bfcde8750bca64c0f69407df4bd6444 /lib/tests/test_opts2.c
parent8ef825d85fb4d09c32ca44c545d6eb8d995ddea4 (diff)
parent15ecdb73ce5cda54f824e5a63ee8e801bf16a996 (diff)
downloadmonitoring-plugins-601a48a63e745817cf2a4c7f3ca526e393dd3fb8.tar.gz
Merge pull request #2150 from RincewindsHat/refactor/lib
general refactorin in lib, more local variables, real booleans
Diffstat (limited to 'lib/tests/test_opts2.c')
-rw-r--r--lib/tests/test_opts2.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c
index d1b0aca3..3dd1b039 100644
--- a/lib/tests/test_opts2.c
+++ b/lib/tests/test_opts2.c
@@ -23,15 +23,16 @@
23 23
24void my_free(int *argc, char **newargv, char **argv) { 24void my_free(int *argc, char **newargv, char **argv) {
25 /* Free stuff (and print while we're at it) */ 25 /* Free stuff (and print while we're at it) */
26 int i, freeflag = 1; 26 bool freeflag = true;
27
27 printf(" Arg(%i): ", *argc + 1); 28 printf(" Arg(%i): ", *argc + 1);
28 printf("'%s' ", newargv[0]); 29 printf("'%s' ", newargv[0]);
29 for (i = 1; i < *argc; i++) { 30 for (int i = 1; i < *argc; i++) {
30 printf("'%s' ", newargv[i]); 31 printf("'%s' ", newargv[i]);
31 /* Stop freeing when we get to the start of the original array */ 32 /* Stop freeing when we get to the start of the original array */
32 if (freeflag) { 33 if (freeflag) {
33 if (newargv[i] == argv[1]) { 34 if (newargv[i] == argv[1]) {
34 freeflag = 0; 35 freeflag = false;
35 } else { 36 } else {
36 free(newargv[i]); 37 free(newargv[i]);
37 } 38 }
@@ -46,13 +47,12 @@ void my_free(int *argc, char **newargv, char **argv) {
46} 47}
47 48
48int array_diff(int i1, char **a1, int i2, char **a2) { 49int array_diff(int i1, char **a1, int i2, char **a2) {
49 int i;
50
51 if (i1 != i2) { 50 if (i1 != i2) {
52 printf(" Argument count doesn't match!\n"); 51 printf(" Argument count doesn't match!\n");
53 return 0; 52 return 0;
54 } 53 }
55 for (i = 0; i <= i1; i++) { 54
55 for (int i = 0; i <= i1; i++) {
56 if (a1[i] == NULL && a2[i] == NULL) { 56 if (a1[i] == NULL && a2[i] == NULL) {
57 continue; 57 continue;
58 } 58 }
@@ -69,11 +69,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
69} 69}
70 70
71int main(int argc, char **argv) { 71int main(int argc, char **argv) {
72 char **argv_new = NULL;
73 int i, argc_test;
74
75 plan_tests(5); 72 plan_tests(5);
76 73
74 char **argv_new = NULL;
75 int argc_test;
77 { 76 {
78 char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *)NULL}; 77 char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *)NULL};
79 argc_test = 5; 78 argc_test = 5;