indent(1): Rearrange option parsing code to squelch clang's static analyzer.
clang-analyzer complained that eqin() sets file-scoped pointer param_start
to point into char buffer defined in scan_profile(), and once
scan_profile() exits, param_start is a "dangling reference". param_start
was never used afterwards, but it's cleaner to move it to set_option()
which is the only branch where param_start is needed.
Reference:
ab0e44e5da
Differential Revision: https://reviews.freebsd.org/D6966 (Partial)
Submitted by: Piotr Stefaniak
This commit is contained in:
parent
efc12d78f7
commit
e725fe4b06
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=303601
@ -223,17 +223,14 @@ scan_profile(FILE *f)
|
||||
}
|
||||
}
|
||||
|
||||
const char *param_start;
|
||||
|
||||
static int
|
||||
static const char *
|
||||
eqin(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1) {
|
||||
if (*s1++ != *s2++)
|
||||
return (false);
|
||||
return (NULL);
|
||||
}
|
||||
param_start = s2;
|
||||
return (true);
|
||||
return (s2);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -257,11 +254,12 @@ set_defaults(void)
|
||||
void
|
||||
set_option(char *arg)
|
||||
{
|
||||
struct pro *p;
|
||||
struct pro *p;
|
||||
const char *param_start;
|
||||
|
||||
arg++; /* ignore leading "-" */
|
||||
for (p = pro; p->p_name; p++)
|
||||
if (*p->p_name == *arg && eqin(p->p_name, arg))
|
||||
if (*p->p_name == *arg && (param_start = eqin(p->p_name, arg)) != NULL)
|
||||
goto found;
|
||||
errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
|
||||
found:
|
||||
|
Loading…
Reference in New Issue
Block a user