Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 Jul 2016 21:43:43 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r303601 - head/usr.bin/indent
Message-ID:  <201607312143.u6VLhhQB062414@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Sun Jul 31 21:43:43 2016
New Revision: 303601
URL: https://svnweb.freebsd.org/changeset/base/303601

Log:
  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

Modified:
  head/usr.bin/indent/args.c

Modified: head/usr.bin/indent/args.c
==============================================================================
--- head/usr.bin/indent/args.c	Sun Jul 31 21:36:40 2016	(r303600)
+++ head/usr.bin/indent/args.c	Sun Jul 31 21:43:43 2016	(r303601)
@@ -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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201607312143.u6VLhhQB062414>