From 0bd77a5b93494ca88bfd1a86fe106e7bb1d90133 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 30 Mar 2023 14:02:04 -0700
Subject: [PATCH] Fixed Visual Studio warning 4389
---
src/audio/SDL_audio.c | 10 +++++-----
src/audio/directsound/SDL_directsound.c | 2 +-
src/audio/wasapi/SDL_wasapi.c | 2 +-
src/joystick/SDL_gamepad.c | 7 ++++---
src/libm/e_pow.c | 2 +-
src/libm/e_sqrt.c | 2 +-
src/render/direct3d11/SDL_render_d3d11.c | 2 +-
src/render/opengles2/SDL_render_gles2.c | 2 +-
src/stdlib/SDL_string.c | 2 +-
src/video/SDL_video.c | 2 +-
src/video/windows/SDL_windowskeyboard.c | 2 +-
src/video/yuv2rgb/yuv_rgb_sse_func.h | 2 +-
12 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 8c5b5d4f0935..f7c3ec81b30c 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -666,7 +666,7 @@ static int SDLCALL SDL_RunAudio(void *devicep)
/* Fill the current buffer with sound */
if (!device->stream && SDL_AtomicGet(&device->enabled)) {
- SDL_assert(data_len == device->spec.size);
+ SDL_assert((Uint32)data_len == device->spec.size);
data = current_audio.impl.GetDeviceBuf(device);
} else {
/* if the device isn't enabled, we still write to the
@@ -700,13 +700,13 @@ static int SDLCALL SDL_RunAudio(void *devicep)
int got;
data = SDL_AtomicGet(&device->enabled) ? current_audio.impl.GetDeviceBuf(device) : NULL;
got = SDL_GetAudioStreamData(device->stream, data ? data : device->work_buffer, device->spec.size);
- SDL_assert((got <= 0) || (got == device->spec.size));
+ SDL_assert((got <= 0) || ((Uint32)got == device->spec.size));
if (data == NULL) { /* device is having issues... */
const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq);
SDL_Delay(delay); /* wait for as long as this buffer would have played. Maybe device recovers later? */
} else {
- if (got != device->spec.size) {
+ if ((Uint32)got != device->spec.size) {
SDL_memset(data, device->spec.silence, device->spec.size);
}
current_audio.impl.PlayDevice(device);
@@ -814,8 +814,8 @@ static int SDLCALL SDL_CaptureAudio(void *devicep)
while (SDL_GetAudioStreamAvailable(device->stream) >= ((int)device->callbackspec.size)) {
const int got = SDL_GetAudioStreamData(device->stream, device->work_buffer, device->callbackspec.size);
- SDL_assert((got < 0) || (got == device->callbackspec.size));
- if (got != device->callbackspec.size) {
+ SDL_assert((got < 0) || ((Uint32)got == device->callbackspec.size));
+ if ((Uint32)got != device->callbackspec.size) {
SDL_memset(device->work_buffer, device->spec.silence, device->callbackspec.size);
}
diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c
index b1ce62a4517b..39e3f334f5f5 100644
--- a/src/audio/directsound/SDL_directsound.c
+++ b/src/audio/directsound/SDL_directsound.c
@@ -328,7 +328,7 @@ static int DSOUND_CaptureFromDevice(_THIS, void *buffer, int buflen)
DWORD junk, cursor, ptr1len, ptr2len;
VOID *ptr1, *ptr2;
- SDL_assert(buflen == this->spec.size);
+ SDL_assert((Uint32)buflen == this->spec.size);
while (SDL_TRUE) {
if (SDL_AtomicGet(&this->shutdown)) { /* in case the buffer froze... */
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index 5de499dd48f8..56da8fb7d355 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -448,7 +448,7 @@ int WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
this->spec.freq = waveformat->nSamplesPerSec; /* force sampling rate so our resampler kicks in, if necessary. */
#else
/* favor WASAPI's resampler over our own */
- if (this->spec.freq != waveformat->nSamplesPerSec) {
+ if ((DWORD)this->spec.freq != waveformat->nSamplesPerSec) {
streamflags |= (AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY);
waveformat->nSamplesPerSec = this->spec.freq;
waveformat->nAvgBytesPerSec = waveformat->nSamplesPerSec * waveformat->nChannels * (waveformat->wBitsPerSample / 8);
diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c
index 26f5f674694b..b14c5bf31bd8 100644
--- a/src/joystick/SDL_gamepad.c
+++ b/src/joystick/SDL_gamepad.c
@@ -1472,14 +1472,15 @@ int SDL_AddGamepadMappingsFromRW(SDL_RWops *rw, int freerw)
const char *platform = SDL_GetPlatform();
int gamepads = 0;
char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
- size_t db_size, platform_len;
+ Sint64 db_size;
+ size_t platform_len;
if (rw == NULL) {
return SDL_SetError("Invalid RWops");
}
- db_size = (size_t)SDL_RWsize(rw);
+ db_size = SDL_RWsize(rw);
- buf = (char *)SDL_malloc(db_size + 1);
+ buf = (char *)SDL_malloc((size_t)db_size + 1);
if (buf == NULL) {
if (freerw) {
SDL_RWclose(rw);
diff --git a/src/libm/e_pow.c b/src/libm/e_pow.c
index 8acb1f5ff7bc..d1a141ec4be7 100644
--- a/src/libm/e_pow.c
+++ b/src/libm/e_pow.c
@@ -139,7 +139,7 @@ double attribute_hidden __ieee754_pow(double x, double y)
k = (iy>>20)-0x3ff; /* exponent */
if(k>20) {
j = ly>>(52-k);
- if((j<<(52-k))==ly) yisint = 2-(j&1);
+ if(((u_int32_t)j<<(52-k))==ly) yisint = 2-(j&1);
} else if(ly==0) {
j = iy>>(20-k);
if((j<<(20-k))==iy) yisint = 2-(j&1);
diff --git a/src/libm/e_sqrt.c b/src/libm/e_sqrt.c
index 7d96e512cd64..8ac58c62ac55 100644
--- a/src/libm/e_sqrt.c
+++ b/src/libm/e_sqrt.c
@@ -149,7 +149,7 @@ double attribute_hidden __ieee754_sqrt(double x)
t = s0;
if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
s1 = t1+r;
- if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1;
+ if(((t1&sign)==(u_int32_t)sign)&&(s1&sign)==0) s0 += 1;
ix0 -= t;
if (ix1 < t1) ix0 -= 1;
ix1 -= t1;
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index bda56f00e9d7..e38b220c2f21 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -1290,7 +1290,7 @@ static int D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Tex
src = (const Uint8 *)pixels;
dst = textureMemory.pData;
length = w * bpp;
- if (length == pitch && length == textureMemory.RowPitch) {
+ if (length == (UINT)pitch && length == textureMemory.RowPitch) {
SDL_memcpy(dst, src, (size_t)length * h);
} else {
if (length > (UINT)pitch) {
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index f00f2e9443ea..010fc8a898f5 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -1579,7 +1579,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff
/* Reformat the texture data into a tightly packed array */
src_pitch = (size_t)width * bpp;
src = (Uint8 *)pixels;
- if (pitch != src_pitch) {
+ if ((size_t)pitch != src_pitch) {
blob = (Uint8 *)SDL_malloc(src_pitch * height);
if (blob == NULL) {
return SDL_OutOfMemory();
diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c
index 6b838714579e..1229c3798a57 100644
--- a/src/stdlib/SDL_string.c
+++ b/src/stdlib/SDL_string.c
@@ -576,7 +576,7 @@ SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_
c = (unsigned char)src[i];
trailing_bytes = UTF8_GetTrailingBytes(c);
if (trailing_bytes) {
- if (bytes - i != trailing_bytes + 1) {
+ if ((bytes - i) != ((size_t)trailing_bytes + 1)) {
bytes = i;
}
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index c9293aad6974..ff64586510dc 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -4698,7 +4698,7 @@ static SDL_bool SDL_IsMessageboxValidForDriver(const SDL_MessageBoxData *message
if (window == NULL || SDL_GetWindowWMInfo(window, &info, SDL_SYSWM_CURRENT_VERSION) < 0) {
return SDL_TRUE;
} else {
- return info.subsystem == drivertype;
+ return info.subsystem == (Uint32)drivertype;
}
}
#endif
diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index 989a0a83916d..65b1e07426f7 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -1673,7 +1673,7 @@ static void IME_RenderCandidateList(SDL_VideoData *videodata, HDC hdc)
bottom = size.cy - listborder - listpadding - candmargin;
}
- if (i == videodata->ime_candsel) {
+ if ((DWORD)i == videodata->ime_candsel) {
SelectObject(hdc, selpen);
SelectObject(hdc, selbrush);
SetTextColor(hdc, seltextcolor);
diff --git a/src/video/yuv2rgb/yuv_rgb_sse_func.h b/src/video/yuv2rgb/yuv_rgb_sse_func.h
index a3c15f2585ef..5d1ea3bccd38 100644
--- a/src/video/yuv2rgb/yuv_rgb_sse_func.h
+++ b/src/video/yuv2rgb/yuv_rgb_sse_func.h
@@ -491,7 +491,7 @@ void SDL_TARGETING("sse2") SSE_FUNCTION_NAME(uint32_t width, uint32_t height,
/* Catch the right column, if needed */
{
- int converted = (width & ~31);
+ uint32_t converted = (width & ~31);
if (fix_read_nv12) {
converted -= 32;
}