Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: bytemaster on December 02, 2013, 06:09:14 PM



Title: assert(...) with side effects
Post by: bytemaster on December 02, 2013, 06:09:14 PM
In main.cpp the following line within ConnectBlock has side effects which would be skipped if -DNDEBUG were to be defined. 

Code:
assert(view.SetBestBlock(pindex->GetBlockHash())); 

Seems to me the code should be

Code:
bool success = view.SetBestBlock(pindex->GetBlockHash());
assert(success);



Title: Re: assert(...) with side effects
Post by: gmaxwell on December 02, 2013, 07:18:42 PM
In main.cpp the following line within ConnectBlock has side effects which would be skipped if -DNDEBUG were to be defined.  
It should be, indeed, but we don't support compiling without asserts. This is a known wart. There are a couple of other similar places that ought to be fixed. I might as well go fix it.


Title: Re: assert(...) with side effects
Post by: Mike Hearn on December 02, 2013, 09:39:49 PM
It's probably better to just define a custom CHECK macro that is always active. It's better to crash the node in production than to enter an undefined state.