Repository: dotnet/runtime
File: src/coreclr/tools/aot/ILCompiler.RyuJit/Compiler/DependencyAnalysis/MethodCodeNode.cs (C#)

Code before:
        {
            _nonRelocationDependencies = dependencies;
        }

        public IEnumerable<NativeSequencePoint> GetNativeSequencePoints()
        {
            // This can be null if we're not generating debug info
            if (_debugLocInfos == null)
                yield break;

            var sequencePoints = new (string Document, int LineNumber)[_debugLocInfos.Length * 4 /* chosen empirically */];
            try
            {
                foreach (var sequencePoint in _debugInfo.GetSequencePoints())
                {
                    int offset = sequencePoint.Offset;
                    if (offset >= sequencePoints.Length)
                    {
                        int newLength = Math.Max(2 * sequencePoints.Length, sequencePoint.Offset + 1);
                        Array.Resize(ref sequencePoints, newLength);
                    }
                    sequencePoints[offset] = (sequencePoint.Document, sequencePoint.LineNumber);
                }

                // Propagate last known document/line number forward to enable correct mapping when IL offsets decrease at higher native offsets
                for (int i = 1; i < sequencePoints.Length; i++)
                {
                    if (sequencePoints[i].Document == null && sequencePoints[i - 1].Document != null)
                    {
                        sequencePoints[i] = (sequencePoints[i - 1].Document, sequencePoints[i - 1].LineNumber);
                    }
                }
            }
            catch (BadImageFormatException)
            {
                // Roslyn had a bug where it was generating bad sequence points:
                // https://github.com/dotnet/roslyn/issues/20118
                // Do not crash the compiler.
                yield break;
            }

            int previousNativeOffset = -1;
            string previousDocument = null;
            int previousLineNumber = -1;
            // OffsetMapping is sorted in order of increasing native offset (but not necessarily by IL offset)
            foreach (var nativeMapping in _debugLocInfos)
            {
                // Make sure we don't emit multiple sequence points for the same native offset
                // Because CreateLineNumbersBlob uses zero deltas to indicate document changes.
                if (nativeMapping.NativeOffset == previousNativeOffset)
                    continue;

Review comment (bug):
The loop now iterates to `sequencePoints.Length`, which may include uninitialized entries beyond the actual sequence points. This could propagate incorrect null values. Consider iterating only to the last known sequence point offset, or tracking the maximum offset explicitly.

Code after:
        {
            _nonRelocationDependencies = dependencies;
        }

        public IEnumerable<NativeSequencePoint> GetNativeSequencePoints()
        {
            // This can be null if we're not generating debug info
            if (_debugLocInfos == null)
                yield break;

            var sequencePoints = new (string Document, int LineNumber)[_debugLocInfos.Length * 4 /* chosen empirically */];
            try
            {
                foreach (var sequencePoint in _debugInfo.GetSequencePoints())
                {
                    int offset = sequencePoint.Offset;
                    if (offset >= sequencePoints.Length)
                    {
                        int newLength = Math.Max(2 * sequencePoints.Length, sequencePoint.Offset + 1);
                        Array.Resize(ref sequencePoints, newLength);
                    }
                    sequencePoints[offset] = (sequencePoint.Document, sequencePoint.LineNumber);
                }

                // Propagate last known document/line number forward to enable correct mapping when IL offsets decrease at higher native offsets
                for (int i = 1; i < sequencePoints.Length; i++)
                {
                    if (sequencePoints[i].Document == null && sequencePoints[i - 1].Document != null)
                    {
                        sequencePoints[i] = (sequencePoints[i - 1].Document, sequencePoints[i - 1].LineNumber);
                    }
                }
            }
            catch (BadImageFormatException)
            {
                // Roslyn had a bug where it was generating bad sequence points:
                // https://github.com/dotnet/roslyn/issues/20118
                // Do not crash the compiler.
                yield break;
            }

            int previousNativeOffset = -1;
            string previousDocument = null;
            int previousLineNumber = -1;
            // OffsetMapping is sorted in order of increasing native offset (but not necessarily by IL offset)
            foreach (var nativeMapping in _debugLocInfos)
            {
                if (nativeMapping.NativeOffset == previousNativeOffset)
                    continue;

                var sequencePoint = sequencePoints[Math.Min(nativeMapping.ILOffset, sequencePoints.Length - 1)];