From 5ee22079822ef30d05366d58173b09e238b6e44b Mon Sep 17 00:00:00 2001 From: Yiding Wen Date: Wed, 11 Sep 2024 13:14:20 -0700 Subject: [PATCH] Return nil to avoid crash Summary: Logiview: https://www.internalfb.com/logview/instagram_ios_crashes/2ece21699d74d3187e8480e2ec0dce14?trace_tab=0&ds=%7B%22start%22%3A%22-1%20day%22%2C%22end%22%3A%22now%22%7D This crash happens at line 297 in this file, when the `indexPath` is `nil` early return when `indexPath == nil` to avoid the crash Differential Revision: D62513388 fbshipit-source-id: 91aef1ab0474563bf639abb1debf9ca1477e64ed --- Source/IGListKit/IGListCollectionViewLayout.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/IGListKit/IGListCollectionViewLayout.mm b/Source/IGListKit/IGListCollectionViewLayout.mm index c8dacbc44..16266780e 100644 --- a/Source/IGListKit/IGListCollectionViewLayout.mm +++ b/Source/IGListKit/IGListCollectionViewLayout.mm @@ -279,6 +279,10 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSInde return attributes; } + if (indexPath == nil) { + return nil; + } + // avoid OOB errors const NSInteger section = indexPath.section; const NSInteger item = indexPath.item; @@ -474,7 +478,7 @@ - (NSString *)_classNameForDelegate:(id)dele - (void)_calculateLayoutIfNeeded { if (_minimumInvalidatedSection == NSNotFound) { return; - } + } UICollectionView *collectionView = self.collectionView; id delegate = (id)collectionView.delegate;