mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
lightningd: configvar style fixes
1) We can't simply cast away const to manipulate a string, the compiler can assume we don't. The type must be made non-const. 2) cisspace() is nicer to use than isspace() (no cast required!) 3) Simply place a NUL terminator instead of using memmove to set it. 4) Use cast_const to add const to char **, where necessary. 5) Add Changelog line, for CHANGELOG.md Changelog-Fixed: Config: whitespace at the end of (most) options is now ignored, not complained about. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3e65ef4b12
commit
62f531a1f2
@ -31,7 +31,7 @@ const struct opt_table *configvar_unparsed(struct configvar *cv)
|
||||
ot = opt_find_short(cv->configline[0]);
|
||||
cv->optarg = NULL;
|
||||
} else {
|
||||
ot = opt_find_long(cv->configline, &cv->optarg);
|
||||
ot = opt_find_long(cv->configline, cast_const2(const char **, &cv->optarg));
|
||||
}
|
||||
if (!ot)
|
||||
return NULL;
|
||||
@ -51,18 +51,13 @@ const struct opt_table *configvar_unparsed(struct configvar *cv)
|
||||
return ot;
|
||||
}
|
||||
|
||||
static void trim_whitespace(const char *s)
|
||||
static void trim_whitespace(char *s)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
|
||||
/* Cast away const to allow modifications */
|
||||
char *mutable_s = (char *)s;
|
||||
|
||||
while (len > 0 && isspace((unsigned char)mutable_s[len - 1]))
|
||||
while (len > 0 && cisspace(s[len - 1]))
|
||||
len--;
|
||||
|
||||
/* Move null terminator to the end of the trimmed string */
|
||||
memmove(mutable_s + len, mutable_s + strlen(s), 1);
|
||||
s[len] = '\0';
|
||||
}
|
||||
|
||||
const char *configvar_parse(struct configvar *cv,
|
||||
|
@ -35,13 +35,13 @@ struct configvar {
|
||||
/* Where did we get this from? */
|
||||
enum configvar_src src;
|
||||
/* Never NULL, the whole line */
|
||||
const char *configline;
|
||||
char *configline;
|
||||
|
||||
/* These are filled in by configvar_parse */
|
||||
/* The variable name (without any =) */
|
||||
const char *optvar;
|
||||
/* NULL for no-arg options, otherwise points after =. */
|
||||
const char *optarg;
|
||||
char *optarg;
|
||||
/* Was this overridden by a following option? */
|
||||
bool overridden;
|
||||
};
|
||||
|
@ -1887,9 +1887,9 @@ void handle_early_opts(struct lightningd *ld, int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Free *str, set *str to copy with `cln` prepended */
|
||||
static void prefix_cln(const char **str STEALS)
|
||||
static void prefix_cln(char **str STEALS)
|
||||
{
|
||||
const char *newstr = tal_fmt(tal_parent(*str), "cln%s", *str);
|
||||
char *newstr = tal_fmt(tal_parent(*str), "cln%s", *str);
|
||||
tal_free(*str);
|
||||
*str = newstr;
|
||||
}
|
||||
@ -1910,7 +1910,7 @@ static void fixup_clnrest_options(struct lightningd *ld)
|
||||
&& !strstarts(cv->configline, "rest-certs="))
|
||||
continue;
|
||||
/* Did some (plugin) claim it? */
|
||||
if (opt_find_long(cv->configline, &cv->optarg))
|
||||
if (opt_find_long(cv->configline, cast_const2(const char **, &cv->optarg)))
|
||||
continue;
|
||||
if (!opt_deprecated_ok(ld,
|
||||
tal_strndup(tmpctx, cv->configline,
|
||||
|
Loading…
Reference in New Issue
Block a user