From 5877402640cff05f779b23a730e4cc62d729113f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 5 Nov 2016 07:26:47 +1030 Subject: [PATCH 1/1] cast, str, take, tal/grabfile, tal/str, typesafe_cb: use argc This avoids the warning about it being unused with -Wunused. Signed-off-by: Rusty Russell --- ccan/cast/_info | 4 ++++ ccan/str/_info | 6 +++--- ccan/take/_info | 2 +- ccan/tal/grab_file/_info | 2 ++ ccan/tal/str/_info | 2 ++ ccan/typesafe_cb/_info | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ccan/cast/_info b/ccan/cast/_info index b09e0344..29128b8d 100644 --- a/ccan/cast/_info +++ b/ccan/cast/_info @@ -24,6 +24,7 @@ * #include * #include * #include + * #include * * // Find char @orig in @str, if @repl, replace them. Return number. * static size_t find_chars(char *str, char orig, char repl) @@ -53,6 +54,9 @@ * { * uint64_t hash; * + * if (argc != 2) { + * fprintf(stderr, "Needs argument\n"); exit(1); + * } * // find_chars wants a non-const string, but doesn't * // need it if repl == 0. * printf("%zu %c's in 'test string'\n", diff --git a/ccan/str/_info b/ccan/str/_info index 251d999a..b579525f 100644 --- a/ccan/str/_info +++ b/ccan/str/_info @@ -26,11 +26,11 @@ * * int main(int argc, char *argv[]) * { - * if (argv[1] && streq(argv[1], "--verbose")) + * if (argc > 1 && streq(argv[1], "--verbose")) * printf("verbose set\n"); - * if (argv[1] && strstarts(argv[1], "--")) + * if (argc > 1 && strstarts(argv[1], "--")) * printf("Some option set\n"); - * if (argv[1] && strends(argv[1], "cow-powers")) + * if (argc > 1 && strends(argv[1], "cow-powers")) * printf("Magic option set\n"); * return 0; * } diff --git a/ccan/take/_info b/ccan/take/_info index 69382466..fcb4f318 100644 --- a/ccan/take/_info +++ b/ccan/take/_info @@ -37,7 +37,7 @@ * { * char *b; * - * if (argv[1]) // Mangle in place. + * if (argc > 1) // Mangle in place. * b = base(take(argv[1])); * else * b = base("test/string"); diff --git a/ccan/tal/grab_file/_info b/ccan/tal/grab_file/_info index 68ad089b..056f1099 100644 --- a/ccan/tal/grab_file/_info +++ b/ccan/tal/grab_file/_info @@ -18,6 +18,8 @@ * { * char *file; * + * if (argc > 2) + * err(1, "Takes 0 or 1 arguments"); * file = grab_file(NULL, argv[1]); * if (!file) * err(1, "Could not read file %s", argv[1]); diff --git a/ccan/tal/str/_info b/ccan/tal/str/_info index cb81c9e1..3037cfde 100644 --- a/ccan/tal/str/_info +++ b/ccan/tal/str/_info @@ -20,6 +20,8 @@ * char *textfile; * char **lines; * + * if (argc > 2) + * errx(1, "Takes 0 or 1 arguments"); * // Grab lines in file. * textfile = grab_file(NULL, argv[1]); * if (!textfile) diff --git a/ccan/typesafe_cb/_info b/ccan/typesafe_cb/_info index 165852a3..b4f379dd 100644 --- a/ccan/typesafe_cb/_info +++ b/ccan/typesafe_cb/_info @@ -106,7 +106,7 @@ * // Silly game to find the longest chain of values. * int main(int argc, char *argv[]) * { - * int i, run = 1, num = argv[1] ? atoi(argv[1]) : 0; + * int i, run = 1, num = argc > 1 ? atoi(argv[1]) : 0; * * for (i = 1; i < 1024;) { * // Since run is an int, compiler checks "add" does too. -- 2.39.2