OSDN Git Service

Partial: Sanitize assert usage and refuse to compile with NDEBUG.
authormonacoinproject <monacoinproject@gmail.com>
Sun, 6 Apr 2014 15:06:25 +0000 (00:06 +0900)
committermonacoinproject <monacoinproject@gmail.com>
Sun, 6 Apr 2014 15:06:25 +0000 (00:06 +0900)
There were quite a few places where assert() was used with side effects,
making operation with NDEBUG non-functional.  This commit fixes all the
cases I know about, but also adds an  #error on NDEBUG because the code
is untested without assertions and may still have vulnerabilities if
used without assert.

Conflicts:
src/key.cpp
src/main.cpp
src/wallet.cpp

src/main.cpp

index cea4fdf..09a4954 100644 (file)
 using namespace std;
 using namespace boost;
 
+#if defined(NDEBUG)
+# error "Litecoin cannot be compiled without assertions."
+#endif
+
 //
 // Global state
 //
@@ -1436,12 +1440,14 @@ unsigned int CTransaction::GetP2SHSigOpCount(CCoinsViewCache& inputs) const
 
 void CTransaction::UpdateCoins(CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, const uint256 &txhash) const
 {
+    bool ret;
     // mark inputs spent
     if (!IsCoinBase()) {
         BOOST_FOREACH(const CTxIn &txin, vin) {
             CCoins &coins = inputs.GetCoins(txin.prevout.hash);
             CTxInUndo undo;
-            assert(coins.Spend(txin.prevout, undo));
+            ret = coins.Spend(txin.prevout, undo);
+            assert(ret);
             txundo.vprevout.push_back(undo);
         }
     }