From 389ffab733b9e875125313e68ad66be9734223ed Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 16 Nov 2022 12:53:48 -0500
Subject: [PATCH] Code style fixes, etc.
Reference PR #6345.
---
src/SDL.c | 25 +++++++++++++------------
src/joystick/hidapi/SDL_hidapi_shield.c | 3 ++-
src/video/SDL_yuv.c | 4 +++-
src/video/windows/SDL_windowskeyboard.c | 3 +--
src/video/windows/SDL_windowswindow.c | 21 +++++++++++++--------
5 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/src/SDL.c b/src/SDL.c
index 42ebc2cfc016..6297159e4219 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -124,18 +124,19 @@ static Uint8 SDL_SubsystemRefCount[ 32 ];
static void
SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
{
- int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
- SDL_assert(subsystem_index < 0 || SDL_SubsystemRefCount[subsystem_index] < 255);
- if (subsystem_index >= 0)
+ const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
+ SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
+ if (subsystem_index >= 0) {
++SDL_SubsystemRefCount[subsystem_index];
+ }
}
/* Private helper to decrement a subsystem's ref counter. */
static void
SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
{
- int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
- if (subsystem_index >= 0 && SDL_SubsystemRefCount[subsystem_index] > 0) {
+ const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
+ if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] > 0)) {
--SDL_SubsystemRefCount[subsystem_index];
}
}
@@ -144,23 +145,23 @@ SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
static SDL_bool
SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
{
- int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
- SDL_assert(subsystem_index < 0 || SDL_SubsystemRefCount[subsystem_index] < 255);
- return (subsystem_index >= 0 && SDL_SubsystemRefCount[subsystem_index] == 0) ? SDL_TRUE : SDL_FALSE;
+ const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
+ SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
+ return ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) ? SDL_TRUE : SDL_FALSE;
}
/* Private helper to check if a system needs to be quit. */
static SDL_bool
SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
- int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
- if (subsystem_index >= 0 && SDL_SubsystemRefCount[subsystem_index] == 0) {
- return SDL_FALSE;
+ const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
+ if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) {
+ return SDL_FALSE;
}
/* If we're in SDL_Quit, we shut down every subsystem, even if refcount
* isn't zero.
*/
- return ((subsystem_index >= 0 && SDL_SubsystemRefCount[subsystem_index] == 1) || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
+ return (((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 1)) || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
}
void
diff --git a/src/joystick/hidapi/SDL_hidapi_shield.c b/src/joystick/hidapi/SDL_hidapi_shield.c
index 557ca45aba50..4fe00901c3c2 100644
--- a/src/joystick/hidapi/SDL_hidapi_shield.c
+++ b/src/joystick/hidapi/SDL_hidapi_shield.c
@@ -169,8 +169,9 @@ HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd, const void
}
/* Zero unused data in the payload */
- if (size != sizeof(cmd_pkt.payload))
+ if (size != sizeof(cmd_pkt.payload)) {
SDL_memset(&cmd_pkt.payload[size], 0, sizeof(cmd_pkt.payload) - size);
+ }
if (SDL_HIDAPI_SendRumbleAndUnlock(device, (Uint8*)&cmd_pkt, sizeof(cmd_pkt)) != sizeof(cmd_pkt)) {
return SDL_SetError("Couldn't send command packet");
diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c
index b163216b955e..38cf9e733e4f 100644
--- a/src/video/SDL_yuv.c
+++ b/src/video/SDL_yuv.c
@@ -603,8 +603,10 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr
if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v,
- &y_stride, &uv_stride) != 0)
+ &y_stride, &uv_stride) != 0) {
return -1;
+ }
+
plane_interleaved_uv = (plane_y + height * y_stride);
y_skip = (y_stride - width);
diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index 3a9988deb627..83a939d64e4b 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -398,8 +398,7 @@ IME_Init(SDL_VideoData *videodata, HWND hwnd)
if (SUCCEEDED(WIN_CoInitialize())) {
videodata->ime_com_initialized = SDL_TRUE;
hResult = CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (LPVOID *)&videodata->ime_threadmgr);
- if (hResult != S_OK)
- {
+ if (hResult != S_OK) {
videodata->ime_available = SDL_FALSE;
SDL_SetError("CoCreateInstance() failed, HRESULT is %08X", (unsigned int)hResult);
return;
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index d74f1dda7968..d260f15c6001 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -739,18 +739,22 @@ WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *b
/* rcClient stores the size of the inner window, while rcWindow stores the outer size relative to the top-left
* screen position; so the top/left values of rcClient are always {0,0} and bottom/right are {height,width} */
- if (!GetClientRect(hwnd, &rcClient))
- SDL_SetError("GetClientRect() failed, error %08X", (unsigned int)GetLastError());
- if (!GetWindowRect(hwnd, &rcWindow))
- SDL_SetError("GetWindowRect() failed, error %08X", (unsigned int)GetLastError());
+ if (!GetClientRect(hwnd, &rcClient)) {
+ return SDL_SetError("GetClientRect() failed, error %08X", (unsigned int)GetLastError());
+ }
+
+ if (!GetWindowRect(hwnd, &rcWindow)) {
+ return SDL_SetError("GetWindowRect() failed, error %08X", (unsigned int)GetLastError());
+ }
/* convert the top/left values to make them relative to
* the window; they will end up being slightly negative */
ptDiff.y = rcWindow.top;
ptDiff.x = rcWindow.left;
- if (!ScreenToClient(hwnd, &ptDiff))
- SDL_SetError("ScreenToClient() failed, error %08X", (unsigned int)GetLastError());
+ if (!ScreenToClient(hwnd, &ptDiff)) {
+ return SDL_SetError("ScreenToClient() failed, error %08X", (unsigned int)GetLastError());
+ }
rcWindow.top = ptDiff.y;
rcWindow.left = ptDiff.x;
@@ -760,8 +764,9 @@ WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *b
ptDiff.y = rcWindow.bottom;
ptDiff.x = rcWindow.right;
- if (!ScreenToClient(hwnd, &ptDiff))
- SDL_SetError("ScreenToClient() failed, error %08X", (unsigned int)GetLastError());
+ if (!ScreenToClient(hwnd, &ptDiff)) {
+ return SDL_SetError("ScreenToClient() failed, error %08X", (unsigned int)GetLastError());
+ }
rcWindow.bottom = ptDiff.y;
rcWindow.right = ptDiff.x;