Thread overview
[Issue 8986] New: The PVS-Studio analyzer has something for you
Nov 09, 2012
Andrey Karpov
Nov 09, 2012
Andrey Karpov
Nov 09, 2012
Walter Bright
November 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8986

           Summary: The PVS-Studio analyzer has something for you
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: karpov@viva64.com


--- Comment #0 from Andrey Karpov <karpov@viva64.com> 2012-11-09 04:20:53 PST ---
Perhaps there are other errors. I have studied the report unthoughtful. The report can be viewed by downloading the PVS-Studio trial version of the analyzer. I think trial version will be enough.

---------------------

V522 Dereferencing of the null pointer 'v' might take place. interpret.c 1711

Expression *getVarExp(Loc loc, InterState *istate, Declaration *d, CtfeGoal
goal)
{
  ....
  VarDeclaration *v = d->isVarDeclaration();
  if (v)
  {
    ....
  }
  else if (s)
  {
    if (s->dsym->toInitializer() == s->sym)
      ....
    else
      error(loc,
            "cannot interpret symbol %s at compile time",
            v->toChars());
  }
  ....
}
---------------------
V519 The 'c2' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1860, 1861. cod2.c 1861

code *cdcond(elem *e,regm_t *pretregs)
{
  code *cc,*c,*c1,*cnop1,*c2,*cnop2;
  ....
  c2 = codelem(e22,&retregs,FALSE);
  c2 = cat(c1, fixresult(e22,retregs,pretregs));
  ....
}

Most likely this is what should be written here: c2 = cat(c2, ....);
---------------------
V612 An unconditional 'return' within a loop. cgxmm.c 825

code *cdvector(elem *e, regm_t *pretregs)
{
  ....
  code *c = CNIL;
  for (int i = 0; i < n; i++)
  {
    c = cat(c, codelem(params[i], pretregs, FALSE));
    *pretregs = 0;      // in case they got set
    return c;
  }
  ....
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8986


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2012-11-09 04:47:20 PST ---
(In reply to comment #0)

> Perhaps there are other errors. I have studied the report unthoughtful. The report can be viewed by downloading the PVS-Studio trial version of the analyzer. I think trial version will be enough.

Thank you for your valuable work Andrey, we read often your articles linked and discussed on Reddit. PVS-Studio seems a interesting tool.

D language itself (and not its compilers) is designed to help D programmers
avoid or remove many of the bugs found by PVS-Studio, see as example:
http://d.puremagic.com/issues/show_bug.cgi?id=5409
So in a sense D makes tools like PVS-Studio less necessary.


> V519 The 'c2' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1860, 1861. cod2.c 1861
> 
> code *cdcond(elem *e,regm_t *pretregs)
> {
>   code *cc,*c,*c1,*cnop1,*c2,*cnop2;
>   ....
>   c2 = codelem(e22,&retregs,FALSE);
>   c2 = cat(c1, fixresult(e22,retregs,pretregs));
>   ....
> }
> 
> Most likely this is what should be written here: c2 = cat(c2, ....);

That's a bug in the C++ code. Maybe it's possible to add a warning inside the D compiler to guard against similar bugs in D code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8986



--- Comment #2 from Andrey Karpov <karpov@viva64.com> 2012-11-09 04:51:49 PST ---
Yes, I know what you are studying common problems in C + + to improve D. Nice to know that my examples are useful.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8986



--- Comment #3 from github-bugzilla@puremagic.com 2012-11-09 11:19:11 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b72f726f84ee58d14b26cc7fdb49a6665932ec80 fix Issue 8986 - The PVS-Studio analyzer has something for you

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8986



--- Comment #4 from github-bugzilla@puremagic.com 2012-11-09 11:20:40 PST ---
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/8dcabd3debb7b891fa5471da98034264caf90545 fix Issue 8986 - The PVS-Studio analyzer has something for you

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8986


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------