Skip to content

Commit

Permalink
Fix unsigned integer overflow (#1299)
Browse files Browse the repository at this point in the history
Summary:
## Changes in this pull request

Issue fixed: #

### Checklist

- [ ] All tests pass. Demo project builds and runs.
- [ ] I added tests, an experiment, or detailed why my change isn't tested.
- [ ] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [ ] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Pull Request resolved: #1299

Reviewed By: m3rlin45

Differential Revision: D18703628

Pulled By: TimOliver

fbshipit-source-id: d347ed9c59c62ccdb73bd3abd14e289b7c06f3f6
  • Loading branch information
ke.xu authored and facebook-github-bot committed May 2, 2023
1 parent 3cd3a11 commit 164f39c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag

- Request the `UICollectionView` until just-before we update. This way if the `UICollectionView` is changed between update-queue and execution, we guarantee the update is performed on the correct view. Ship with experiment `IGListExperimentGetCollectionViewAtUpdate` from Ryan Nystrom. [Maxime Ollivier](https://github.com/maxolls) (tbd)

- Fixed unsigned integer overflow handling in `IGListBatchUpdateData` [Jason Hsu](https://github.com/tuoxie007) [(#1299)](https://github.com/Instagram/IGListKit/pull/1299)

4.0.0
-----
### Breaking Changes
Expand Down
7 changes: 5 additions & 2 deletions Source/IGListDiffKit/IGListBatchUpdateData.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ + (void)_cleanIndexPathsWithMap:(const std::unordered_map<NSInteger, IGListMoveI
indexPaths:(NSMutableArray<NSIndexPath *> *)indexPaths
deletes:(NSMutableIndexSet *)deletes
inserts:(NSMutableIndexSet *)inserts {
if (indexPaths.count == 0) {
return;
}
for (NSInteger i = indexPaths.count - 1; i >= 0; i--) {
NSIndexPath *path = indexPaths[i];
const auto it = map.find(path.section);
Expand Down Expand Up @@ -77,8 +80,8 @@ - (instancetype)initWithInsertSections:(nonnull NSIndexSet *)insertSections
// convert one of the item changes into a section delete+insert. this will fail hard and be VERY difficult to
// debug
const NSInteger moveCount = [moveSections count];
std::unordered_map<NSInteger, IGListMoveIndex*> fromMap(moveCount);
std::unordered_map<NSInteger, IGListMoveIndex*> toMap(moveCount);
std::unordered_map<NSInteger, IGListMoveIndex*> fromMap(MAX(moveCount, 1));
std::unordered_map<NSInteger, IGListMoveIndex*> toMap(MAX(moveCount, 1));
for (IGListMoveIndex *move in moveSections) {
const NSInteger from = move.from;
const NSInteger to = move.to;
Expand Down
2 changes: 1 addition & 1 deletion Source/IGListKit/Internal/IGListWorkingRangeHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ - (void)_updateWorkingRangesWithListAdapter:(IGListAdapter *)listAdapter {
}

// Build the current set of working range section controllers
_IGListWorkingRangeSectionControllerSet workingRangeSectionControllers (visibleSectionSet.size());
_IGListWorkingRangeSectionControllerSet workingRangeSectionControllers (MAX(visibleSectionSet.size(), 1));
for (NSInteger idx = start; idx < end; idx++) {
id item = [listAdapter objectAtSection:idx];
IGListSectionController *sectionController = [listAdapter sectionControllerForObject:item];
Expand Down

0 comments on commit 164f39c

Please sign in to comment.