OSDN Git Service

TweenMain.CreateCacheメソッドでTabModelの範囲外のインデックスを参照する問題を回避
authorKimura Youichi <kim.upsilon@bucyou.net>
Sun, 4 Jun 2017 09:07:17 +0000 (18:07 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sun, 4 Jun 2017 09:23:32 +0000 (18:23 +0900)
修正前のコードでは startIndex に対しては下限値、endIndex に対しては上限値
に対するチェックを行っているが、startIndex, endIndex ともに tabInfo.AllCount を
越えている場合に、endIndex のみ上限値である tabInfo.AllCount - 1 に変更される。
これにより、startIndex と endIndex の大小関係が逆転してしまうことで
ArgumentException が発生する状態となっていた。

https://osdn.net/ticket/browse.php?group_id=6526&tid=36684

OpenTween/Tween.cs

index 9577ee0..6b1192c 100644 (file)
@@ -4854,9 +4854,13 @@ namespace OpenTween
             if (tabInfo.AllCount == 0)
                 return;
 
+            // インデックスを 0...(tabInfo.AllCount - 1) の範囲内にする
+            int FilterRange(int index)
+                => Math.Max(Math.Min(index, tabInfo.AllCount - 1), 0);
+
             // キャッシュ要求(要求範囲±30を作成)
-            startIndex = Math.Max(startIndex - 30, 0);
-            endIndex = Math.Min(endIndex + 30, tabInfo.AllCount - 1);
+            startIndex = FilterRange(startIndex - 30);
+            endIndex = FilterRange(endIndex + 30);
 
             var cacheLength = endIndex - startIndex + 1;