digitalmars.D.bugs - assert fails to fail
- Derek Parnell <derek psych.ward> May 30 2005
- "Walter" <newshound digitalmars.com> May 31 2005
- Thomas Kuehne <thomas-dloop kuehne.this-is.spam.cn> Jun 01 2005
Given the program below ...
[test.d]
<code>
debug(1) import std.stdio;
const int anything = -1000; // Line #2
dchar[] SomeFunc( dchar[] pText, out int pStopPosn)
{
if (pText.length == 0)
pStopPosn = 0;
else
pStopPosn = -1;
debug(1) writefln("DEBUG: using '%s' we get %d", pText, pStopPosn);
return pText.dup;
}
int main(char[][] pArgs)
{
int sp;
SomeFunc("123", sp);
debug(1) writefln("DEBUG: got %d", sp);
assert(sp == -1);
SomeFunc("", sp);
// if (sp != 0){} // Line #22
debug(1) writefln("DEBUG: got %d", sp);
assert(sp == -1);
return 0;
}
</code>
and compiled with "dmd test.d" version 0.125, the last assert() fails to
crash the program. However, if you comment out line #2 *or* uncomment line
#22, the program works as expected - that is, the assert catches the
mistake.
You can compile with -debug to take a look at the returned data and this
shows that it is being set correctly, its just that assert() doesn't seem
to see the most recent value.
I chopped down this example from a 3,600 line program so its taken a long
while to isolate the offending conditions.
--
Derek
Melbourne, Australia
31/05/2005 11:09:36 AM
May 30 2005
Sorry about that. It'll get fixed next update.
May 31 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Derek Parnell schrieb am Tue, 31 May 2005 11:19:42 +1000:Given the program below ... [test.d] <code> debug(1) import std.stdio; const int anything = -1000; // Line #2 dchar[] SomeFunc( dchar[] pText, out int pStopPosn) { if (pText.length == 0) pStopPosn = 0; else pStopPosn = -1; debug(1) writefln("DEBUG: using '%s' we get %d", pText, pStopPosn); return pText.dup; } int main(char[][] pArgs) { int sp; SomeFunc("123", sp); debug(1) writefln("DEBUG: got %d", sp); assert(sp == -1); SomeFunc("", sp); // if (sp != 0){} // Line #22 debug(1) writefln("DEBUG: got %d", sp); assert(sp == -1); return 0; } </code> and compiled with "dmd test.d" version 0.125, the last assert() fails to crash the program. However, if you comment out line #2 *or* uncomment line #22, the program works as expected - that is, the assert catches the mistake. You can compile with -debug to take a look at the returned data and this shows that it is being set correctly, its just that assert() doesn't seem to see the most recent value. I chopped down this example from a 3,600 line program so its taken a long while to isolate the offending conditions.
Added to DStress as http://dstress.kuehne.cn/norun/a/assert_10_A.d http://dstress.kuehne.cn/norun/a/assert_10_B.d http://dstress.kuehne.cn/norun/a/assert_10_C.d http://dstress.kuehne.cn/norun/a/assert_10_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCnixn3w+/yD4P9tIRAocIAJ9IdbhBdGvodwr0ZzcCsKkKjGKnEACeOamV 0JBF7QyrAOSMGjs77jmiJqY= =IuJ8 -----END PGP SIGNATURE-----
Jun 01 2005









"Walter" <newshound digitalmars.com> 