From 44341959e8f96d7c687a26296fa27fd4a5627d8f Mon Sep 17 00:00:00 2001 From: Po Lu Date: Thu, 2 Mar 2023 13:48:03 +0800 Subject: [PATCH] Fix Android handle wraparound * src/android.c (android_alloc_id): Return correct values upon wraparound. --- src/android.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/android.c b/src/android.c index daeb7ab70f6..1e91abffa6f 100644 --- a/src/android.c +++ b/src/android.c @@ -2825,25 +2825,32 @@ android_alloc_id (void) android_handle handle; /* 0 is never a valid handle ID. */ + if (!max_handle) max_handle++; + /* See if the handle is already occupied. */ + if (android_handles[max_handle].handle) { - handle = max_handle + 1; + /* Look for a fresh unoccupied handle. */ - while (max_handle < handle) + handle = max_handle; + max_handle++; + + while (handle != max_handle) { ++max_handle; + /* Make sure the handle is valid. */ if (!max_handle) ++max_handle; if (!android_handles[max_handle].handle) - return 0; + return max_handle++; } - return 0; + return ANDROID_NONE; } return max_handle++; -- 2.39.2