From b8840801cc83eeeb8c0fd0bb7e805c44b22f35ae Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 4 Dec 2023 21:53:14 -0800 Subject: [PATCH] Fixed analyze warnings in SDL_xinputhaptic.c warning C6340: Mismatch on sign: 'int' passed as _Param_(4) when some unsigned type is required in call to 'SDL_snprintf_REAL'. warning C6340: Mismatch on sign: 'const unsigned char' passed as _Param_(4) when some signed type is required in call to 'SDL_snprintf_REAL'. warning C26451: Arithmetic overflow: Using operator '*' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '*' to avoid overflow (io.2). --- src/haptic/windows/SDL_xinputhaptic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/haptic/windows/SDL_xinputhaptic.c b/src/haptic/windows/SDL_xinputhaptic.c index b84c2eadd0..b307b31cf1 100644 --- a/src/haptic/windows/SDL_xinputhaptic.c +++ b/src/haptic/windows/SDL_xinputhaptic.c @@ -86,7 +86,7 @@ int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid) /* !!! FIXME: I'm not bothering to query for a real name right now (can we even?) */ { char buf[64]; - (void)SDL_snprintf(buf, sizeof(buf), "XInput Controller #%u", userid + 1); + (void)SDL_snprintf(buf, sizeof(buf), "XInput Controller #%d", 1 + userid); item->name = SDL_strdup(buf); } @@ -196,7 +196,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us return SDL_SetError("Couldn't create XInput haptic mutex"); } - (void)SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%d", userid); + (void)SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%u", userid); haptic->hwdata->thread = SDL_CreateThreadInternal(SDL_RunXInputHaptic, threadName, 64 * 1024, haptic->hwdata); if (!haptic->hwdata->thread) { @@ -283,7 +283,7 @@ int SDL_XINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, } else if ((!effect->effect.leftright.length) || (!iterations)) { /* do nothing. Effect runs for zero milliseconds. */ } else { - haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations); + haptic->hwdata->stopTicks = SDL_GetTicks() + ((Uint64)effect->effect.leftright.length * iterations); } SDL_UnlockMutex(haptic->hwdata->mutex); return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;