From 32a25db6683f652ec4953d2e3f27f1a8e21384d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=A5=D0=B0=D1=80=D1=8C?= =?utf8?q?=D0=BA=D0=BE=D0=B2?= <48874697+PabloKharo@users.noreply.github.com> Date: Sat, 12 Aug 2023 18:58:33 +0300 Subject: [PATCH] runtime: fix variable null check (#89920) Fixed error when _hashtableContentsToEnumerate is null. It appears always when using 'Length' property when variable is null. Also reduced nesting. --- .../Utilities/LockFreeReaderHashtable.cs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/coreclr/tools/Common/TypeSystem/Common/Utilities/LockFreeReaderHashtable.cs b/src/coreclr/tools/Common/TypeSystem/Common/Utilities/LockFreeReaderHashtable.cs index 44be986803b..613ec30fa01 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/Utilities/LockFreeReaderHashtable.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/Utilities/LockFreeReaderHashtable.cs @@ -689,27 +689,24 @@ namespace Internal.TypeSystem public bool MoveNext() { - if (_sentinel != null) + if ((_sentinel != null) && (_hashtableContentsToEnumerate != null)) { - if ((_hashtableContentsToEnumerate != null) && (_index < _hashtableContentsToEnumerate.Length)) + for (; _index < _hashtableContentsToEnumerate.Length; _index++) { - for (; _index < _hashtableContentsToEnumerate.Length; _index++) + if ((_hashtableContentsToEnumerate[_index] != null) && (_hashtableContentsToEnumerate[_index] != _sentinel)) { - if ((_hashtableContentsToEnumerate[_index] != null) && (_hashtableContentsToEnumerate[_index] != _sentinel)) - { - _current = _hashtableContentsToEnumerate[_index]; - _index++; - return true; - } + _current = _hashtableContentsToEnumerate[_index]; + _index++; + return true; } } - } - if ((_index == _hashtableContentsToEnumerate.Length) && _sentinel != null) - { - _current = _sentinel; - _index++; - return true; + if (_index == _hashtableContentsToEnumerate.Length) + { + _current = _sentinel; + _index++; + return true; + } } _current = default(TValue); -- 2.34.1