Skip to content

Commit

Permalink
[cleanup] Rearrange option parsing code a bit to avoid complaints fro…
Browse files Browse the repository at this point in the history
…m static analyzers.

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.
  • Loading branch information
pstef committed Jul 31, 2016
1 parent a2203ed commit ab0e44e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions args.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,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);
}

/*
Expand All @@ -264,11 +261,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:
Expand Down

0 comments on commit ab0e44e

Please sign in to comment.