digitalmars.D.bugs - [Issue 5540] New: Probable bug-hiding redundancies
- d-bugmail puremagic.com (34/34) Feb 07 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5540
- d-bugmail puremagic.com (11/11) Feb 07 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5540
- d-bugmail puremagic.com (7/7) Apr 07 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5540
- d-bugmail puremagic.com (8/8) Jun 19 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5540
- d-bugmail puremagic.com (12/16) Jun 19 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5540
- d-bugmail puremagic.com (8/8) Jun 29 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5540
- d-bugmail puremagic.com (24/24) Jun 29 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5540
http://d.puremagic.com/issues/show_bug.cgi?id=5540
Summary: Probable bug-hiding redundancies
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
This is a real bug in good C++ code:
if ((p_newHeader.frame_num != m_lastSlice.frame_num) ||
(p_newHeader.pic_parameter_set_id !=
p_newHeader.pic_parameter_set_id) ||
(p_newHeader.field_pic_flag != p_newHeader.field_pic_flag) ||
(p_newHeader.bottom_field_flag != m_lastSlice.bottom_field_flag)
){
return false;
}
The bug is of the kind:
if (x != x) {}
Two other similar bugs:
if (x == x) {}
auto y = x - x;
For the compiler it's easy to spot such three situations. They are correct
code, yet experience shows that often such redundancies hide bugs. So I suggest
to add to DMD warnings for such tree situations.
See also bug 3878
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 07 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5540
Another case, in good C++ code (probably caused by not complete copy & paste &
modify):
return Contains(Sphere(lss.mP0, lss.mRadius)) &&
Contains(Sphere(lss.mP0, lss.mRadius));
That is of this kind:
x && x
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 07 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5540 Reference: http://www.viva64.com/en/a/0068/ -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 07 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5540 See a very nice example of bug of this kind, that's easy to find for a compiler or lint: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=139021 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 19 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5540See a very nice example of bug of this kind, that's easy to find for a compiler or lint: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=139021The bug in Andrej Mitrovic code was: if (mmioRead(hmmio, cast(LPSTR)&drum, DRUM.sizeof != DRUM.sizeof)) { mmioClose(hmmio, 0); return szErrorCannotRead; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 19 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5540 See also: http://www.viva64.com/en/b/0103/ http://www.viva64.com/en/d/0090/ -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 29 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5540
A class of bug-hiding redundancy:
if (x == 10)
foo1();
else if (x == 20)
foo2();
else if (x == 10) // ***
foo3();
Another class, two assignments to the same variable in a row:
x = foo();
x = bar();
While this is OK:
x = 1;
x = x + 1;
x = foo(x);
Another class (the two branches are equal):
if (x)
foo();
else
foo();
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 29 2011









d-bugmail puremagic.com 