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).
This commit is contained in:
Sam Lantinga 2023-12-04 21:53:14 -08:00
parent 8e0d728c67
commit b8840801cc

View file

@ -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?) */ /* !!! FIXME: I'm not bothering to query for a real name right now (can we even?) */
{ {
char buf[64]; 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); 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"); 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); haptic->hwdata->thread = SDL_CreateThreadInternal(SDL_RunXInputHaptic, threadName, 64 * 1024, haptic->hwdata);
if (!haptic->hwdata->thread) { 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)) { } else if ((!effect->effect.leftright.length) || (!iterations)) {
/* do nothing. Effect runs for zero milliseconds. */ /* do nothing. Effect runs for zero milliseconds. */
} else { } 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); SDL_UnlockMutex(haptic->hwdata->mutex);
return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1; return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;