From e646dd23b33935cd206539111828714babbeb1d8 Mon Sep 17 00:00:00 2001 From: Vance Morrison Date: Wed, 16 May 2018 18:55:41 -0700 Subject: [PATCH] Add Asserts. Fix bug found in testing. --- .../shared/System/Text/StringBuilder.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs index ac50bcb..0cac07a 100644 --- a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs @@ -573,9 +573,12 @@ namespace System.Text /// public struct ChunkEnumerable { - internal ChunkEnumerable(StringBuilder stringBuilder) { _stringBuilder = stringBuilder; } + internal ChunkEnumerable(StringBuilder stringBuilder) { + Debug.Assert(stringBuilder != null); // Because it is only called with at 'this' pointer. + _stringBuilder = stringBuilder; + } public ChunkEnumerator GetEnumerator() => new ChunkEnumerator(this._stringBuilder); - private StringBuilder _stringBuilder; + private StringBuilder _stringBuilder; // We insure this is never null. } /// @@ -604,8 +607,9 @@ namespace System.Text #region private internal ChunkEnumerator(StringBuilder stringBuilder) { + Debug.Assert(stringBuilder != null); _firstChunk = stringBuilder; - _currentChunk = null; + _currentChunk = null; // MoveNext will find the last chunk if we do this. _manyChunks = null; // There is a performance-vs-allocation tradeoff. Because the chunks @@ -647,7 +651,7 @@ namespace System.Text public ManyChunkInfo(StringBuilder stringBuilder, int chunkCount) { _chunks = new StringBuilder[chunkCount]; - while (0 < --chunkCount) + while (0 <= --chunkCount) { _chunks[chunkCount] = stringBuilder; stringBuilder = stringBuilder.m_ChunkPrevious; @@ -661,7 +665,7 @@ namespace System.Text StringBuilder _firstChunk; // The first Stringbuilder chunk (which is the end of the logical string) StringBuilder _currentChunk; // The chunk that this enumerator is currently returning (Current). ManyChunkInfo _manyChunks; // Only used for long string builders with many chunks (see constructor) - #endregion +#endregion } /// @@ -1186,7 +1190,7 @@ namespace System.Text return this; } - #region AppendJoin +#region AppendJoin public unsafe StringBuilder AppendJoin(string separator, params object[] values) { @@ -1294,7 +1298,7 @@ namespace System.Text return this; } - #endregion +#endregion public StringBuilder Insert(int index, String value) { -- 2.7.4