Bug 8986 – The PVS-Studio analyzer has something for you
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-09T04:20:00Z
Last change time
2015-06-09T05:11:49Z
Assigned to
nobody
Creator
karpov
Comments
Comment #0 by karpov — 2012-11-09T04:20:53Z
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;
}
....
}
Comment #1 by bearophile_hugs — 2012-11-09T04:47:20Z
(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.
Comment #2 by karpov — 2012-11-09T04:51:49Z
Yes, I know what you are studying common problems in C + + to improve D. Nice to know that my examples are useful.
Comment #3 by github-bugzilla — 2012-11-09T11:19:11Z