From 59a104b8039c65a59210d51e2bd54a44d283fcbb Mon Sep 17 00:00:00 2001
From: Mathieu Eyraud <[EMAIL REDACTED]>
Date: Tue, 2 Aug 2022 15:00:55 +0200
Subject: [PATCH] Do not pass NULL to memcpy
ReadJoyConControllerType calls WriteSubcommandSync with pbuf=NULL
---
src/joystick/hidapi/SDL_hidapi_switch.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 9977fac1d2d..f9f30c5fb27 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -493,7 +493,9 @@ static void ConstructSubcommand(SDL_DriverSwitch_Context *ctx, ESwitchSubcommand
SDL_memcpy(outPacket->commonData.rumbleData, ctx->m_RumblePacket.rumbleData, sizeof(ctx->m_RumblePacket.rumbleData));
outPacket->ucSubcommandID = ucCommandID;
- SDL_memcpy(outPacket->rgucSubcommandData, pBuf, ucLen);
+ if (pBuf) {
+ SDL_memcpy(outPacket->rgucSubcommandData, pBuf, ucLen);
+ }
ctx->m_nCommandNumber = (ctx->m_nCommandNumber + 1) & 0xF;
}