X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Fhelpers.c;h=e7ab273cdcede67a9bec9ae868ec8d8faa84cd6b;hp=dfeb4e2e790a553173830d039ae84b8026df2fa8;hb=926996e88c32445c874ff9c4f47f159db6b45995;hpb=ac9d55d8c5af9697be8c4dd4f27de61e3cb8bf95 diff --git a/ccan/opt/helpers.c b/ccan/opt/helpers.c index dfeb4e2e..e7ab273c 100644 --- a/ccan/opt/helpers.c +++ b/ccan/opt/helpers.c @@ -1,5 +1,6 @@ /* Licensed under GPLv3+ - see LICENSE file for details */ #include +#include #include #include #include @@ -52,7 +53,7 @@ char *opt_set_invbool_arg(const char *arg, bool *b) /* Set a char *. */ char *opt_set_charp(const char *arg, char **p) { - *p = (char *)arg; + *p = cast_const(char *, arg); return NULL; } @@ -123,12 +124,18 @@ char *opt_inc_intval(int *i) char *opt_version_and_exit(const char *version) { printf("%s\n", version); + /* Don't have valgrind complain! */ + opt_free_table(); exit(0); } char *opt_usage_and_exit(const char *extra) { - printf("%s", opt_usage(opt_argv0, extra)); + char *usage = opt_usage(opt_argv0, extra); + printf("%s", usage); + /* Don't have valgrind complain! */ + free(usage); + opt_free_table(); exit(0); } @@ -258,7 +265,8 @@ static char * set_long_with_suffix(const char *arg, long *l, const long base) return err; *l = ll; - if (*l != ll) + /* Beware truncation, but don't generate untestable code. */ + if (sizeof(*l) != sizeof(ll) && *l != ll) return arg_bad("value '%s' does not fit into a long", arg); return NULL; } @@ -272,7 +280,8 @@ static char * set_ulong_with_suffix(const char *arg, unsigned long *ul, const lo if (ll < 0) return arg_bad("'%s' is negative but destination is unsigned", arg); *ul = ll; - if (*ul != ll) + /* Beware truncation, but don't generate untestable code. */ + if (sizeof(*ul) != sizeof(ll) && *ul != ll) return arg_bad("value '%s' does not fit into an unsigned long", arg); return NULL; }