Browse Source

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 <rusty@rustcorp.com.au>
Rusty Russell 9 years ago
parent
commit
5877402640
6 changed files with 13 additions and 5 deletions
  1. 4 0
      ccan/cast/_info
  2. 3 3
      ccan/str/_info
  3. 1 1
      ccan/take/_info
  4. 2 0
      ccan/tal/grab_file/_info
  5. 2 0
      ccan/tal/str/_info
  6. 1 1
      ccan/typesafe_cb/_info

+ 4 - 0
ccan/cast/_info

@@ -24,6 +24,7 @@
  *	#include <ccan/cast/cast.h>
  *	#include <stdint.h>
  *	#include <stdio.h>
+ *	#include <stdlib.h>
  *
  *	// 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",

+ 3 - 3
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;
  *	}

+ 1 - 1
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");

+ 2 - 0
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]);

+ 2 - 0
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)

+ 1 - 1
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.