[cfe-dev] clang-tidy / static analysis

Richard via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 13 08:51:11 PST 2017


[Please reply *only* to the list and do not include my email directly
in the To: or Cc: of your reply; otherwise I will not see your reply.
Thanks.]

In article <CAAeLbQKtKAHE5RAweH2a0n+Dq8EwOKmjy8n2n1bMVYrDCdhQOQ at mail.gmail.com>,
    Maurizio Vitale via cfe-dev <cfe-dev at lists.llvm.org> writes:

> The idea is to find all uses of putenv and replace them w/ setenv. This
> requires analyzing the argument to discover constant parts in it (setenv
> require a separate variable name). It also require to check that the
> argument is not modified (or such modifications need also to be replaces w/
> setenvs).

In addition to what's already been mentioned, I would recommend
implementing your check in stages:

1. Constant string arguments

    putenv("FOO=bar");

    =>

    setenv("FOO", "bar", 1);

2. Constant environment variable names

    char buff[256];
    sprintf(buff, "FOO=%d", value);
    putenv(buff);

    =>

    char buff[256];
    sprintf(buff, "%d", value);
    setenv("FOO", buff, 1);

3. Varying environment variable names

    .... you get the idea :)

Basically start with the simplest case and get that working and then
enhance for subsequent cases.  You can even submit incremental work
for review and incorporation into clang-tidy this way.  It is better
to have a working check that handles simple cases and does no harm on
complex cases than to wait for a check that covers 100% of everything.
-- 
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
            The Terminals Wiki <http://terminals-wiki.org>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>


More information about the cfe-dev mailing list