From e725fe4b067936d0a53cf96eced05831f1366937 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Sun, 31 Jul 2016 21:43:43 +0000 Subject: [PATCH] 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: https://github.com/pstef/freebsd_indent/commit/ab0e44e5da3ff0fa4b62e451e4bbc3ea1ec7f365 Differential Revision: https://reviews.freebsd.org/D6966 (Partial) Submitted by: Piotr Stefaniak --- usr.bin/indent/args.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c index 3321d20bd406..b32c8fc7bee9 100644 --- a/usr.bin/indent/args.c +++ b/usr.bin/indent/args.c @@ -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: