From 44a7d20d502911a6e2562d0f973e87730fa15477 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+AtariDreams@users.noreply.github.com> Date: Sat, 28 Aug 2021 12:04:53 -0400 Subject: [PATCH] Fix undefined behavior regarding pData pData is a void pointer, and even though the address at request.pData[2] is being cast to that of a const UInt8 pointer, the request.pData has to be converted first BEFORE doing any pointer arithmetic. For this reason, it is best to write this it as a pointer sum, rather than an array. --- backend/usb-darwin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/usb-darwin.c b/backend/usb-darwin.c index 7c25905319..b17a9b382a 100644 --- a/backend/usb-darwin.c +++ b/backend/usb-darwin.c @@ -1616,14 +1616,14 @@ static CFStringRef copy_printer_interface_deviceid(printer_interface_t printer, if (actualLength > 2 && actualLength <= bufferLength - 2) { - ret = CFStringCreateWithBytes(NULL, (const UInt8 *) &request.pData[2], actualLength - 2, kCFStringEncodingUTF8, false); + ret = CFStringCreateWithBytes(NULL, (const UInt8 *)request.pData + 2, actualLength - 2, kCFStringEncodingUTF8, false); } else if (actualLength > 2) { err = sendRequest(actualLength); if (err == kIOReturnSuccess && request.wLenDone > 0) { actualLength = OSSwapBigToHostInt16(*((UInt16 *)request.pData)); - ret = CFStringCreateWithBytes(NULL, (const UInt8 *) &request.pData[2], actualLength - 2, kCFStringEncodingUTF8, false); + ret = CFStringCreateWithBytes(NULL, (const UInt8 *)request.pData + 2, actualLength - 2, kCFStringEncodingUTF8, false); } } } @@ -1817,7 +1817,7 @@ static CFStringRef copy_printer_interface_indexed_description(printer_interface_ if ((description[0] & 1) != 0) description[0] &= 0xfe; - char buffer[258] = {}; + char buffer[258] = {0}; unsigned int maxLength = sizeof buffer; if (description[0] > 1) { -- 2.47.2