Вебинар: Стратегия без иллюзий: как превращать цели в результаты - 19.08
V3106. Possibly index is out of bound.
V3106 Possible negative index value. The value of 'truncationIndex' index could reach -1. ChatHistoryMaxTokensReducer.cs 75
private int ComputeTruncationIndex(
IReadOnlyList<ChatMessageContent> chatHistory,
ChatMessageContent? systemMessage)
{
var truncationIndex = -1; // <=
var totalTokenCount = (int)(systemMessage?.Metadata?["TokenCount"] ?? 0);
for (int i = chatHistory.Count - 1; i >= 0; i--) // <=
{
truncationIndex = i;
var tokenCount = (int)(chatHistory[i].Metadata?["TokenCount"] ?? 0);
if (tokenCount + totalTokenCount > this._maxTokenCount)
{
break;
}
totalTokenCount += tokenCount;
}
// Skip function related content
while (truncationIndex < chatHistory.Count) // <=
{
if (chatHistory[truncationIndex].Items.Any(i => i is FunctionCallContent
or FunctionResultContent))
{
truncationIndex++;
}
else
{
break;
}
}
return truncationIndex;
}
V3106 Possible negative index value. The value of 'deletedIndex == 0 ? 1 : deletedIndex - 1' index could reach -2. Editor.cs 1457
private void deleteDifficulty()
{
....
void delete()
{
BeatmapInfo difficultyToDelete =
playableBeatmap.BeatmapInfo;
var difficultiesBeforeDeletion =
groupedOrderedBeatmaps.SelectMany(g => g).ToList();
....
int deletedIndex = difficultiesBeforeDeletion.IndexOf(difficultyToDelete);
BeatmapInfo nextToShow =
difficultiesBeforeDeletion
[deletedIndex == 0 ? 1 : deletedIndex - 1];
Beatmap.Value = beatmapManager.GetWorkingBeatmap(nextToShow);
SwitchToDifficulty(nextToShow);
}
}
V3106 [CWE-125] Possible negative index value. The value of 'currTaskIndex - 1' index could reach -2. TaskHandler.cs 201
public void Skip()
{
....
var currTaskIndex = Task.Sequence
.TaskDefinitions
.FindIndex(def => def.ID == TaskID);
if (currTaskIndex != 0)
{
var lastTask = Task.Sequence.TaskDefinitions[currTaskIndex - 1];
....
}
....
}
V3106 The 1st argument 'AstarPath.active.data.GetGraphIndex(this)' is potentially used inside method to point beyond collection's bounds. NavMeshGenerator.cs 225
protected override IEnumerable<Progress> ScanInternal ()
{
....
TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this),
this);
....
}
public int GetGraphIndex (NavGraph graph) {
if (graph == null) throw new System.ArgumentNullException("graph");
var index = -1;
if (graphs != null) {
index = System.Array.IndexOf(graphs, graph);
if (index == -1) Debug.LogError("Graph doesn't exist");
}
return index;
}
public static void SetNavmeshHolder (int graphIndex, INavmeshHolder graph) {
// We need to lock to make sure that
// the resize operation is thread safe
lock (lockObject) {
if (graphIndex >= _navmeshHolders.Length) {
var gg = new INavmeshHolder[graphIndex+1];
_navmeshHolders.CopyTo(gg, 0);
_navmeshHolders = gg;
}
_navmeshHolders[graphIndex] = graph; // <=
}
}
V3106 Possible negative index value. The value of 'index' index could reach -1. ExpressionCompiler.cs 1977
public static bool TryEmit(....)
{
....
if ((parent & ParentFlags.InlinedLambdaInvoke) != 0)
{
var index = closure.GetLabelOrInvokeIndex(gt.Target); // <=
var invokeIndex = closure.Labels
.Items[index] // <=
.InlinedLambdaInvokeIndex;
....
}
....
}
public short GetLabelOrInvokeIndex(object labelTarget)
{
var count = Labels.Count;
var items = Labels.Items;
for (short i = 0; i < count; ++i)
if (items[i].Target == labelTarget)
return i;
return -1;
}
V3106 Possible negative index value. The value of 'paramCount' index could reach -1. ExpressionCompiler.cs 555
private static void
ReturnClosureTypeToParamTypesToPool(Type[] closurePlusParamTypes)
{
var paramCount = closurePlusParamTypes.Length - 1; // <=
if (paramCount != 0 && paramCount < 8)
Interlocked.Exchange(ref _closureTypePlusParamTypesPool[paramCount],
closurePlusParamTypes);
}
V3106 Possibly index is out of bound. The '0' index is pointing beyond 'Sprites' bound. ParticlePrefab.cs 303
public ParticlePrefab(XElement element, ContentFile file)
{
....
if (CollisionRadius <= 0.0f)
CollisionRadius = Sprites.Count > 0 ? 1 :
Sprites[0].SourceRect.Width / 2.0f;
}
V3106 Possible negative index value. The value of 'i' index could reach -1. MonoGame.Framework.DesktopGL(netstandard2.0) Cue.cs 251
public void Apply3D(AudioListener listener, AudioEmitter emitter)
{
....
var i = FindVariable("Distance");
_variables[i].SetValue(distance);
....
var j = FindVariable("OrientationAngle");
_variables[j].SetValue(angle);
....
}
V3106 Possibly index is out of bound. The '2' index is pointing beyond 'm.Arguments' bound. ExpressionVisitorBase.cs 632
protected virtual string VisitMethodCall(MethodCallExpression m)
{
....
case "SqlText":
....
if (m.Arguments.Count == 2)
{
var n1 = Visit(m.Arguments[0]);
var f = m.Arguments[2];
....
}
}
V3106 Possible negative index value. The value of 'index' index could reach -1. EFCore CompositePrincipalKeyValueFactory.cs 68
protected virtual IReadOnlyList<IProperty> Properties { get; }
....
public virtual IProperty FindNullPropertyInKeyValues(object[] keyValues)
{
var index = -1;
for (var i = 0; i < keyValues.Length; i++)
{
if (keyValues[i] == null)
{
index = i;
break;
}
}
return Properties[index];
}
V3106 Possibly index is out of bound. The '0' index is pointing beyond 'bytes' bound. Nethermind.Network ReceiptsMessageSerializer.cs 50
public ReceiptsMessage Deserialize(byte[] bytes)
{
if (bytes.Length == 0 && bytes[0] == Rlp.OfEmptySequence[0])
return new ReceiptsMessage(null);
....
}
Similar errors can be found in some other places:
V3106 Possible negative index value. The value of 'index' index could reach -1. Animator.cs 68
protected T InterpolationHandler(double animationTime, T neutralValue)
{
....
if (kvCount > 2)
{
if (animationTime <= 0.0)
{
....
}
else if (animationTime >= 1.0)
{
....
}
else
{
int index = FindClosestBeforeKeyFrame(animationTime);
firstKeyframe = _convertedKeyframes[index];
}
....
}
....
}
V3106 Possibly index is out of bound. The '0' index is pointing beyond '_tables' bound. XMLDiffLoader.cs 277
private ArrayList _tables;
private DataTable GetTable(string tableName, string ns)
{
....
if (_tables.Count == 0)
return (DataTable)_tables[0];
....
}
V3106 Possible negative index value. The value of 'idx' index could reach -1. BarcodeCodabar.cs 70
private int FindBarItem(string c)
{
for (int i = 0; i < tabelle_cb.Length; i++)
{
if (c == tabelle_cb[i].c)
return i;
}
return -1;
}
internal override string GetPattern()
{
string result = tabelle_cb[FindBarItem("A")].data + "0";
foreach (char c in text)
{
int idx = FindBarItem(c.ToString());
result += tabelle_cb[idx].data + "0";
}
result += tabelle_cb[FindBarItem("B")].data;
return result;
}
V3106 Possibly index is out of bound. The '4' index is pointing beyond 'values' bound. Matrix2x2.cs 98
public Matrix2x2(float[] values)
{
....
if (values.Length != 4)
throw new ArgumentOutOfRangeException(....);
M11 = values[0];
M12 = values[1];
M21 = values[3];
M22 = values[4]; // <=
}