Skip to content

Commit 5a6dfc4

Browse files
committed
Do not call WaitForMultipleObjects with 0 as first parameter
1 parent e8966dc commit 5a6dfc4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/refresh/win32/Win32Monitor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ protected long[][] createHandleArrays() {
431431
Set<Long> keys = fHandleValueToHandle.keySet();
432432
int size = keys.size();
433433
if (size == 0) {
434+
// This is dangerous: the documentation of WaitForMultipleObjects says that the
435+
// number of object handles cannot be zero and returning empty arrays will end
436+
// up passing zero as the 1st parameter to WaitForMultipleObjects. Therefore one
437+
// needs to make sure to check for this case when calling
438+
// Win32Natives.WaitForMultipleObjects(int, ...)
434439
return new long[0][0];
435440
}
436441
handles = new long[size];
@@ -607,6 +612,11 @@ public void unmonitor(IResource resource) {
607612
*/
608613
private void waitForNotification(long[] handleValues) {
609614
int handleCount = handleValues.length;
615+
if (handleCount == 0) {
616+
// According to the documentation of WaitForMultipleObjects,
617+
// nCount (the 1st parameter) cannot be zero
618+
return;
619+
}
610620
int index = Win32Natives.WaitForMultipleObjects(handleCount, handleValues, false, WAIT_FOR_MULTIPLE_OBJECTS_TIMEOUT);
611621
if (index == Win32Natives.WAIT_TIMEOUT) {
612622
// nothing happened.

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/refresh/win32/Win32Natives.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static boolean FindNextChangeNotification(long hChangeHandle) {
193193
* <li>All of the objects are signaled, when bWaitAll is <code>true</code></li>
194194
* <li>The timeout interval of dwMilliseconds elapses.</li>
195195
* </ul>
196-
* @param nCount The number of handles, cannot be greater than MAXIMUM_WAIT_OBJECTS.
196+
* @param nCount The number of handles, cannot be zero and cannot be greater than MAXIMUM_WAIT_OBJECTS.
197197
* @param lpHandles The array of handles to objects to be waited upon cannot contain
198198
* duplicate handles.
199199
* @param bWaitAll If <code>true</code> requires all objects to be signaled before this

0 commit comments

Comments
 (0)