From: CryptoManiac Date: Sat, 29 Aug 2015 16:46:46 +0000 (+0300) Subject: ScriptCode: fix stack depth precondition and add preproccessor directive checking... X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=2039e10848db3f133fea8a34413166312f277aa8 ScriptCode: fix stack depth precondition and add preproccessor directive checking to prevent such issues in the future. --- diff --git a/Novacoin/Novacoin.csproj b/Novacoin/Novacoin.csproj index 2348e63..825a890 100644 --- a/Novacoin/Novacoin.csproj +++ b/Novacoin/Novacoin.csproj @@ -15,7 +15,7 @@ full false bin\Debug - DEBUG; + DEBUG;CODE_ANALYSIS; prompt 4 false diff --git a/Novacoin/ScriptCode.cs b/Novacoin/ScriptCode.cs index 458445a..1b6cbea 100644 --- a/Novacoin/ScriptCode.cs +++ b/Novacoin/ScriptCode.cs @@ -794,8 +794,8 @@ namespace Novacoin /// Byte sequence private static byte[] stacktop(ref List stack, int nDepth) { - Contract.Requires(nDepth < 0, "Positive stack depth makes no sense."); - Contract.Requires(stack.Count + nDepth > 0, "Value exceeds real stack depth."); + Contract.Requires(nDepth < 0, "Positive or zero stack depth makes no sense."); + Contract.Requires(stack.Count + nDepth >= 0, "Value exceeds real stack depth."); return stack[stack.Count + nDepth]; } @@ -866,8 +866,10 @@ namespace Novacoin var CodeQueue = script.GetByteQueue(); var altStack = new List(); +#if !DEBUG try { +#endif instruction opcode; byte[] pushArg; @@ -1703,12 +1705,14 @@ namespace Novacoin return false; } } +#if !DEBUG } catch (Exception) { // If there are any exceptions then just return false. return false; } +#endif if (vfExec.Count() != 0) {