087af1
From b9c5e3668c4022b34734ac8ccb07dd044d4ff38c Mon Sep 17 00:00:00 2001
087af1
From: akallabeth <akallabeth@posteo.net>
087af1
Date: Thu, 13 Oct 2022 08:27:41 +0200
087af1
Subject: [PATCH] Fixed division by zero in urbdrc
087af1
087af1
(cherry picked from commit 731f8419d04b481d7160de1f34062d630ed48765)
087af1
---
087af1
 channels/urbdrc/client/libusb/libusb_udevice.c | 12 +++++++++---
087af1
 1 file changed, 9 insertions(+), 3 deletions(-)
087af1
087af1
diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c
087af1
index aa69890ae..5784d9fe2 100644
087af1
--- a/channels/urbdrc/client/libusb/libusb_udevice.c
087af1
+++ b/channels/urbdrc/client/libusb/libusb_udevice.c
087af1
@@ -1149,12 +1149,18 @@ static int libusb_udev_isoch_transfer(IUDEVICE* idev, URBDRC_CHANNEL_CALLBACK* c
087af1
 	else
087af1
 		Stream_Seek(user_data->data, (NumberOfPackets * 12));
087af1
 
087af1
-	iso_packet_size = BufferSize / NumberOfPackets;
087af1
-	iso_transfer = libusb_alloc_transfer(NumberOfPackets);
087af1
+	if (NumberOfPackets > 0)
087af1
+	{
087af1
+		iso_packet_size = BufferSize / NumberOfPackets;
087af1
+		iso_transfer = libusb_alloc_transfer((int)NumberOfPackets);
087af1
+	}
087af1
 
087af1
 	if (iso_transfer == NULL)
087af1
 	{
087af1
-		WLog_Print(urbdrc->log, WLOG_ERROR, "Error: libusb_alloc_transfer.");
087af1
+		WLog_Print(urbdrc->log, WLOG_ERROR,
087af1
+		           "Error: libusb_alloc_transfer [NumberOfPackets=%" PRIu32 ", BufferSize=%" PRIu32
087af1
+		           " ]",
087af1
+		           NumberOfPackets, BufferSize);
087af1
 		async_transfer_user_data_free(user_data);
087af1
 		return -1;
087af1
 	}
087af1
-- 
087af1
2.37.1
087af1