diff --git a/bin/mac/libnst64.dylib b/bin/mac/libnst64.dylib index 24716823755a..56cba80105e8 100755 Binary files a/bin/mac/libnst64.dylib and b/bin/mac/libnst64.dylib differ diff --git a/native/MacTouchBar/src/Scrubber.m b/native/MacTouchBar/src/Scrubber.m index b3dbc9484be6..3fd3e299cddf 100644 --- a/native/MacTouchBar/src/Scrubber.m +++ b/native/MacTouchBar/src/Scrubber.m @@ -101,7 +101,9 @@ static const int g_interItemSpacings = 5; @end -static int _fillCache(NSMutableArray * cache, NSMutableArray * visibleItems, void* items, int byteCount) { +static void _fillCache(NSMutableArray * cache, NSMutableArray * visibleItems, void* items, int byteCount) { + if (cache == NULL || visibleItems == NULL || items == NULL || byteCount <= 0) + return; const int prevCacheSize = cache.count; const int prevVisibleSize = visibleItems.count; const char * p = items; @@ -188,6 +190,9 @@ void appendScrubberItems(id scrubObj, void* packedItems, int byteCount) { // NOTE: called from EDT (when update UI) void enableScrubberItems(id scrubObj, void* itemIndices, int count, bool enabled) { + if (itemIndices == NULL || count <= 0) + return; + NSScrubberContainer *container = scrubObj; NSScrubber *scrubber = container.view; const int sizeInBytes = sizeof(int)*count; @@ -220,6 +225,9 @@ void enableScrubberItems(id scrubObj, void* itemIndices, int count, bool enabled // NOTE: called from EDT (when update UI) void showScrubberItems(id scrubObj, void* itemIndices, int count, bool show) { + if (itemIndices == NULL || count <= 0) + return; + NSScrubberContainer * container = scrubObj; NSScrubber *scrubber = container.view; diff --git a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/NST.java b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/NST.java index 800d3f815df5..d838548948f1 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/NST.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/NST.java @@ -145,7 +145,7 @@ public class NST { public static ID createScrubber(String uid, int itemWidth, NSTLibrary.ScrubberDelegate delegate, NSTLibrary.ScrubberCacheUpdater updater, List items, int itemsCount) { final Memory mem = _packItems(items, 0, itemsCount); - final ID scrubberNativePeer = ourNSTLibrary.createScrubber(uid, itemWidth, delegate, updater, mem, (int)mem.size()); // called from AppKit, uses per-event autorelease-pool + final ID scrubberNativePeer = ourNSTLibrary.createScrubber(uid, itemWidth, delegate, updater, mem, mem == null ? 0 : (int)mem.size()); // called from AppKit, uses per-event autorelease-pool return scrubberNativePeer; } @@ -206,7 +206,7 @@ public class NST { static void appendScrubberItems(ID scrubObj, List items, int fromIndex, int itemsCount) { final Memory mem = _packItems(items, fromIndex, itemsCount); - ourNSTLibrary.appendScrubberItems(scrubObj, mem, (int)mem.size()); // called from AppKit, uses per-event autorelease-pool + ourNSTLibrary.appendScrubberItems(scrubObj, mem, mem == null ? 0 : (int)mem.size()); // called from AppKit, uses per-event autorelease-pool } public static void enableScrubberItem(ID scrubObj, Collection indices, boolean enabled) { if (indices == null || indices.isEmpty()) @@ -222,8 +222,16 @@ public class NST { } private static @Nullable Memory _packItems(List items, int fromIndex, int itemsCount) { - if (items == null) + if (items == null || itemsCount <= 0) return null; + if (fromIndex < 0) { + LOG.error("_packItems: fromIndex < 0 (" + fromIndex + ")"); + return null; + } + if (fromIndex + itemsCount > items.size()) { + LOG.error("_packItems: fromIndex + itemsCount > items.size() (" + fromIndex + ", " + itemsCount + ", " + items.size() + ")"); + return null; + } // 1. calculate size int byteCount = 4;