diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 14:06:55 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 14:06:55 +0200 |
commit | f855c5b5bbbc6d5436741fd8108be64825a3c76b (patch) | |
tree | 0ee1242bc21dc75a12fae03a5bb211fe10c89625 /lib/tests/test_opts2.c | |
parent | 8ef825d85fb4d09c32ca44c545d6eb8d995ddea4 (diff) | |
download | monitoring-plugins-f855c5b5bbbc6d5436741fd8108be64825a3c76b.tar.gz |
general refactorin in lib, more local variables, real booleans
Diffstat (limited to 'lib/tests/test_opts2.c')
-rw-r--r-- | lib/tests/test_opts2.c | 17 |
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 | ||
24 | void my_free(int *argc, char **newargv, char **argv) { | 24 | void 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 | ||
48 | int array_diff(int i1, char **a1, int i2, char **a2) { | 49 | int 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 | ||
71 | int main(int argc, char **argv) { | 71 | int 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; |