瀏覽代碼

Cleanup add brace (#6545)

* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line
Sylvain Becker 2 年之前
父節點
當前提交
6a2200823c
共有 100 個文件被更改,包括 1251 次插入1101 次删除
  1. 7 6
      VisualC-GDK/tests/testgdk/src/testgdk.cpp
  2. 2 2
      Xcode-iOS/Demos/src/accelerometer.c
  3. 16 9
      Xcode-iOS/Demos/src/fireworks.c
  4. 1 1
      Xcode-iOS/Demos/src/happy.c
  5. 2 2
      Xcode-iOS/Demos/src/keyboard.c
  6. 2 2
      Xcode-iOS/Demos/src/mixer.c
  7. 2 2
      Xcode-iOS/Demos/src/rectangles.c
  8. 1 1
      Xcode-iOS/Demos/src/touch.c
  9. 10 11
      src/SDL.c
  10. 1 4
      src/SDL_assert.c
  11. 11 11
      src/SDL_dataqueue.c
  12. 3 3
      src/SDL_guid.c
  13. 9 9
      src/SDL_hints.c
  14. 6 4
      src/SDL_log.c
  15. 14 14
      src/atomic/SDL_atomic.c
  16. 11 11
      src/atomic/SDL_spinlock.c
  17. 3 5
      src/audio/SDL_audio.c
  18. 22 20
      src/audio/SDL_audiocvt.c
  19. 2 1
      src/audio/SDL_audiodev.c
  20. 9 5
      src/audio/SDL_wave.c
  21. 1 1
      src/audio/aaudio/SDL_aaudio.c
  22. 32 37
      src/audio/alsa/SDL_alsa_audio.c
  23. 6 8
      src/audio/android/SDL_androidaudio.c
  24. 3 3
      src/audio/directsound/SDL_directsound.c
  25. 1 1
      src/audio/disk/SDL_diskaudio.c
  26. 6 5
      src/audio/dsp/SDL_dspaudio.c
  27. 1 1
      src/audio/emscripten/SDL_emscriptenaudio.c
  28. 1 1
      src/audio/jack/SDL_jackaudio.c
  29. 1 1
      src/audio/netbsd/SDL_netbsdaudio.c
  30. 2 2
      src/audio/openslES/SDL_openslES.c
  31. 5 5
      src/audio/pipewire/SDL_pipewire.c
  32. 2 1
      src/audio/ps2/SDL_ps2audio.c
  33. 2 2
      src/audio/psp/SDL_pspaudio.c
  34. 4 10
      src/audio/pulseaudio/SDL_pulseaudio.c
  35. 2 2
      src/audio/vita/SDL_vitaaudio.c
  36. 2 3
      src/audio/wasapi/SDL_wasapi_winrt.cpp
  37. 11 16
      src/core/android/SDL_android.c
  38. 66 45
      src/core/freebsd/SDL_evdev_kbd_freebsd.c
  39. 2 2
      src/core/gdk/SDL_gdk.cpp
  40. 15 10
      src/core/linux/SDL_dbus.c
  41. 50 30
      src/core/linux/SDL_evdev.c
  42. 2 1
      src/core/linux/SDL_evdev_capabilities.c
  43. 39 25
      src/core/linux/SDL_evdev_kbd.c
  44. 25 9
      src/core/linux/SDL_fcitx.c
  45. 48 25
      src/core/linux/SDL_ibus.c
  46. 17 10
      src/core/linux/SDL_ime.c
  47. 22 24
      src/core/linux/SDL_threadprio.c
  48. 5 6
      src/core/linux/SDL_udev.c
  49. 110 45
      src/core/openbsd/SDL_wscons_kbd.c
  50. 8 6
      src/core/openbsd/SDL_wscons_mouse.c
  51. 3 3
      src/core/windows/SDL_hid.c
  52. 2 2
      src/core/windows/SDL_immdevice.c
  53. 3 3
      src/core/windows/SDL_windows.c
  54. 2 2
      src/core/windows/SDL_xinput.c
  55. 3 8
      src/core/winrt/SDL_winrtapp_common.cpp
  56. 3 5
      src/core/winrt/SDL_winrtapp_direct3d.cpp
  57. 21 20
      src/cpuinfo/SDL_cpuinfo.c
  58. 1 1
      src/events/SDL_clipboardevents.c
  59. 2 2
      src/events/SDL_displayevents.c
  60. 16 16
      src/events/SDL_events.c
  61. 54 36
      src/events/SDL_gesture.c
  62. 8 9
      src/events/SDL_keyboard.c
  63. 14 14
      src/events/SDL_mouse.c
  64. 33 17
      src/events/SDL_touch.c
  65. 1 1
      src/events/SDL_windowevents.c
  66. 33 26
      src/file/SDL_rwops.c
  67. 1 1
      src/filesystem/android/SDL_sysfilesystem.c
  68. 5 4
      src/filesystem/emscripten/SDL_sysfilesystem.c
  69. 4 4
      src/filesystem/haiku/SDL_sysfilesystem.cc
  70. 8 5
      src/filesystem/ps2/SDL_sysfilesystem.c
  71. 2 2
      src/filesystem/psp/SDL_sysfilesystem.c
  72. 14 11
      src/filesystem/riscos/SDL_sysfilesystem.c
  73. 21 19
      src/filesystem/unix/SDL_sysfilesystem.c
  74. 3 3
      src/filesystem/vita/SDL_sysfilesystem.c
  75. 3 3
      src/filesystem/windows/SDL_sysfilesystem.c
  76. 6 6
      src/filesystem/winrt/SDL_sysfilesystem.cpp
  77. 20 24
      src/haptic/SDL_haptic.c
  78. 7 7
      src/haptic/android/SDL_syshaptic.c
  79. 1 2
      src/haptic/darwin/SDL_syshaptic.c
  80. 21 13
      src/haptic/linux/SDL_syshaptic.c
  81. 10 5
      src/haptic/windows/SDL_dinputhaptic.c
  82. 1 1
      src/haptic/windows/SDL_xinputhaptic.c
  83. 14 20
      src/hidapi/SDL_hidapi.c
  84. 80 74
      src/joystick/SDL_gamecontroller.c
  85. 19 22
      src/joystick/SDL_joystick.c
  86. 1 1
      src/joystick/android/SDL_sysjoystick.c
  87. 14 13
      src/joystick/bsd/SDL_bsdjoystick.c
  88. 12 14
      src/joystick/darwin/SDL_iokitjoystick.c
  89. 12 12
      src/joystick/emscripten/SDL_sysjoystick.c
  90. 1 2
      src/joystick/haiku/SDL_haikujoystick.cc
  91. 2 2
      src/joystick/hidapi/SDL_hidapi_gamecube.c
  92. 7 12
      src/joystick/hidapi/SDL_hidapi_luna.c
  93. 7 7
      src/joystick/hidapi/SDL_hidapi_ps3.c
  94. 5 7
      src/joystick/hidapi/SDL_hidapi_ps4.c
  95. 4 6
      src/joystick/hidapi/SDL_hidapi_ps5.c
  96. 1 1
      src/joystick/hidapi/SDL_hidapi_rumble.c
  97. 5 7
      src/joystick/hidapi/SDL_hidapi_shield.c
  98. 4 6
      src/joystick/hidapi/SDL_hidapi_stadia.c
  99. 93 138
      src/joystick/hidapi/SDL_hidapi_steam.c
  100. 19 22
      src/joystick/hidapi/SDL_hidapi_switch.c

+ 7 - 6
VisualC-GDK/tests/testgdk/src/testgdk.cpp

@@ -239,17 +239,17 @@ LoadSprite(const char *file)
         /* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
         sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
         if (!sprites[i]) {
-            return (-1);
+            return -1;
         }
         if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
             SDL_DestroyTexture(sprites[i]);
-            return (-1);
+            return -1;
         }
     }
 
     /* We're ready to roll. :) */
-    return (0);
+    return 0;
 }
 
 void
@@ -364,8 +364,9 @@ loop()
 #endif
     }
     for (i = 0; i < state->num_windows; ++i) {
-        if (state->windows[i] == NULL)
+        if (state->windows[i] == NULL) {
             continue;
+        }
         DrawSprites(state->renderers[i], sprites[i]);
     }
 }
@@ -382,7 +383,7 @@ main(int argc, char *argv[])
 
     /* Initialize test framework */
     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
-    if (!state) {
+    if (state == NULL) {
         return 1;
     }
 
@@ -445,7 +446,7 @@ main(int argc, char *argv[])
     /* Create the windows, initialize the renderers, and load the textures */
     sprites =
         (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
-    if (!sprites) {
+    if (sprites == NULL) {
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
         quit(2);
     }

+ 2 - 2
Xcode-iOS/Demos/src/accelerometer.c

@@ -127,7 +127,7 @@ initializeTextures(SDL_Renderer *renderer)
 
     /* create ship texture from surface */
     ship = SDL_CreateTextureFromSurface(renderer, bmp_surface);
-    if (!ship) {
+    if (ship == NULL) {
         fatalError("could not create ship texture");
     }
     SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND);
@@ -145,7 +145,7 @@ initializeTextures(SDL_Renderer *renderer)
     }
     /* create space texture from surface */
     space = SDL_CreateTextureFromSurface(renderer, bmp_surface);
-    if (!space) {
+    if (space == NULL) {
         fatalError("could not create space texture");
     }
     SDL_FreeSurface(bmp_surface);

+ 16 - 9
Xcode-iOS/Demos/src/fireworks.c

@@ -84,14 +84,16 @@ stepParticles(double deltaTime)
         /* is the particle actually active, or is it marked for deletion? */
         if (curr->isActive) {
             /* is the particle off the screen? */
-            if (curr->y > screen_h)
+            if (curr->y > screen_h) {
                 curr->isActive = 0;
-            else if (curr->y < 0)
+            } else if (curr->y < 0) {
                 curr->isActive = 0;
-            if (curr->x > screen_w)
+            }
+            if (curr->x > screen_w) {
                 curr->isActive = 0;
-            else if (curr->x < 0)
+            } else if (curr->x < 0) {
                 curr->isActive = 0;
+            }
 
             /* step velocity, then step position */
             curr->yvel += ACCEL * deltaMilliseconds;
@@ -133,15 +135,17 @@ stepParticles(double deltaTime)
                 }
 
                 /* if we're a dust particle, shrink our size */
-                if (curr->type == dust)
+                if (curr->type == dust) {
                     curr->size -= deltaMilliseconds * 0.010f;
+                }
 
             }
 
             /* if we're still active, pack ourselves in the array next
                to the last active guy (pack the array tightly) */
-            if (curr->isActive)
+            if (curr->isActive) {
                 *(slot++) = *curr;
+            }
         }                       /* endif (curr->isActive) */
         curr++;
     }
@@ -188,8 +192,9 @@ explodeEmitter(struct particle *emitter)
     int i;
     for (i = 0; i < 200; i++) {
 
-        if (num_active_particles >= MAX_PARTICLES)
+        if (num_active_particles >= MAX_PARTICLES) {
             return;
+        }
 
         /* come up with a random angle and speed for new particle */
         float theta = randomFloat(0, 2.0f * 3.141592);
@@ -226,8 +231,9 @@ void
 spawnTrailFromEmitter(struct particle *emitter)
 {
 
-    if (num_active_particles >= MAX_PARTICLES)
+    if (num_active_particles >= MAX_PARTICLES) {
         return;
+    }
 
     /* select the particle at the slot at the end of our array */
     struct particle *p = &particles[num_active_particles];
@@ -262,8 +268,9 @@ void
 spawnEmitterParticle(GLfloat x, GLfloat y)
 {
 
-    if (num_active_particles >= MAX_PARTICLES)
+    if (num_active_particles >= MAX_PARTICLES) {
         return;
+    }
 
     /* find particle at endpoint of array */
     struct particle *p = &particles[num_active_particles];

+ 1 - 1
Xcode-iOS/Demos/src/happy.c

@@ -117,7 +117,7 @@ initializeTexture(SDL_Renderer *renderer)
 
     /* convert RGBA surface to texture */
     texture = SDL_CreateTextureFromSurface(renderer, bmp_surface);
-    if (!texture) {
+    if (texture == NULL) {
         fatalError("could not create texture");
     }
     SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);

+ 2 - 2
Xcode-iOS/Demos/src/keyboard.c

@@ -165,7 +165,7 @@ loadFont(void)
 {
     SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp");
 
-    if (!surface) {
+    if (surface == NULL) {
         printf("Error loading bitmap: %s\n", SDL_GetError());
         return 0;
     } else {
@@ -183,7 +183,7 @@ loadFont(void)
         SDL_BlitSurface(surface, NULL, converted, NULL);
         /* create our texture */
         texture = SDL_CreateTextureFromSurface(renderer, converted);
-        if (!texture) {
+        if (texture == NULL) {
             printf("texture creation failed: %s\n", SDL_GetError());
         } else {
             /* set blend mode for our texture */

+ 2 - 2
Xcode-iOS/Demos/src/mixer.c

@@ -207,9 +207,9 @@ playSound(struct sound *s)
             break;
         }
         /* if this channel's sound is older than the oldest so far, set it to oldest */
-        if (mixer.channels[i].timestamp <
-            mixer.channels[oldest_channel].timestamp)
+        if (mixer.channels[i].timestamp < mixer.channels[oldest_channel].timestamp) {
             oldest_channel = i;
+        }
     }
 
     /* no empty channels, take the oldest one */

+ 2 - 2
Xcode-iOS/Demos/src/rectangles.c

@@ -58,11 +58,11 @@ main(int argc, char *argv[])
 
     /* create window and renderer */
     window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
-    if (!window) {
+    if (window == NULL) {
         fatalError("Could not initialize Window");
     }
     renderer = SDL_CreateRenderer(window, -1, 0);
-    if (!renderer) {
+    if (renderer == NULL) {
         fatalError("Could not create renderer");
     }
 

+ 1 - 1
Xcode-iOS/Demos/src/touch.c

@@ -63,7 +63,7 @@ initializeTexture(SDL_Renderer *renderer)
     brush =
         SDL_CreateTextureFromSurface(renderer, bmp_surface);
     SDL_FreeSurface(bmp_surface);
-    if (!brush) {
+    if (brush == NULL) {
         fatalError("could not create brush texture");
     }
     /* additive blending -- laying strokes on top of eachother makes them brighter */

+ 10 - 11
src/SDL.c

@@ -216,7 +216,7 @@ SDL_InitSubSystem(Uint32 flags)
     }
 
     /* Initialize the timer subsystem */
-    if ((flags & SDL_INIT_TIMER)){
+    if ((flags & SDL_INIT_TIMER)) {
 #if !SDL_TIMERS_DISABLED && !SDL_TIMER_DUMMY
         if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
             if (SDL_TimerInit() < 0) {
@@ -232,7 +232,7 @@ SDL_InitSubSystem(Uint32 flags)
     }
 
     /* Initialize the video subsystem */
-    if ((flags & SDL_INIT_VIDEO)){
+    if ((flags & SDL_INIT_VIDEO)) {
 #if !SDL_VIDEO_DISABLED
         if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
             if (SDL_VideoInit(NULL) < 0) {
@@ -248,7 +248,7 @@ SDL_InitSubSystem(Uint32 flags)
     }
 
     /* Initialize the audio subsystem */
-    if ((flags & SDL_INIT_AUDIO)){
+    if ((flags & SDL_INIT_AUDIO)) {
 #if !SDL_AUDIO_DISABLED
         if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
             if (SDL_AudioInit(NULL) < 0) {
@@ -264,7 +264,7 @@ SDL_InitSubSystem(Uint32 flags)
     }
 
     /* Initialize the joystick subsystem */
-    if ((flags & SDL_INIT_JOYSTICK)){
+    if ((flags & SDL_INIT_JOYSTICK)) {
 #if !SDL_JOYSTICK_DISABLED
         if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
            if (SDL_JoystickInit() < 0) {
@@ -279,7 +279,7 @@ SDL_InitSubSystem(Uint32 flags)
 #endif
     }
 
-    if ((flags & SDL_INIT_GAMECONTROLLER)){
+    if ((flags & SDL_INIT_GAMECONTROLLER)) {
 #if !SDL_JOYSTICK_DISABLED
         if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
             if (SDL_GameControllerInit() < 0) {
@@ -295,7 +295,7 @@ SDL_InitSubSystem(Uint32 flags)
     }
 
     /* Initialize the haptic subsystem */
-    if ((flags & SDL_INIT_HAPTIC)){
+    if ((flags & SDL_INIT_HAPTIC)) {
 #if !SDL_HAPTIC_DISABLED
         if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
             if (SDL_HapticInit() < 0) {
@@ -311,7 +311,7 @@ SDL_InitSubSystem(Uint32 flags)
     }
 
     /* Initialize the sensor subsystem */
-    if ((flags & SDL_INIT_SENSOR)){
+    if ((flags & SDL_INIT_SENSOR)) {
 #if !SDL_SENSOR_DISABLED
         if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
             if (SDL_SensorInit() < 0) {
@@ -328,11 +328,11 @@ SDL_InitSubSystem(Uint32 flags)
 
     (void) flags_initialized;  /* make static analysis happy, since this only gets used in error cases. */
 
-    return (0);
+    return 0;
 
 quit_and_error:
     SDL_QuitSubSystem(flags_initialized);
-    return (-1);
+    return -1;
 }
 
 int
@@ -500,8 +500,7 @@ SDL_GetVersion(SDL_version * ver)
     static SDL_bool check_hint = SDL_TRUE;
     static SDL_bool legacy_version = SDL_FALSE;
 
-    if (!ver) {
-        return;
+    if (ver == NULL) {        return;
     }
 
     SDL_VERSION(ver);

+ 1 - 4
src/SDL_assert.c

@@ -244,10 +244,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
         } else {
             state = (SDL_assert_state)selected;
         }
-    }
-
-    else
-    {
+    } else {
 #if defined(__EMSCRIPTEN__)
         /* This is nasty, but we can't block on a custom UI. */
         for ( ; ; ) {

+ 11 - 11
src/SDL_dataqueue.c

@@ -57,7 +57,7 @@ SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
 {
     SDL_DataQueue *queue = (SDL_DataQueue *) SDL_malloc(sizeof (SDL_DataQueue));
 
-    if (!queue) {
+    if (queue == NULL) {
         SDL_OutOfMemory();
         return NULL;
     } else {
@@ -101,7 +101,7 @@ SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
     SDL_DataQueuePacket *prev = NULL;
     size_t i;
 
-    if (!queue) {
+    if (queue == NULL) {
         return;
     }
 
@@ -180,7 +180,7 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
     size_t origlen;
     size_t datalen;
 
-    if (!queue) {
+    if (queue == NULL) {
         return SDL_InvalidParamError("queue");
     }
 
@@ -190,13 +190,13 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
 
     while (len > 0) {
         SDL_DataQueuePacket *packet = queue->tail;
-        SDL_assert(!packet || (packet->datalen <= packet_size));
-        if (!packet || (packet->datalen >= packet_size)) {
+        SDL_assert(packet == NULL || (packet->datalen <= packet_size));
+        if (packet == NULL || (packet->datalen >= packet_size)) {
             /* tail packet missing or completely full; we need a new packet. */
             packet = AllocateDataQueuePacket(queue);
-            if (!packet) {
+            if (packet == NULL) {
                 /* uhoh, reset so we've queued nothing new, free what we can. */
-                if (!origtail) {
+                if (origtail == NULL) {
                     packet = queue->head;  /* whole queue. */
                 } else {
                     packet = origtail->next;  /* what we added to existing queue. */
@@ -231,7 +231,7 @@ SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
     Uint8 *ptr = buf;
     SDL_DataQueuePacket *packet;
 
-    if (!queue) {
+    if (queue == NULL) {
         return 0;
     }
 
@@ -256,7 +256,7 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
     Uint8 *ptr = buf;
     SDL_DataQueuePacket *packet;
 
-    if (!queue) {
+    if (queue == NULL) {
         return 0;
     }
 
@@ -299,7 +299,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
 {
     SDL_DataQueuePacket *packet;
 
-    if (!queue) {
+    if (queue == NULL) {
         SDL_InvalidParamError("queue");
         return NULL;
     } else if (len == 0) {
@@ -323,7 +323,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
 
     /* Need a fresh packet. */
     packet = AllocateDataQueuePacket(queue);
-    if (!packet) {
+    if (packet == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }

+ 3 - 3
src/SDL_guid.c

@@ -51,15 +51,15 @@ void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
 static unsigned char nibble(unsigned char c)
 {
     if ((c >= '0') && (c <= '9')) {
-        return (c - '0');
+        return c - '0';
     }
 
     if ((c >= 'A') && (c <= 'F')) {
-        return (c - 'A' + 0x0a);
+        return c - 'A' + 0x0a;
     }
 
     if ((c >= 'a') && (c <= 'f')) {
-        return (c - 'a' + 0x0a);
+        return c - 'a' + 0x0a;
     }
 
     /* received an invalid character, and no real way to return an error */

+ 9 - 9
src/SDL_hints.c

@@ -50,7 +50,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
     SDL_Hint *hint;
     SDL_HintWatch *entry;
 
-    if (!name) {
+    if (name == NULL) {
         return SDL_FALSE;
     }
 
@@ -65,7 +65,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
                 return SDL_FALSE;
             }
             if (hint->value != value &&
-                (!value || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
+                (value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
                 for (entry = hint->callbacks; entry; ) {
                     /* Save the next entry in case this one is deleted */
                     SDL_HintWatch *next = entry->next;
@@ -82,7 +82,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
 
     /* Couldn't find the hint, add a new one */
     hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
-    if (!hint) {
+    if (hint == NULL) {
         return SDL_FALSE;
     }
     hint->name = SDL_strdup(name);
@@ -101,7 +101,7 @@ SDL_ResetHint(const char *name)
     SDL_Hint *hint;
     SDL_HintWatch *entry;
 
-    if (!name) {
+    if (name == NULL) {
         return SDL_FALSE;
     }
 
@@ -179,7 +179,7 @@ SDL_GetHint(const char *name)
 SDL_bool
 SDL_GetStringBoolean(const char *value, SDL_bool default_value)
 {
-    if (!value || !*value) {
+    if (value == NULL || !*value) {
         return default_value;
     }
     if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
@@ -202,7 +202,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
     SDL_HintWatch *entry;
     const char *value;
 
-    if (!name || !*name) {
+    if (name == NULL || !*name) {
         SDL_InvalidParamError("name");
         return;
     }
@@ -214,7 +214,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
     SDL_DelHintCallback(name, callback, userdata);
 
     entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
-    if (!entry) {
+    if (entry == NULL) {
         SDL_OutOfMemory();
         return;
     }
@@ -226,10 +226,10 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
             break;
         }
     }
-    if (!hint) {
+    if (hint == NULL) {
         /* Need to add a hint entry for this watcher */
         hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
-        if (!hint) {
+        if (hint == NULL) {
             SDL_OutOfMemory();
             SDL_free(entry);
             return;

+ 6 - 4
src/SDL_log.c

@@ -105,7 +105,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
 void
 SDL_LogInit(void)
 {
-    if (!log_function_mutex) {
+    if (log_function_mutex == NULL) {
         /* if this fails we'll try to continue without it. */
         log_function_mutex = SDL_CreateMutex();
     }
@@ -313,7 +313,7 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
         return;
     }
 
-    if (!log_function_mutex) {
+    if (log_function_mutex == NULL) {
         /* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */
         log_function_mutex = SDL_CreateMutex();
     }
@@ -323,15 +323,17 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
     len = SDL_vsnprintf(stack_buf, sizeof(stack_buf), fmt, aq);
     va_end(aq);
 
-    if (len < 0)
+    if (len < 0) {
         return;
+    }
 
     /* If message truncated, allocate and re-render */
     if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) {
         /* Allocate exactly what we need, including the zero-terminator */
         message = (char *)SDL_malloc(len_plus_term);
-        if (!message)
+        if (message == NULL) {
             return;
+        }
         va_copy(aq, ap);
         len = SDL_vsnprintf(message, len_plus_term, fmt, aq);
         va_end(aq);

+ 14 - 14
src/atomic/SDL_atomic.c

@@ -128,15 +128,15 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
 {
 #ifdef HAVE_MSC_ATOMICS
     SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(long) == sizeof(a->value));
-    return (_InterlockedCompareExchange((long*)&a->value, (long)newval, (long)oldval) == (long)oldval);
+    return _InterlockedCompareExchange((long *)&a->value, (long)newval, (long)oldval) == (long)oldval;
 #elif defined(HAVE_WATCOM_ATOMICS)
-    return (SDL_bool) _SDL_cmpxchg_watcom(&a->value, newval, oldval);
+    return (SDL_bool)_SDL_cmpxchg_watcom(&a->value, newval, oldval);
 #elif defined(HAVE_GCC_ATOMICS)
     return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval);
-#elif defined(__MACOS__)  /* this is deprecated in 10.12 sdk; favor gcc atomics. */
+#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
     return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
 #elif defined(__SOLARIS__)
-    return (SDL_bool) ((int) atomic_cas_uint((volatile uint_t*)&a->value, (uint_t)oldval, (uint_t)newval) == oldval);
+    return (SDL_bool)((int)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval);
 #elif EMULATE_CAS
     SDL_bool retval = SDL_FALSE;
 
@@ -157,17 +157,17 @@ SDL_bool
 SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
 {
 #if defined(HAVE_MSC_ATOMICS)
-    return (_InterlockedCompareExchangePointer(a, newval, oldval) == oldval);
+    return _InterlockedCompareExchangePointer(a, newval, oldval) == oldval;
 #elif defined(HAVE_WATCOM_ATOMICS)
-    return (SDL_bool) _SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
+    return (SDL_bool)_SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
 #elif defined(HAVE_GCC_ATOMICS)
     return __sync_bool_compare_and_swap(a, oldval, newval);
-#elif defined(__MACOS__) && defined(__LP64__)  /* this is deprecated in 10.12 sdk; favor gcc atomics. */
+#elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
     return (SDL_bool) OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t*) a);
-#elif defined(__MACOS__) && !defined(__LP64__)  /* this is deprecated in 10.12 sdk; favor gcc atomics. */
+#elif defined(__MACOS__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
     return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a);
 #elif defined(__SOLARIS__)
-    return (SDL_bool) (atomic_cas_ptr(a, oldval, newval) == oldval);
+    return (SDL_bool)(atomic_cas_ptr(a, oldval, newval) == oldval);
 #elif EMULATE_CAS
     SDL_bool retval = SDL_FALSE;
 
@@ -189,13 +189,13 @@ SDL_AtomicSet(SDL_atomic_t *a, int v)
 {
 #ifdef HAVE_MSC_ATOMICS
     SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value));
-    return _InterlockedExchange((long*)&a->value, v);
+    return _InterlockedExchange((long *)&a->value, v);
 #elif defined(HAVE_WATCOM_ATOMICS)
     return _SDL_xchg_watcom(&a->value, v);
 #elif defined(HAVE_GCC_ATOMICS)
     return __sync_lock_test_and_set(&a->value, v);
 #elif defined(__SOLARIS__)
-    return (int) atomic_swap_uint((volatile uint_t*)&a->value, v);
+    return (int)atomic_swap_uint((volatile uint_t *)&a->value, v);
 #else
     int value;
     do {
@@ -211,7 +211,7 @@ SDL_AtomicSetPtr(void **a, void *v)
 #if defined(HAVE_MSC_ATOMICS)
     return _InterlockedExchangePointer(a, v);
 #elif defined(HAVE_WATCOM_ATOMICS)
-    return (void *) _SDL_xchg_watcom((int *)a, (long)v);
+    return (void *)_SDL_xchg_watcom((int *)a, (long)v);
 #elif defined(HAVE_GCC_ATOMICS)
     return __sync_lock_test_and_set(a, v);
 #elif defined(__SOLARIS__)
@@ -230,7 +230,7 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
 {
 #ifdef HAVE_MSC_ATOMICS
     SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value));
-    return _InterlockedExchangeAdd((long*)&a->value, v);
+    return _InterlockedExchangeAdd((long *)&a->value, v);
 #elif defined(HAVE_WATCOM_ATOMICS)
     return _SDL_xadd_watcom(&a->value, v);
 #elif defined(HAVE_GCC_ATOMICS)
@@ -261,7 +261,7 @@ SDL_AtomicGet(SDL_atomic_t *a)
     return _SDL_xadd_watcom(&a->value, 0);
 #elif defined(HAVE_GCC_ATOMICS)
     return __sync_or_and_fetch(&a->value, 0);
-#elif defined(__MACOS__)  /* this is deprecated in 10.12 sdk; favor gcc atomics. */
+#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
     return sizeof(a->value) == sizeof(uint32_t) ? OSAtomicOr32Barrier(0, (volatile uint32_t *)&a->value) : OSAtomicAdd64Barrier(0, (volatile int64_t *)&a->value);
 #elif defined(__SOLARIS__)
     return atomic_or_uint((volatile uint_t *)&a->value, 0);

+ 11 - 11
src/atomic/SDL_spinlock.c

@@ -63,7 +63,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
     /* Terrible terrible damage */
     static SDL_mutex *_spinlock_mutex;
 
-    if (!_spinlock_mutex) {
+    if (_spinlock_mutex == NULL) {
         /* Race condition on first lock... */
         _spinlock_mutex = SDL_CreateMutex();
     }
@@ -78,14 +78,14 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
     }
 
 #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
-    return (__sync_lock_test_and_set(lock, 1) == 0);
+    return __sync_lock_test_and_set(lock, 1) == 0;
 
 #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
-    return (_InterlockedExchange_acq(lock, 1) == 0);
+    return _InterlockedExchange_acq(lock, 1) == 0;
 
 #elif defined(_MSC_VER)
     SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
-    return (InterlockedExchange((long*)lock, 1) == 0);
+    return InterlockedExchange((long *)lock, 1) == 0;
 
 #elif defined(__WATCOMC__) && defined(__386__)
     return _SDL_xchg_watcom(lock, 1) == 0;
@@ -102,28 +102,28 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
         __asm__ __volatile__ (
             "ldrex %0, [%2]\nteq   %0, #0\nstrexeq %0, %1, [%2]"
             : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
-        return (result == 0);
+        return result == 0;
     }
 #endif
 
     __asm__ __volatile__ (
         "swp %0, %1, [%2]\n"
         : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
-    return (result == 0);
+    return result == 0;
 
 #elif defined(__GNUC__) && defined(__arm__)
     int result;
     __asm__ __volatile__ (
         "ldrex %0, [%2]\nteq   %0, #0\nstrexeq %0, %1, [%2]"
         : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
-    return (result == 0);
+    return result == 0;
 
 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
     int result;
     __asm__ __volatile__(
         "lock ; xchgl %0, (%1)\n"
         : "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
-    return (result == 0);
+    return result == 0;
 
 #elif defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__)
     /* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
@@ -131,11 +131,11 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
 
 #elif defined(__SOLARIS__) && defined(_LP64)
     /* Used for Solaris with non-gcc compilers. */
-    return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)lock, 0, 1) == 0);
+    return (SDL_bool)((int)atomic_cas_64((volatile uint64_t *)lock, 0, 1) == 0);
 
 #elif defined(__SOLARIS__) && !defined(_LP64)
     /* Used for Solaris with non-gcc compilers. */
-    return (SDL_bool) ((int) atomic_cas_32((volatile uint32_t*)lock, 0, 1) == 0);
+    return (SDL_bool)((int)atomic_cas_32((volatile uint32_t *)lock, 0, 1) == 0);
 #elif defined(PS2)
     uint32_t oldintr;
     SDL_bool res = SDL_FALSE;
@@ -147,7 +147,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
         res = SDL_TRUE;
     }
     // enable interuption
-    if(oldintr) { EIntr(); }
+    if (oldintr) { EIntr(); }
     return res;
 #else
 #error Please implement for your platform.

+ 3 - 5
src/audio/SDL_audio.c

@@ -509,11 +509,9 @@ SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle)
     } else {
         mark_device_removed(handle, current_audio.outputDevices, &current_audio.outputDevicesRemoved);
     }
-    for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++)
-    {
+    for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++) {
         device = open_devices[device_index];
-        if (device != NULL && device->handle == handle)
-        {
+        if (device != NULL && device->handle == handle) {
             device_was_opened = SDL_TRUE;
             SDL_OpenedAudioDeviceDisconnected(device);
             break;
@@ -977,7 +975,7 @@ SDL_AudioInit(const char *driver_name)
         }
     } else {
         for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
-            if(bootstrap[i]->demand_only) {
+            if (bootstrap[i]->demand_only) {
                 continue;
             }
 

+ 22 - 20
src/audio/SDL_audiocvt.c

@@ -180,7 +180,7 @@ ResamplerPadding(const int inrate, const int outrate)
         return 0;
     }
     if (inrate > outrate) {
-        return (int) SDL_ceilf(((float) (RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float) outrate)));
+        return (int)SDL_ceilf(((float)(RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float)outrate)));
     }
     return RESAMPLER_SAMPLES_PER_ZERO_CROSSING;
 }
@@ -246,7 +246,7 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate,
         outtime = outtimeincr * i;
     }
 
-    return outframes * chans * sizeof (float);
+    return outframes * chans * sizeof(float);
 }
 
 int
@@ -485,7 +485,7 @@ SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format
 
     /* we keep no streaming state here, so pad with silence on both ends. */
     padding = (float *) SDL_calloc(paddingsamples ? paddingsamples : 1, sizeof (float));
-    if (!padding) {
+    if (padding == NULL) {
         SDL_OutOfMemory();
         return;
     }
@@ -583,7 +583,7 @@ SDL_BuildAudioResampleCVT(SDL_AudioCVT * cvt, const int dst_channels,
        !!! FIXME in 2.1:   We need to store data for this resampler, because the cvt structure doesn't store the original sample rates,
        !!! FIXME in 2.1:   so we steal the ninth and tenth slot.  :( */
     if (cvt->filter_index >= (SDL_AUDIOCVT_MAX_FILTERS-2)) {
-        return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS-2);
+        return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS - 2);
     }
     cvt->filters[SDL_AUDIOCVT_MAX_FILTERS-1] = (SDL_AudioFilter) (uintptr_t) src_rate;
     cvt->filters[SDL_AUDIOCVT_MAX_FILTERS] = (SDL_AudioFilter) (uintptr_t) dst_rate;
@@ -785,7 +785,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
     }
 
     cvt->needed = (cvt->filter_index != 0);
-    return (cvt->needed);
+    return cvt->needed;
 }
 
 typedef int (*SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen);
@@ -832,7 +832,7 @@ EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
         ptr = stream->work_buffer_base;
     } else {
         ptr = (Uint8 *) SDL_realloc(stream->work_buffer_base, newlen + 32);
-        if (!ptr) {
+        if (ptr == NULL) {
             SDL_OutOfMemory();
             return NULL;
         }
@@ -908,12 +908,12 @@ SetupLibSampleRateResampling(SDL_AudioStream *stream)
 
     if (SRC_available) {
         state = SRC_src_new(SRC_converter, stream->pre_resample_channels, &result);
-        if (!state) {
+        if (state == NULL) {
             SDL_SetError("src_new() failed: %s", SRC_src_strerror(result));
         }
     }
 
-    if (!state) {
+    if (state == NULL) {
         SDL_CleanupAudioStreamResampler_SRC(stream);
         return SDL_FALSE;
     }
@@ -980,7 +980,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
     SDL_AudioStream *retval;
 
     retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream));
-    if (!retval) {
+    if (retval == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -1123,7 +1123,7 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in
     #endif
 
     workbuf = EnsureStreamBufferSize(stream, workbuflen);
-    if (!workbuf) {
+    if (workbuf == NULL) {
         return -1;  /* probably out of memory. */
     }
 
@@ -1190,8 +1190,9 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in
 
     if (maxputbytes) {
         const int maxbytes = *maxputbytes;
-        if (buflen > maxbytes)
+        if (buflen > maxbytes) {
             buflen = maxbytes;
+        }
         *maxputbytes -= buflen;
     }
 
@@ -1214,10 +1215,10 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
     SDL_Log("AUDIOSTREAM: wants to put %d preconverted bytes\n", buflen);
     #endif
 
-    if (!stream) {
+    if (stream == NULL) {
         return SDL_InvalidParamError("stream");
     }
-    if (!buf) {
+    if (buf == NULL) {
         return SDL_InvalidParamError("buf");
     }
     if (len == 0) {
@@ -1269,7 +1270,7 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
 
 int SDL_AudioStreamFlush(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    if (stream == NULL) {
         return SDL_InvalidParamError("stream");
     }
 
@@ -1287,8 +1288,9 @@ int SDL_AudioStreamFlush(SDL_AudioStream *stream)
         const SDL_bool first_run = stream->first_run;
         const int filled = stream->staging_buffer_filled;
         int actual_input_frames = filled / stream->src_sample_frame_size;
-        if (!first_run)
+        if (!first_run) {
             actual_input_frames += stream->resampler_padding_samples / stream->pre_resample_channels;
+        }
 
         if (actual_input_frames > 0) {  /* don't bother if nothing to flush. */
             /* This is how many bytes we're expecting without silence appended. */
@@ -1327,10 +1329,10 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
     SDL_Log("AUDIOSTREAM: want to get %d converted bytes\n", len);
     #endif
 
-    if (!stream) {
+    if (stream == NULL) {
         return SDL_InvalidParamError("stream");
     }
-    if (!buf) {
+    if (buf == NULL) {
         return SDL_InvalidParamError("buf");
     }
     if (len <= 0) {
@@ -1340,20 +1342,20 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
         return SDL_SetError("Can't request partial sample frames");
     }
 
-    return (int) SDL_ReadFromDataQueue(stream->queue, buf, len);
+    return (int)SDL_ReadFromDataQueue(stream->queue, buf, len);
 }
 
 /* number of converted/resampled bytes available */
 int
 SDL_AudioStreamAvailable(SDL_AudioStream *stream)
 {
-    return stream ? (int) SDL_CountDataQueue(stream->queue) : 0;
+    return stream ? (int)SDL_CountDataQueue(stream->queue) : 0;
 }
 
 void
 SDL_AudioStreamClear(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    if (stream == NULL) {
         SDL_InvalidParamError("stream");
     } else {
         SDL_ClearDataQueue(stream->queue, stream->packetlen * 2);

+ 2 - 1
src/audio/SDL_audiodev.c

@@ -83,8 +83,9 @@ SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*
     const char *audiodev;
     char audiopath[1024];
 
-    if (test == NULL)
+    if (test == NULL) {
         test = test_stub;
+    }
 
     /* Figure out what our audio device is */
     if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&

+ 9 - 5
src/audio/SDL_wave.c

@@ -818,7 +818,7 @@ IMA_ADPCM_Init(WaveFile *file, size_t datalength)
         /* There's no specification for this, but it's basically the same
          * format because the extensible header has wSampePerBlocks too.
          */
-    } else  {
+    } else {
         /* The Standards Update says there 'should' be 2 bytes for wSamplesPerBlock. */
         if (chunk->size >= 20 && format->extsize >= 2) {
             format->samplesperblock = chunk->data[18] | ((Uint16)chunk->data[19] << 8);
@@ -899,14 +899,18 @@ IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
      * (nybble & 0x8 ? -1 : 1) * ((nybble & 0x7) * step / 4 + step / 8)
      */
     delta = step >> 3;
-    if (nybble & 0x04)
+    if (nybble & 0x04) {
         delta += step;
-    if (nybble & 0x02)
+    }
+    if (nybble & 0x02) {
         delta += step >> 1;
-    if (nybble & 0x01)
+    }
+    if (nybble & 0x01) {
         delta += step >> 2;
-    if (nybble & 0x08)
+    }
+    if (nybble & 0x08) {
         delta = -delta;
+    }
 
     sample = lastsample + delta;
 

+ 1 - 1
src/audio/aaudio/SDL_aaudio.c

@@ -439,7 +439,7 @@ SDL_bool aaudio_DetectBrokenPlayState( void )
     int64_t framePosition, timeNanoseconds;
     aaudio_result_t res;
 
-    if ( !audioDevice || !audioDevice->hidden ) {
+    if (audioDevice == NULL || !audioDevice->hidden ) {
         return SDL_FALSE;
     }
 

+ 32 - 37
src/audio/alsa/SDL_alsa_audio.c

@@ -230,7 +230,7 @@ get_audio_device(void *handle, const int channels)
     const char *device;
 
     if (handle != NULL) {
-        return (const char *) handle;
+        return (const char *)handle;
     }
 
     /* !!! FIXME: we also check "SDL_AUDIO_DEVICE_NAME" at the higher level. */
@@ -398,8 +398,7 @@ ALSA_PlayDevice(_THIS)
                 return;
             }
             continue;
-        }
-        else if (status == 0) {
+        } else if (status == 0) {
             /* No frames were written (no available space in pcm device).
                Allow other threads to catch up. */
             Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq;
@@ -414,7 +413,7 @@ ALSA_PlayDevice(_THIS)
 static Uint8 *
 ALSA_GetDeviceBuf(_THIS)
 {
-    return (this->hidden->mixbuf);
+    return this->hidden->mixbuf;
 }
 
 static int
@@ -438,8 +437,7 @@ ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
         if (status == -EAGAIN) {
             ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time);
             status = 0;
-        }
-        else if (status < 0) {
+        } else if (status < 0) {
             /*printf("ALSA: capture error %d\n", status);*/
             status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
             if (status < 0) {
@@ -500,7 +498,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
     status = ALSA_snd_pcm_hw_params_set_period_size_near(
                 this->hidden->pcm_handle, hwparams, &persize, NULL);
     if ( status < 0 ) {
-        return(-1);
+        return -1;
     }
 
     /* Need to at least double buffer */
@@ -508,19 +506,19 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
     status = ALSA_snd_pcm_hw_params_set_periods_min(
                 this->hidden->pcm_handle, hwparams, &periods, NULL);
     if ( status < 0 ) {
-        return(-1);
+        return -1;
     }
 
     status = ALSA_snd_pcm_hw_params_set_periods_first(
                 this->hidden->pcm_handle, hwparams, &periods, NULL);
     if ( status < 0 ) {
-        return(-1);
+        return -1;
     }
 
     /* "set" the hardware with the desired parameters */
     status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams);
     if ( status < 0 ) {
-        return(-1);
+        return -1;
     }
 
     this->spec.samples = persize;
@@ -536,7 +534,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
             persize, periods, bufsize);
     }
 
-    return(0);
+    return 0;
 }
 
 static int
@@ -572,8 +570,7 @@ ALSA_OpenDevice(_THIS, const char *devname)
                 SND_PCM_NONBLOCK);
 
     if (status < 0) {
-        return SDL_SetError("ALSA: Couldn't open audio device: %s",
-                            ALSA_snd_strerror(status));
+        return SDL_SetError("ALSA: Couldn't open audio device: %s", ALSA_snd_strerror(status));
     }
 
     this->hidden->pcm_handle = pcm_handle;
@@ -582,16 +579,14 @@ ALSA_OpenDevice(_THIS, const char *devname)
     snd_pcm_hw_params_alloca(&hwparams);
     status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
     if (status < 0) {
-        return SDL_SetError("ALSA: Couldn't get hardware config: %s",
-                            ALSA_snd_strerror(status));
+        return SDL_SetError("ALSA: Couldn't get hardware config: %s", ALSA_snd_strerror(status));
     }
 
     /* SDL only uses interleaved sample output */
     status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
                                                SND_PCM_ACCESS_RW_INTERLEAVED);
     if (status < 0) {
-        return SDL_SetError("ALSA: Couldn't set interleaved access: %s",
-                     ALSA_snd_strerror(status));
+        return SDL_SetError("ALSA: Couldn't set interleaved access: %s", ALSA_snd_strerror(status));
     }
 
     /* Try for a closest match on audio format */
@@ -673,8 +668,7 @@ ALSA_OpenDevice(_THIS, const char *devname)
     status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
                                                   &rate, NULL);
     if (status < 0) {
-        return SDL_SetError("ALSA: Couldn't set audio frequency: %s",
-                            ALSA_snd_strerror(status));
+        return SDL_SetError("ALSA: Couldn't set audio frequency: %s", ALSA_snd_strerror(status));
     }
     this->spec.freq = rate;
 
@@ -688,24 +682,20 @@ ALSA_OpenDevice(_THIS, const char *devname)
     snd_pcm_sw_params_alloca(&swparams);
     status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
     if (status < 0) {
-        return SDL_SetError("ALSA: Couldn't get software config: %s",
-                            ALSA_snd_strerror(status));
+        return SDL_SetError("ALSA: Couldn't get software config: %s", ALSA_snd_strerror(status));
     }
     status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
     if (status < 0) {
-        return SDL_SetError("Couldn't set minimum available samples: %s",
-                            ALSA_snd_strerror(status));
+        return SDL_SetError("Couldn't set minimum available samples: %s", ALSA_snd_strerror(status));
     }
     status =
         ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
     if (status < 0) {
-        return SDL_SetError("ALSA: Couldn't set start threshold: %s",
-                            ALSA_snd_strerror(status));
+        return SDL_SetError("ALSA: Couldn't set start threshold: %s", ALSA_snd_strerror(status));
     }
     status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
     if (status < 0) {
-        return SDL_SetError("Couldn't set software audio parameters: %s",
-                            ALSA_snd_strerror(status));
+        return SDL_SetError("Couldn't set software audio parameters: %s", ALSA_snd_strerror(status));
     }
 
     /* Calculate the final parameters for this audio specification */
@@ -746,7 +736,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
     char *handle = NULL;
     char *ptr;
 
-    if (!dev) {
+    if (dev == NULL) {
         return;
     }
 
@@ -756,7 +746,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
        Make sure not to free the storage associated with desc in this case */
     if (hint) {
         desc = ALSA_snd_device_name_get_hint(hint, "DESC");
-        if (!desc) {
+        if (desc == NULL) {
             SDL_free(dev);
             return;
         }
@@ -776,7 +766,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
     /*printf("ALSA: adding %s device '%s' (%s)\n", iscapture ? "capture" : "output", name, desc);*/
 
     handle = SDL_strdup(name);
-    if (!handle) {
+    if (handle == NULL) {
         if (hint) {
             free(desc);
         }
@@ -789,8 +779,9 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
      * enumeration time
      */
     SDL_AddAudioDevice(iscapture, desc, NULL, handle);
-    if (hint)
+    if (hint) {
         free(desc);
+    }
     dev->name = handle;
     dev->iscapture = iscapture;
     dev->next = *pSeen;
@@ -829,7 +820,7 @@ ALSA_HotplugIteration(void)
            if we can find a preferred prefix for the system. */
         for (i = 0; hints[i]; i++) {
             char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
-            if (!name) {
+            if (name == NULL) {
                 continue;
             }
 
@@ -858,17 +849,17 @@ ALSA_HotplugIteration(void)
             char *name;
 
             /* if we didn't find a device name prefix we like at all... */
-            if ((!match) && (defaultdev != i)) {
+            if ((match == NULL) && (defaultdev != i)) {
                 continue;  /* ...skip anything that isn't the default device. */
             }
 
             name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
-            if (!name) {
+            if (name == NULL) {
                 continue;
             }
 
             /* only want physical hardware interfaces */
-            if (!match || (SDL_strncmp(name, match, match_len) == 0)) {
+            if (match == NULL || (SDL_strncmp(name, match, match_len) == 0)) {
                 char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
                 const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
                 const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
@@ -893,8 +884,12 @@ ALSA_HotplugIteration(void)
                         }
                         dev->next = seen;
                         seen = dev;
-                        if (isinput) have_input = SDL_TRUE;
-                        if (isoutput) have_output = SDL_TRUE;
+                        if (isinput) {
+                            have_input = SDL_TRUE;
+                        }
+                        if (isoutput) {
+                            have_output = SDL_TRUE;
+                        }
                     } else {
                         prev = dev;
                     }

+ 6 - 8
src/audio/android/SDL_androidaudio.c

@@ -146,26 +146,24 @@ void ANDROIDAUDIO_PauseDevices(void)
 {
     /* TODO: Handle multiple devices? */
     struct SDL_PrivateAudioData *private;
-    if(audioDevice != NULL && audioDevice->hidden != NULL) {
+    if (audioDevice != NULL && audioDevice->hidden != NULL) {
         private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
         if (SDL_AtomicGet(&audioDevice->paused)) {
             /* The device is already paused, leave it alone */
             private->resume = SDL_FALSE;
-        }
-        else {
+        } else {
             SDL_LockMutex(audioDevice->mixer_lock);
             SDL_AtomicSet(&audioDevice->paused, 1);
             private->resume = SDL_TRUE;
         }
     }
 
-    if(captureDevice != NULL && captureDevice->hidden != NULL) {
+    if (captureDevice != NULL && captureDevice->hidden != NULL) {
         private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
         if (SDL_AtomicGet(&captureDevice->paused)) {
             /* The device is already paused, leave it alone */
             private->resume = SDL_FALSE;
-        }
-        else {
+        } else {
             SDL_LockMutex(captureDevice->mixer_lock);
             SDL_AtomicSet(&captureDevice->paused, 1);
             private->resume = SDL_TRUE;
@@ -178,7 +176,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
 {
     /* TODO: Handle multiple devices? */
     struct SDL_PrivateAudioData *private;
-    if(audioDevice != NULL && audioDevice->hidden != NULL) {
+    if (audioDevice != NULL && audioDevice->hidden != NULL) {
         private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
         if (private->resume) {
             SDL_AtomicSet(&audioDevice->paused, 0);
@@ -187,7 +185,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
         }
     }
 
-    if(captureDevice != NULL && captureDevice->hidden != NULL) {
+    if (captureDevice != NULL && captureDevice->hidden != NULL) {
         private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
         if (private->resume) {
             SDL_AtomicSet(&captureDevice->paused, 0);

+ 3 - 3
src/audio/directsound/SDL_directsound.c

@@ -293,7 +293,7 @@ DSOUND_GetDeviceBuf(_THIS)
     }
     if (result != DS_OK) {
         SetDSerror("DirectSound GetCurrentPosition", result);
-        return (NULL);
+        return NULL;
     }
     cursor /= this->spec.size;
 #ifdef DEBUG_SOUND
@@ -328,9 +328,9 @@ DSOUND_GetDeviceBuf(_THIS)
     }
     if (result != DS_OK) {
         SetDSerror("DirectSound Lock", result);
-        return (NULL);
+        return NULL;
     }
-    return (this->hidden->locked_buf);
+    return this->hidden->locked_buf;
 }
 
 static int

+ 1 - 1
src/audio/disk/SDL_diskaudio.c

@@ -65,7 +65,7 @@ DISKAUDIO_PlayDevice(_THIS)
 static Uint8 *
 DISKAUDIO_GetDeviceBuf(_THIS)
 {
-    return (_this->hidden->mixbuf);
+    return _this->hidden->mixbuf;
 }
 
 static int

+ 6 - 5
src/audio/dsp/SDL_dspaudio.c

@@ -80,12 +80,13 @@ DSP_OpenDevice(_THIS, const char *devname)
 
     /* Make sure fragment size stays a power of 2, or OSS fails. */
     /* I don't know which of these are actually legal values, though... */
-    if (this->spec.channels > 8)
+    if (this->spec.channels > 8) {
         this->spec.channels = 8;
-    else if (this->spec.channels > 4)
+    } else if (this->spec.channels > 4) {
         this->spec.channels = 4;
-    else if (this->spec.channels > 2)
+    } else if (this->spec.channels > 2) {
         this->spec.channels = 2;
+    }
 
     /* Initialize all variables that we clean on shutdown */
     this->hidden = (struct SDL_PrivateAudioData *)
@@ -258,13 +259,13 @@ DSP_PlayDevice(_THIS)
 static Uint8 *
 DSP_GetDeviceBuf(_THIS)
 {
-    return (this->hidden->mixbuf);
+    return this->hidden->mixbuf;
 }
 
 static int
 DSP_CaptureFromDevice(_THIS, void *buffer, int buflen)
 {
-    return (int) read(this->hidden->audio_fd, buffer, buflen);
+    return (int)read(this->hidden->audio_fd, buffer, buflen);
 }
 
 static void

+ 1 - 1
src/audio/emscripten/SDL_emscriptenaudio.c

@@ -206,7 +206,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
 
     /* create context */
     result = MAIN_THREAD_EM_ASM_INT({
-        if(typeof(Module['SDL3']) === 'undefined') {
+        if (typeof(Module['SDL3']) === 'undefined') {
             Module['SDL3'] = {};
         }
         var SDL3 = Module['SDL3'];

+ 1 - 1
src/audio/jack/SDL_jackaudio.c

@@ -310,7 +310,7 @@ JACK_OpenDevice(_THIS, const char *devname)
     }
 
     devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags);
-    if (!devports || !devports[0]) {
+    if (devports == NULL || !devports[0]) {
         return SDL_SetError("No physical JACK ports available");
     }
 

+ 1 - 1
src/audio/netbsd/SDL_netbsdaudio.c

@@ -144,7 +144,7 @@ NETBSDAUDIO_PlayDevice(_THIS)
 static Uint8 *
 NETBSDAUDIO_GetDeviceBuf(_THIS)
 {
-    return (this->hidden->mixbuf);
+    return this->hidden->mixbuf;
 }
 
 

+ 2 - 2
src/audio/openslES/SDL_openslES.c

@@ -423,7 +423,7 @@ openslES_CreatePCMPlayer(_THIS)
        it can be done as described here:
         https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point
     */
-    if(SDL_GetAndroidSDKVersion() >= 21) {
+    if (SDL_GetAndroidSDKVersion() >= 21) {
         SDL_AudioFormat test_format;
         for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
             if (SDL_AUDIO_ISSIGNED(test_format)) {
@@ -498,7 +498,7 @@ openslES_CreatePCMPlayer(_THIS)
         break;
     }
 
-    if(SDL_AUDIO_ISFLOAT(this->spec.format)) {
+    if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
         /* Copy all setup into PCM EX structure */
         format_pcm_ex.formatType = SL_ANDROID_DATAFORMAT_PCM_EX;
         format_pcm_ex.endianness = format_pcm.endianness;

+ 5 - 5
src/audio/pipewire/SDL_pipewire.c

@@ -1062,7 +1062,7 @@ input_callback(void *data)
     }
 
     pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream);
-    if (!pw_buf) {
+    if (pw_buf == NULL) {
         return;
     }
 
@@ -1186,15 +1186,15 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname)
 
     /* Get the hints for the application name, stream name and role */
     app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
-    if (!app_name || *app_name == '\0') {
+    if (app_name == NULL || *app_name == '\0') {
         app_name = SDL_GetHint(SDL_HINT_APP_NAME);
-        if (!app_name || *app_name == '\0') {
+        if (app_name == NULL || *app_name == '\0') {
             app_name = "SDL Application";
         }
     }
 
     stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME);
-    if (!stream_name || *stream_name == '\0') {
+    if (stream_name == NULL || *stream_name == '\0') {
         stream_name = "Audio Stream";
     }
 
@@ -1203,7 +1203,7 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname)
      * but 'Game' seems more appropriate for the majority of SDL applications.
      */
     stream_role = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_ROLE);
-    if (!stream_role || *stream_role == '\0') {
+    if (stream_role == NULL || *stream_role == '\0') {
         stream_role = "Game";
     }
 

+ 2 - 1
src/audio/ps2/SDL_ps2audio.c

@@ -154,8 +154,9 @@ static void PS2AUDIO_Deinitialize(void)
 
 static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl * impl)
 {
-    if(init_audio_driver() < 0)
+    if (init_audio_driver() < 0) {
         return SDL_FALSE;
+    }
 
     /* Set the function pointers */
     impl->OpenDevice = PS2AUDIO_OpenDevice;

+ 2 - 2
src/audio/psp/SDL_pspaudio.c

@@ -102,7 +102,7 @@ PSPAUDIO_OpenDevice(_THIS, const char *devname)
 
 static void PSPAUDIO_PlayDevice(_THIS)
 {
-    if (this->spec.freq != 44100){
+    if (this->spec.freq != 44100) {
         Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
         SDL_assert(this->spec.channels == 2);
         sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, mixbuf);
@@ -128,7 +128,7 @@ static Uint8 *PSPAUDIO_GetDeviceBuf(_THIS)
 static void PSPAUDIO_CloseDevice(_THIS)
 {
     if (this->hidden->channel >= 0) {
-        if (this->spec.freq != 44100){
+        if (this->spec.freq != 44100) {
             sceAudioSRCChRelease();
         } else {
             sceAudioChRelease(this->hidden->channel);

+ 4 - 10
src/audio/pulseaudio/SDL_pulseaudio.c

@@ -49,17 +49,11 @@ static SDL_bool include_monitors = SDL_FALSE;
 #if (PA_API_VERSION < 12)
 /** Return non-zero if the passed state is one of the connected states */
 static SDL_INLINE int PA_CONTEXT_IS_GOOD(pa_context_state_t x) {
-    return
-        x == PA_CONTEXT_CONNECTING ||
-        x == PA_CONTEXT_AUTHORIZING ||
-        x == PA_CONTEXT_SETTING_NAME ||
-        x == PA_CONTEXT_READY;
+    return x == PA_CONTEXT_CONNECTING || x == PA_CONTEXT_AUTHORIZING || x == PA_CONTEXT_SETTING_NAME || x == PA_CONTEXT_READY;
 }
 /** Return non-zero if the passed state is one of the connected states */
 static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x) {
-    return
-        x == PA_STREAM_CREATING ||
-        x == PA_STREAM_READY;
+    return x == PA_STREAM_CREATING || x == PA_STREAM_READY;
 }
 #endif /* pulseaudio <= 0.9.10 */
 
@@ -308,7 +302,7 @@ ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
     SDL_assert(mainloop_api);  /* this never fails, right? */
 
     context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
-    if (!context) {
+    if (context == NULL) {
         PULSEAUDIO_pa_mainloop_free(mainloop);
         return SDL_SetError("pa_context_new() failed");
     }
@@ -541,7 +535,7 @@ FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *h
                 SinkDeviceNameCallback, &h->device_name));
     }
 
-    return (h->device_name != NULL);
+    return h->device_name != NULL;
 }
 
 static int

+ 2 - 2
src/audio/vita/SDL_vitaaudio.c

@@ -78,7 +78,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
         }
     }
 
-    if(!test_format) {
+    if (!test_format) {
         return SDL_SetError("Unsupported audio format");
     }
 
@@ -108,7 +108,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
         format = SCE_AUDIO_OUT_MODE_STEREO;
     }
 
-    if(this->spec.freq < 48000) {
+    if (this->spec.freq < 48000) {
         port = SCE_AUDIO_OUT_PORT_TYPE_BGM;
     }
 

+ 2 - 3
src/audio/wasapi/SDL_wasapi_winrt.cpp

@@ -387,8 +387,7 @@ WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
         if (SDL_wcscmp(i->str, devid) == 0) {
             if (prev) {
                 prev->next = next;
-            }
-            else {
+            } else {
                 deviceid_list = next;
             }
             SDL_RemoveAudioDevice(iscapture, i->str);
@@ -419,7 +418,7 @@ WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTENS
     }
 
     devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist));
-    if (!devidlist) {
+    if (devidlist == NULL) {
         return;  /* oh well. */
     }
 

+ 11 - 16
src/core/android/SDL_android.c

@@ -727,7 +727,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
     library_file = (*env)->GetStringUTFChars(env, library, NULL);
     library_handle = dlopen(library_file, RTLD_GLOBAL);
 
-    if (!library_handle) {
+    if (library_handle == NULL) {
         /* When deploying android app bundle format uncompressed native libs may not extract from apk to filesystem.
            In this case we should use lib name without path. https://bugzilla.libsdl.org/show_bug.cgi?id=4739 */
         const char *library_name = SDL_strrchr(library_file, '/');
@@ -770,7 +770,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
                     }
                     (*env)->DeleteLocalRef(env, string);
                 }
-                if (!arg) {
+                if (arg == NULL) {
                     arg = SDL_strdup("");
                 }
                 argv[argc++] = arg;
@@ -867,8 +867,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
 {
     SDL_LockMutex(Android_ActivityMutex);
 
-    if (Android_Window)
-    {
+    if (Android_Window) {
         Android_SendResize(Android_Window);
     }
 
@@ -883,8 +882,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
 
     displayOrientation = (SDL_DisplayOrientation)orientation;
 
-    if (Android_Window)
-    {
+    if (Android_Window) {
         SDL_VideoDisplay *display = SDL_GetDisplay(0);
         SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
     }
@@ -993,8 +991,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, j
 {
     SDL_LockMutex(Android_ActivityMutex);
 
-    if (Android_Window)
-    {
+    if (Android_Window) {
         SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
 
         data->native_window = Android_JNI_GetNativeWindow();
@@ -1012,8 +1009,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j
     SDL_LockMutex(Android_ActivityMutex);
 
 #if SDL_VIDEO_OPENGL_EGL
-    if (Android_Window)
-    {
+    if (Android_Window) {
         SDL_VideoDevice *_this = SDL_GetVideoDevice();
         SDL_WindowData  *data  = (SDL_WindowData *) Android_Window->driverdata;
 
@@ -1038,8 +1034,7 @@ retry:
 
     SDL_LockMutex(Android_ActivityMutex);
 
-    if (Android_Window)
-    {
+    if (Android_Window) {
         SDL_VideoDevice *_this = SDL_GetVideoDevice();
         SDL_WindowData  *data  = (SDL_WindowData *) Android_Window->driverdata;
 
@@ -1873,7 +1868,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
 
     if (result > 0) {
         /* Number of chuncks */
-        return (result / size);
+        return result / size;
     } else {
         /* Error or EOF */
         return result;
@@ -2258,7 +2253,7 @@ void *SDL_AndroidGetActivity(void)
     /* See SDL_system.h for caveats on using this function. */
 
     JNIEnv *env = Android_JNI_GetEnv();
-    if (!env) {
+    if (env == NULL) {
         return NULL;
     }
 
@@ -2312,7 +2307,7 @@ const char * SDL_AndroidGetInternalStoragePath(void)
 {
     static char *s_AndroidInternalFilesPath = NULL;
 
-    if (!s_AndroidInternalFilesPath) {
+    if (s_AndroidInternalFilesPath == NULL) {
         struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
         jmethodID mid;
         jobject context;
@@ -2405,7 +2400,7 @@ const char * SDL_AndroidGetExternalStoragePath(void)
 {
     static char *s_AndroidExternalFilesPath = NULL;
 
-    if (!s_AndroidExternalFilesPath) {
+    if (s_AndroidExternalFilesPath == NULL) {
         struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
         jmethodID mid;
         jobject context;

+ 66 - 45
src/core/freebsd/SDL_evdev_kbd_freebsd.c

@@ -67,7 +67,7 @@ struct SDL_EVDEV_keyboard_state
 
 static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd)
 {
-    return (ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0);
+    return ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0;
 }
 
 static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL;
@@ -95,7 +95,9 @@ static void kbd_cleanup(void)
     SDL_zero(mData);
     mData.operation = MOUSE_SHOW;
     ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
-    if (kbd->keyboard_fd != kbd->console_fd) close(kbd->keyboard_fd);
+    if (kbd->keyboard_fd != kbd->console_fd) {
+        close(kbd->keyboard_fd);
+    }
     ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
     ioctl(kbd->console_fd, CONS_MOUSECTL, &mData);
 }
@@ -151,13 +153,14 @@ static void kbd_unregister_emerg_cleanup()
         old_action_p = &(old_sigaction[signum]);
 
         /* Examine current signal action */
-        if (sigaction(signum, NULL, &cur_action))
+        if (sigaction(signum, NULL, &cur_action)) {
             continue;
+        }
 
         /* Check if action installed and not modifed */
-        if (!(cur_action.sa_flags & SA_SIGINFO)
-                || cur_action.sa_sigaction != &kbd_cleanup_signal_action)
+        if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) {
             continue;
+        }
 
         /* Restore original action */
         sigaction(signum, old_action_p, NULL);
@@ -201,16 +204,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
         struct sigaction new_action;
         signum = fatal_signals[tabidx];   
         old_action_p = &(old_sigaction[signum]);
-        if (sigaction(signum, NULL, old_action_p))
+        if (sigaction(signum, NULL, old_action_p)) {
             continue;
+        }
 
         /* Skip SIGHUP and SIGPIPE if handler is already installed
          * - assume the handler will do the cleanup
          */
-        if ((signum == SIGHUP || signum == SIGPIPE)
-                && (old_action_p->sa_handler != SIG_DFL 
-                    || (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
+        if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
             continue;
+        }
 
         new_action = *old_action_p;
         new_action.sa_flags |= SA_SIGINFO;
@@ -230,7 +233,7 @@ SDL_EVDEV_kbd_init(void)
     SDL_zero(mData);
     mData.operation = MOUSE_HIDE;
     kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
-    if (!kbd) {
+    if (kbd == NULL) {
         return NULL;
     }
 
@@ -252,8 +255,7 @@ SDL_EVDEV_kbd_init(void)
         kbd->ledflagstate = flag_state;
     }
     
-    if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0)
-    {
+    if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0) {
         SDL_free(kbd->accents);
         kbd->accents = &accentmap_default_us_acc;
     }
@@ -261,8 +263,7 @@ SDL_EVDEV_kbd_init(void)
     if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) {
         /* Set the keyboard in XLATE mode and load the keymaps */
         ioctl(kbd->console_fd, KDSKBMODE, (unsigned long)(K_XLATE));
-        if(!SDL_EVDEV_kbd_load_keymaps(kbd))
-        {
+        if (!SDL_EVDEV_kbd_load_keymaps(kbd)) {
             SDL_free(kbd->key_map);
             kbd->key_map = &keymap_default_us_acc;
         }
@@ -274,8 +275,7 @@ SDL_EVDEV_kbd_init(void)
             ioctl(kbd->console_fd, CONS_RELKBD, 1ul);
             SDL_asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index);
             kbd->keyboard_fd = open(devicePath, O_WRONLY | O_CLOEXEC);
-            if (kbd->keyboard_fd == -1)
-            {
+            if (kbd->keyboard_fd == -1) {
                 // Give keyboard back.
                 ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
                 kbd->keyboard_fd = kbd->console_fd;
@@ -288,8 +288,7 @@ SDL_EVDEV_kbd_init(void)
                 kbd_register_emerg_cleanup(kbd);
             }
             SDL_free(devicePath);
-        }
-        else kbd->keyboard_fd = kbd->console_fd;
+        } else kbd->keyboard_fd = kbd->console_fd;
     }
 
     return kbd;
@@ -300,7 +299,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
 {
     struct mouse_info mData;
 
-    if (!kbd) {
+    if (kbd == NULL) {
         return;
     }
     SDL_zero(mData);
@@ -314,8 +313,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
         ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
 
         close(kbd->keyboard_fd);
-        if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0)
-        {
+        if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0) {
             // Give back keyboard.
             ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
         }
@@ -346,10 +344,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
         put_queue(kbd, 0xc0 | (c >> 6));
         put_queue(kbd, 0x80 | (c & 0x3f));
     } else if (c < 0x10000) {
-        if (c >= 0xD800 && c < 0xE000)
+        if (c >= 0xD800 && c < 0xE000) {
             return;
-        if (c == 0xFFFF)
+        }
+        if (c == 0xFFFF) {
             return;
+        }
         /* 1110**** 10****** 10****** */
         put_queue(kbd, 0xe0 | (c >> 12));
         put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
@@ -378,13 +378,14 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
     kbd->diacr = 0;
 
     for (i = 0; i < kbd->accents->n_accs; i++) {
-        if (kbd->accents->acc[i].accchar == d)
-        {
+        if (kbd->accents->acc[i].accchar == d) {
             for (j = 0; j < NUM_ACCENTCHARS; ++j) {
-                    if (kbd->accents->acc[i].map[j][0] == 0)        /* end of table */
+                    if (kbd->accents->acc[i].map[j][0] == 0) { /* end of table */
                             break;
-                    if (kbd->accents->acc[i].map[j][0] == ch)
+                    } 
+                    if (kbd->accents->acc[i].map[j][0] == ch) {
                             return kbd->accents->acc[i].map[j][1];
+                    }
             }
         }
     }
@@ -415,11 +416,13 @@ static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
 
 static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag)
 {
-    if (up_flag)
-        return;        /* no action, if this is a key release */
+    if (up_flag) {
+        return; /* no action, if this is a key release */
+    }
 
-    if (kbd->diacr)
+    if (kbd->diacr) {
         value = handle_diacr(kbd, value);
+    }
 
     if (kbd->dead_key_next) {
         kbd->dead_key_next = SDL_FALSE;
@@ -449,8 +452,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
          * handle the case that two shift or control
          * keys are depressed simultaneously
          */
-        if (kbd->shift_down[value])
+        if (kbd->shift_down[value]) {
             kbd->shift_down[value]--;
+        }
     } else
         kbd->shift_down[value]++;
 
@@ -476,7 +480,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
 
     key_map = *kbd->key_map;
 
-    if (!kbd) {
+    if (kbd == NULL) {
         return;
     }
 
@@ -487,10 +491,10 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
             /* These constitute unprintable language-related keys, so ignore them. */
             return;
         }
-        if (keycode > 95)
+        if (keycode > 95) {
             keycode -= 7;
-        if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8))
-        {
+        }
+        if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8)) {
             keycode += ALTGR_OFFSET;
         }
         keysym = key_map.key[keycode];
@@ -499,18 +503,21 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
     }
 
     final_key_state = kbd->shift_state & 0x7;
-    if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP))
+    if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP)) {
         final_key_state ^= 0x1;
-    if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM))
+    }
+    if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM)) {
         final_key_state ^= 0x1;
+    }
 
     map_from_key_sym = keysym.map[final_key_state];
     if ((keysym.spcl & (0x80 >> final_key_state)) || (map_from_key_sym & SPCLKEY)) {
         /* Special function.*/
         if (map_from_key_sym == 0)
             return; /* Nothing to do. */
-        if (map_from_key_sym & SPCLKEY)
+        if (map_from_key_sym & SPCLKEY) {
             map_from_key_sym &= ~SPCLKEY;
+        }
         if (map_from_key_sym >= F_ACC && map_from_key_sym <= L_ACC) {
             /* Accent function.*/
             unsigned int accent_index = map_from_key_sym - F_ACC;
@@ -524,36 +531,50 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
                 break;
             case LSHA: /* left shift + alt lock */
             case RSHA: /* right shift + alt lock */
-                if (down == 0) chg_vc_kbd_led(kbd, ALKED);
+                if (down == 0) {
+                    chg_vc_kbd_led(kbd, ALKED);
+                }
             case LSH: /* left shift */
             case RSH: /* right shift */
                 k_shift(kbd, 0, down == 0);
                 break;
             case LCTRA: /* left ctrl + alt lock */
             case RCTRA: /* right ctrl + alt lock */
-                if (down == 0) chg_vc_kbd_led(kbd, ALKED);
+                if (down == 0) {
+                    chg_vc_kbd_led(kbd, ALKED);
+                }
             case LCTR: /* left ctrl */
             case RCTR: /* right ctrl */
                 k_shift(kbd, 1, down == 0);
                 break;
             case LALTA: /* left alt + alt lock */
             case RALTA: /* right alt + alt lock */
-                if (down == 0) chg_vc_kbd_led(kbd, ALKED);
+                if (down == 0) {
+                    chg_vc_kbd_led(kbd, ALKED);
+                }
             case LALT: /* left alt */
             case RALT: /* right alt */
                 k_shift(kbd, 2, down == 0);
                 break;
             case ALK: /* alt lock */
-                if (down == 1) chg_vc_kbd_led(kbd, ALKED);
+                if (down == 1) {
+                    chg_vc_kbd_led(kbd, ALKED);
+                }
                 break;
             case CLK: /* caps lock*/
-                if (down == 1) chg_vc_kbd_led(kbd, CLKED);
+                if (down == 1) {
+                    chg_vc_kbd_led(kbd, CLKED);
+                }
                 break;
             case NLK: /* num lock */
-                if (down == 1) chg_vc_kbd_led(kbd, NLKED);
+                if (down == 1) {
+                    chg_vc_kbd_led(kbd, NLKED);
+                }
                 break;
             case SLK: /* scroll lock */
-                if (down == 1) chg_vc_kbd_led(kbd, SLKED);
+                if (down == 1) {
+                    chg_vc_kbd_led(kbd, SLKED);
+                }
                 break;
             default:
                 return;

+ 2 - 2
src/core/gdk/SDL_gdk.cpp

@@ -105,13 +105,13 @@ SDL_GDKRunApp(SDL_main_func mainFunction, void *reserved)
 
     /* Parse it into argv and argc */
     argv = (char **) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv));
-    if (!argv) {
+    if (argv == NULL) {
         return OutOfMemory();
     }
     for (i = 0; i < argc; ++i) {
         DWORD len;
         char *arg = WIN_StringToUTF8W(argvw[i]);
-        if (!arg) {
+        if (arg == NULL) {
             return OutOfMemory();
         }
         len = (DWORD) SDL_strlen(arg);

+ 15 - 10
src/core/linux/SDL_dbus.c

@@ -198,7 +198,7 @@ SDL_DBus_Quit(void)
 SDL_DBusContext *
 SDL_DBus_GetContext(void)
 {
-    if (!dbus_handle || !dbus.session_conn) {
+    if (dbus_handle == NULL || !dbus.session_conn) {
         SDL_DBus_Init();
     }
     
@@ -376,20 +376,25 @@ SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, cons
 {
     DBusMessageIter iterDict, iterEntry, iterValue;
 
-    if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict))
+    if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict)) {
         goto failed;
+    }
 
-    if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry))
+    if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry)) {
         goto failed;
+    }
 
-    if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key))
+    if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) {
         goto failed;
+    }
 
-    if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue))
+    if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue)) {
         goto failed;
+    }
 
-    if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value))
+    if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) {
         goto failed;
+    }
 
     if (!dbus.message_iter_close_container(&iterEntry, &iterValue)
         || !dbus.message_iter_close_container(&iterDict, &iterEntry)
@@ -436,12 +441,12 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
             const char *key = "reason";
             const char *reply = NULL;
             const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
-            if (!reason || !reason[0]) {
+            if (reason == NULL || !reason[0]) {
                 reason = default_inhibit_reason;
             }
 
             msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit");
-            if (!msg) {
+            if (msg == NULL) {
                 return SDL_FALSE;
             }
 
@@ -478,10 +483,10 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
         if (inhibit) {
             const char *app = SDL_GetHint(SDL_HINT_APP_NAME);
             const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
-            if (!app || !app[0]) {
+            if (app == NULL || !app[0]) {
                app  = "My SDL application";
             }
-            if (!reason || !reason[0]) {
+            if (reason == NULL || !reason[0]) {
                 reason = default_inhibit_reason;
             }
 

+ 50 - 30
src/core/linux/SDL_evdev.c

@@ -188,11 +188,11 @@ SDL_EVDEV_Init(void)
                 while ((spec = SDL_strtokr(rest, ",", &rest))) {
                     char* endofcls = 0;
                     long cls = SDL_strtol(spec, &endofcls, 0);
-                    if (endofcls)
+                    if (endofcls) {
                         SDL_EVDEV_device_added(endofcls + 1, cls);
+                    }
                 }
-            }
-            else {
+            } else {
                 /* TODO: Scan the devices manually, like a caveman */
             }
         }
@@ -226,7 +226,7 @@ SDL_EVDEV_Quit(void)
         SDL_EVDEV_kbd_quit(_this->kbd);
 
         /* Remove existing devices */
-        while(_this->first != NULL) {
+        while (_this->first != NULL) {
             SDL_EVDEV_device_removed(_this->first->path);
         }
 
@@ -249,11 +249,13 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
 
     switch(udev_event) {
     case SDL_UDEV_DEVICEADDED:
-        if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD)))
+        if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD))) {
             return;
+        }
 
-        if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK))
+        if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
             return;
+        }
 
         SDL_EVDEV_device_added(dev_path, udev_class);
         break;  
@@ -338,13 +340,15 @@ SDL_EVDEV_Poll(void)
                 case EV_ABS:
                     switch(events[i].code) {
                     case ABS_MT_SLOT:
-                        if (!item->is_touchscreen) /* FIXME: temp hack */
+                        if (!item->is_touchscreen) { /* FIXME: temp hack */
                             break;
+                        } 
                         item->touchscreen_data->current_slot = events[i].value;
                         break;
                     case ABS_MT_TRACKING_ID:
-                        if (!item->is_touchscreen) /* FIXME: temp hack */
+                        if (!item->is_touchscreen) { /* FIXME: temp hack */
                             break;
+                        }
                         if (events[i].value >= 0) {
                             item->touchscreen_data->slots[item->touchscreen_data->current_slot].tracking_id = events[i].value;
                             item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
@@ -353,24 +357,27 @@ SDL_EVDEV_Poll(void)
                         }
                         break;
                     case ABS_MT_POSITION_X:
-                        if (!item->is_touchscreen) /* FIXME: temp hack */
+                        if (!item->is_touchscreen) { /* FIXME: temp hack */
                             break;
+                        }
                         item->touchscreen_data->slots[item->touchscreen_data->current_slot].x = events[i].value;
                         if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
                             item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
                         }
                         break;
                     case ABS_MT_POSITION_Y:
-                        if (!item->is_touchscreen) /* FIXME: temp hack */
+                        if (!item->is_touchscreen) { /* FIXME: temp hack */
                             break;
+                        }
                         item->touchscreen_data->slots[item->touchscreen_data->current_slot].y = events[i].value;
                         if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
                             item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
                         }
                         break;
                     case ABS_MT_PRESSURE:
-                        if (!item->is_touchscreen) /* FIXME: temp hack */
+                        if (!item->is_touchscreen) { /* FIXME: temp hack */
                             break;
+                        }
                         item->touchscreen_data->slots[item->touchscreen_data->current_slot].pressure = events[i].value;
                         if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
                             item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
@@ -378,8 +385,9 @@ SDL_EVDEV_Poll(void)
                         break;
                     case ABS_X:
                         if (item->is_touchscreen) {
-                            if (item->touchscreen_data->max_slots != 1)
+                            if (item->touchscreen_data->max_slots != 1) {
                                 break;
+                            }
                             item->touchscreen_data->slots[0].x = events[i].value;
                         } else if (!item->relative_mouse) {
                             /* FIXME: Normalize to input device's reported input range (EVIOCGABS) */
@@ -388,8 +396,9 @@ SDL_EVDEV_Poll(void)
                         break;
                     case ABS_Y:
                         if (item->is_touchscreen) {
-                            if (item->touchscreen_data->max_slots != 1)
+                            if (item->touchscreen_data->max_slots != 1) {
                                 break;
+                            }
                             item->touchscreen_data->slots[0].y = events[i].value;
                         } else if (!item->relative_mouse) {
                             /* FIXME: Normalize to input device's reported input range (EVIOCGABS) */
@@ -403,24 +412,28 @@ SDL_EVDEV_Poll(void)
                 case EV_REL:
                     switch(events[i].code) {
                     case REL_X:
-                        if (item->relative_mouse)
+                        if (item->relative_mouse) {
                             item->mouse_x += events[i].value;
+                        }
                         break;
                     case REL_Y:
-                        if (item->relative_mouse)
+                        if (item->relative_mouse) {
                             item->mouse_y += events[i].value;
+                        }
                         break;
                     case REL_WHEEL:
-                        if (!item->high_res_wheel)
+                        if (!item->high_res_wheel) {
                             item->mouse_wheel += events[i].value;
+                        }
                         break;
                     case REL_WHEEL_HI_RES:
                         SDL_assert(item->high_res_wheel);
                         item->mouse_wheel += events[i].value;
                         break;
                     case REL_HWHEEL:
-                        if (!item->high_res_hwheel)
+                        if (!item->high_res_hwheel) {
                             item->mouse_hwheel += events[i].value;
+                        }
                         break;
                     case REL_HWHEEL_HI_RES:
                         SDL_assert(item->high_res_hwheel);
@@ -446,10 +459,11 @@ SDL_EVDEV_Poll(void)
                             item->mouse_wheel = item->mouse_hwheel = 0;
                         }
 
-                        if (!item->is_touchscreen) /* FIXME: temp hack */
+                        if (!item->is_touchscreen) { /* FIXME: temp hack */
                             break;
+                        }
 
-                        for(j = 0; j < item->touchscreen_data->max_slots; j++) {
+                        for (j = 0; j < item->touchscreen_data->max_slots; j++) {
                             norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) /
                                 (float)item->touchscreen_data->range_x;
                             norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) /
@@ -485,12 +499,14 @@ SDL_EVDEV_Poll(void)
                             }
                         }
 
-                        if (item->out_of_sync)
+                        if (item->out_of_sync) {
                             item->out_of_sync = SDL_FALSE;
+                        }
                         break;
                     case SYN_DROPPED:
-                        if (item->is_touchscreen)
+                        if (item->is_touchscreen) {
                             item->out_of_sync = SDL_TRUE;
+                        }
                         SDL_EVDEV_sync_device(item);
                         break;
                     default:
@@ -533,12 +549,14 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
     char name[64];
     struct input_absinfo abs_info;
 
-    if (!item->is_touchscreen)
+    if (!item->is_touchscreen) {
         return 0;
+    }
 
     item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data));
-    if (item->touchscreen_data == NULL)
+    if (item->touchscreen_data == NULL) {
         return SDL_OutOfMemory();
+    }
 
     ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
     if (ret < 0) {
@@ -608,7 +626,7 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
         return SDL_OutOfMemory();
     }
 
-    for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+    for (i = 0; i < item->touchscreen_data->max_slots; i++) {
         item->touchscreen_data->slots[i].tracking_id = -1;
     }
 
@@ -627,8 +645,9 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
 
 static void
 SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) {
-    if (!item->is_touchscreen)
+    if (!item->is_touchscreen) {
         return;
+    }
 
     SDL_DelTouch(item->fd);
     SDL_free(item->touchscreen_data->slots);
@@ -655,8 +674,9 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
     size_t mt_req_size;
 
     /* TODO: sync devices other than touchscreen */
-    if (!item->is_touchscreen)
+    if (!item->is_touchscreen) {
         return;
+    }
 
     mt_req_size = sizeof(*mt_req_code) +
         sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
@@ -674,7 +694,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
         SDL_free(mt_req_code);
         return;
     }
-    for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+    for (i = 0; i < item->touchscreen_data->max_slots; i++) {
         /*
          * This doesn't account for the very edge case of the user removing their
          * finger and replacing it on the screen during the time we're out of sync,
@@ -701,7 +721,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
         SDL_free(mt_req_code);
         return;
     }
-    for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+    for (i = 0; i < item->touchscreen_data->max_slots; i++) {
         if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
             item->touchscreen_data->slots[i].x != mt_req_values[i]) {
             item->touchscreen_data->slots[i].x = mt_req_values[i];
@@ -719,7 +739,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
         SDL_free(mt_req_code);
         return;
     }
-    for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+    for (i = 0; i < item->touchscreen_data->max_slots; i++) {
         if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
             item->touchscreen_data->slots[i].y != mt_req_values[i]) {
             item->touchscreen_data->slots[i].y = mt_req_values[i];
@@ -737,7 +757,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
         SDL_free(mt_req_code);
         return;
     }
-    for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+    for (i = 0; i < item->touchscreen_data->max_slots; i++) {
         if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
             item->touchscreen_data->slots[i].pressure != mt_req_values[i]) {
             item->touchscreen_data->slots[i].pressure = mt_req_values[i];

+ 2 - 1
src/core/linux/SDL_evdev_capabilities.c

@@ -138,8 +138,9 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
     /* the first 32 bits are ESC, numbers, and Q to D; if we have any of
      * those, consider it a keyboard device; do not test KEY_RESERVED, though */
     keyboard_mask = 0xFFFFFFFE;
-    if ((bitmask_key[0] & keyboard_mask) != 0)
+    if ((bitmask_key[0] & keyboard_mask) != 0) {
         devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */
+    }
 
     return devclass;
 }

+ 39 - 25
src/core/linux/SDL_evdev_kbd.c

@@ -269,13 +269,14 @@ static void kbd_unregister_emerg_cleanup()
         old_action_p = &(old_sigaction[signum]);
 
         /* Examine current signal action */
-        if (sigaction(signum, NULL, &cur_action))
+        if (sigaction(signum, NULL, &cur_action)) {
             continue;
+        }
 
         /* Check if action installed and not modifed */
-        if (!(cur_action.sa_flags & SA_SIGINFO)
-                || cur_action.sa_sigaction != &kbd_cleanup_signal_action)
+        if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) {
             continue;
+        }
 
         /* Restore original action */
         sigaction(signum, old_action_p, NULL);
@@ -319,16 +320,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
         struct sigaction new_action;
         signum = fatal_signals[tabidx];   
         old_action_p = &(old_sigaction[signum]);
-        if (sigaction(signum, NULL, old_action_p))
+        if (sigaction(signum, NULL, old_action_p)) {
             continue;
+        }
 
         /* Skip SIGHUP and SIGPIPE if handler is already installed
          * - assume the handler will do the cleanup
          */
-        if ((signum == SIGHUP || signum == SIGPIPE)
-                && (old_action_p->sa_handler != SIG_DFL 
-                    || (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
+        if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
             continue;
+        }
 
         new_action = *old_action_p;
         new_action.sa_flags |= SA_SIGINFO;
@@ -346,7 +347,7 @@ SDL_EVDEV_kbd_init(void)
     char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0};
 
     kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd));
-    if (!kbd) {
+    if (kbd == NULL) {
         return NULL;
     }
 
@@ -412,7 +413,7 @@ SDL_EVDEV_kbd_init(void)
 void
 SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
 {
-    if (!kbd) {
+    if (kbd == NULL) {
         return;
     }
 
@@ -460,10 +461,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
         put_queue(kbd, 0xc0 | (c >> 6));
         put_queue(kbd, 0x80 | (c & 0x3f));
     } else if (c < 0x10000) {
-        if (c >= 0xD800 && c < 0xE000)
+        if (c >= 0xD800 && c < 0xE000) {
             return;
-        if (c == 0xFFFF)
+        }
+        if (c == 0xFFFF) {
             return;
+        }
         /* 1110**** 10****** 10****** */
         put_queue(kbd, 0xe0 | (c >> 12));
         put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
@@ -498,8 +501,9 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
         }
     }
 
-    if (ch == ' ' || ch == d)
+    if (ch == ' ' || ch == d) {
         return d;
+    }
 
     put_utf8(kbd, d);
 
@@ -553,24 +557,27 @@ static void fn_enter(SDL_EVDEV_keyboard_state *kbd)
 
 static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd)
 {
-    if (kbd->rep)
+    if (kbd->rep) {
         return;
+    }
 
     chg_vc_kbd_led(kbd, K_CAPSLOCK);
 }
 
 static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd)
 {
-    if (kbd->rep)
+    if (kbd->rep) {
         return;
+    }
 
     set_vc_kbd_led(kbd, K_CAPSLOCK);
 }
 
 static void fn_num(SDL_EVDEV_keyboard_state *kbd)
 {
-    if (!kbd->rep)
+    if (!kbd->rep) {
         chg_vc_kbd_led(kbd, K_NUMLOCK);
+    }
 }
 
 static void fn_compose(SDL_EVDEV_keyboard_state *kbd)
@@ -588,12 +595,15 @@ static void k_ignore(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up
 
 static void k_spec(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
 {
-    if (up_flag)
+    if (up_flag) {
         return;
-    if (value >= SDL_arraysize(fn_handler))
+    }
+    if (value >= SDL_arraysize(fn_handler)) {
         return;
-    if (fn_handler[value])
+    }
+    if (fn_handler[value]) {
         fn_handler[value](kbd);
+    }
 }
 
 static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
@@ -602,11 +612,13 @@ static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char
 
 static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
 {
-    if (up_flag)
-        return;        /* no action, if this is a key release */
+    if (up_flag) {
+        return; /* no action, if this is a key release */
+    } 
 
-    if (kbd->diacr)
+    if (kbd->diacr) {
         value = handle_diacr(kbd, value);
+    }
 
     if (kbd->dead_key_next) {
         kbd->dead_key_next = SDL_FALSE;
@@ -675,8 +687,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
      */
     if (value == KVAL(K_CAPSSHIFT)) {
         value = KVAL(K_SHIFT);
-        if (!up_flag)
+        if (!up_flag) {
             clr_vc_kbd_led(kbd, K_CAPSLOCK);
+        }
     }
 
     if (up_flag) {
@@ -684,8 +697,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
          * handle the case that two shift or control
          * keys are depressed simultaneously
          */
-        if (kbd->shift_down[value])
+        if (kbd->shift_down[value]) {
             kbd->shift_down[value]--;
+        }
     } else
         kbd->shift_down[value]++;
 
@@ -761,7 +775,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
     unsigned short *key_map;
     unsigned short keysym;
 
-    if (!kbd) {
+    if (kbd == NULL) {
         return;
     }
 
@@ -769,7 +783,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
 
     shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate;
     key_map = kbd->key_maps[shift_final];
-    if (!key_map) {
+    if (key_map == NULL) {
         /* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */
         kbd->shift_state = 0;
         kbd->slockstate = 0;

+ 25 - 9
src/core/linux/SDL_fcitx.c

@@ -347,14 +347,30 @@ Fcitx_ModState(void)
     Uint32 fcitx_mods = 0;
     SDL_Keymod sdl_mods = SDL_GetModState();
 
-    if (sdl_mods & KMOD_SHIFT) fcitx_mods |= (1 << 0);
-    if (sdl_mods & KMOD_CAPS)   fcitx_mods |= (1 << 1);
-    if (sdl_mods & KMOD_CTRL)  fcitx_mods |= (1 << 2);
-    if (sdl_mods & KMOD_ALT)   fcitx_mods |= (1 << 3);
-    if (sdl_mods & KMOD_NUM)    fcitx_mods |= (1 << 4);
-    if (sdl_mods & KMOD_MODE)   fcitx_mods |= (1 << 7);
-    if (sdl_mods & KMOD_LGUI)   fcitx_mods |= (1 << 6);
-    if (sdl_mods & KMOD_RGUI)   fcitx_mods |= (1 << 28);
+    if (sdl_mods & KMOD_SHIFT) {
+        fcitx_mods |= (1 << 0);
+    }
+    if (sdl_mods & KMOD_CAPS) {
+        fcitx_mods |= (1 << 1);
+    }
+    if (sdl_mods & KMOD_CTRL) {
+        fcitx_mods |= (1 << 2);
+    }
+    if (sdl_mods & KMOD_ALT) {
+        fcitx_mods |= (1 << 3);
+    }
+    if (sdl_mods & KMOD_NUM) {
+        fcitx_mods |= (1 << 4);
+    }
+    if (sdl_mods & KMOD_MODE) {
+        fcitx_mods |= (1 << 7);
+    }
+    if (sdl_mods & KMOD_LGUI) {
+        fcitx_mods |= (1 << 6);
+    }
+    if (sdl_mods & KMOD_RGUI) {
+        fcitx_mods |= (1 << 28);
+    }
 
     return fcitx_mods;
 }
@@ -436,7 +452,7 @@ SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
     }
 
     focused_win = SDL_GetKeyboardFocus();
-    if (!focused_win) {
+    if (focused_win == NULL) {
         return ;
     }
 

+ 48 - 25
src/core/linux/SDL_ibus.c

@@ -64,14 +64,30 @@ IBus_ModState(void)
     SDL_Keymod sdl_mods = SDL_GetModState();
     
     /* Not sure about MOD3, MOD4 and HYPER mappings */
-    if (sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK;
-    if (sdl_mods & KMOD_CAPS)   ibus_mods |= IBUS_LOCK_MASK;
-    if (sdl_mods & KMOD_LCTRL)  ibus_mods |= IBUS_CONTROL_MASK;
-    if (sdl_mods & KMOD_LALT)   ibus_mods |= IBUS_MOD1_MASK;
-    if (sdl_mods & KMOD_NUM)    ibus_mods |= IBUS_MOD2_MASK;
-    if (sdl_mods & KMOD_MODE)   ibus_mods |= IBUS_MOD5_MASK;
-    if (sdl_mods & KMOD_LGUI)   ibus_mods |= IBUS_SUPER_MASK;
-    if (sdl_mods & KMOD_RGUI)   ibus_mods |= IBUS_META_MASK;
+    if (sdl_mods & KMOD_LSHIFT) {
+        ibus_mods |= IBUS_SHIFT_MASK;
+    }
+    if (sdl_mods & KMOD_CAPS) {
+        ibus_mods |= IBUS_LOCK_MASK;
+    }
+    if (sdl_mods & KMOD_LCTRL) {
+        ibus_mods |= IBUS_CONTROL_MASK;
+    }
+    if (sdl_mods & KMOD_LALT) {
+        ibus_mods |= IBUS_MOD1_MASK;
+    }
+    if (sdl_mods & KMOD_NUM) {
+        ibus_mods |= IBUS_MOD2_MASK;
+    }
+    if (sdl_mods & KMOD_MODE) {
+        ibus_mods |= IBUS_MOD5_MASK;
+    }
+    if (sdl_mods & KMOD_LGUI) {
+        ibus_mods |= IBUS_SUPER_MASK;
+    }
+    if (sdl_mods & KMOD_RGUI) {
+        ibus_mods |= IBUS_META_MASK;
+    }
 
     return ibus_mods;
 }
@@ -98,7 +114,7 @@ IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *
     }
 
     dbus->message_iter_get_basic(inside, &struct_id);
-    if (!struct_id || SDL_strncmp(struct_id, struct_id, id_size) != 0) {
+    if (struct_id == NULL || SDL_strncmp(struct_id, struct_id, id_size) != 0) {
         return SDL_FALSE;
     }
     return SDL_TRUE;
@@ -248,13 +264,12 @@ IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
 
                 dbus->message_iter_init(msg, &iter);
                 has_dec_pos = IBus_GetDecorationPosition(conn, &iter, dbus, &start_pos, &end_pos);
-                if (!has_dec_pos)
-                {
+                if (!has_dec_pos) {
                     dbus->message_iter_init(msg, &iter);
                     has_pos = IBus_GetVariantCursorPos(conn, &iter, dbus, &pos);
                 }
 
-                if(has_dec_pos) {
+                if (has_dec_pos) {
                     SDL_SendEditingText(text, start_pos, end_pos - start_pos);
                 } else if (has_pos) {
                     SDL_SendEditingText(text, pos, -1);
@@ -298,15 +313,19 @@ IBus_ReadAddressFromFile(const char *file_path)
     FILE *addr_file;
 
     addr_file = fopen(file_path, "r");
-    if (!addr_file) {
+    if (addr_file == NULL) {
         return NULL;
     }
 
     while (fgets(addr_buf, sizeof(addr_buf), addr_file)) {
         if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) {
             size_t sz = SDL_strlen(addr_buf);
-            if (addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0;
-            if (addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0;
+            if (addr_buf[sz - 1] == '\n') {
+                addr_buf[sz - 1] = 0;
+            }
+            if (addr_buf[sz - 2] == '\r') {
+                addr_buf[sz - 2] = 0;
+            }
             success = SDL_TRUE;
             break;
         }
@@ -340,7 +359,7 @@ IBus_GetDBusAddressFilename(void)
     }
     
     dbus = SDL_DBus_GetContext();
-    if (!dbus) {
+    if (dbus == NULL) {
         return NULL;
     }
     
@@ -354,7 +373,7 @@ IBus_GetDBusAddressFilename(void)
        and look up the address from a filepath using all those bits, eek. */
     disp_env = SDL_getenv("DISPLAY");
 
-    if (!disp_env || !*disp_env) {
+    if (disp_env == NULL || !*disp_env) {
         display = SDL_strdup(":0.0");
     } else {
         display = SDL_strdup(disp_env);
@@ -364,7 +383,7 @@ IBus_GetDBusAddressFilename(void)
     disp_num   = SDL_strrchr(display, ':');
     screen_num = SDL_strrchr(display, '.');
     
-    if (!disp_num) {
+    if (disp_num == NULL) {
         SDL_free(display);
         return NULL;
     }
@@ -392,7 +411,7 @@ IBus_GetDBusAddressFilename(void)
         SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
     } else {
         const char *home_env = SDL_getenv("HOME");
-        if (!home_env || !*home_env) {
+        if (home_env == NULL || !*home_env) {
             SDL_free(display);
             return NULL;
         }
@@ -460,7 +479,7 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
         ibus_input_interface = IBUS_INPUT_INTERFACE;
         ibus_conn = dbus->connection_open_private(addr, NULL);
 
-        if (!ibus_conn) {
+        if (ibus_conn == NULL) {
             return SDL_FALSE;  /* oh well. */
         }
 
@@ -498,7 +517,9 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
 static SDL_bool
 IBus_CheckConnection(SDL_DBusContext *dbus)
 {
-    if (!dbus) return SDL_FALSE;
+    if (dbus == NULL) {
+        return SDL_FALSE;
+    }
     
     if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) {
         return SDL_TRUE;
@@ -516,7 +537,9 @@ IBus_CheckConnection(SDL_DBusContext *dbus)
                 struct inotify_event *event = (struct inotify_event*) p;
                 if (event->len > 0) {
                     char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
-                    if (!addr_file_no_path) return SDL_FALSE;
+                    if (addr_file_no_path == NULL) {
+                        return SDL_FALSE;
+                    }
                  
                     if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) {
                         file_updated = SDL_TRUE;
@@ -552,7 +575,7 @@ SDL_IBus_Init(void)
         char *addr;
         char *addr_file_dir;
 
-        if (!addr_file) {
+        if (addr_file == NULL) {
             return SDL_FALSE;
         }
         
@@ -560,7 +583,7 @@ SDL_IBus_Init(void)
         ibus_addr_file = SDL_strdup(addr_file);
         
         addr = IBus_ReadAddressFromFile(addr_file);
-        if (!addr) {
+        if (addr == NULL) {
             SDL_free(addr_file);
             return SDL_FALSE;
         }
@@ -699,7 +722,7 @@ SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
     }
 
     focused_win = SDL_GetKeyboardFocus();
-    if (!focused_win) {
+    if (focused_win == NULL) {
         return;
     }
 

+ 17 - 10
src/core/linux/SDL_ime.c

@@ -49,16 +49,17 @@ InitIME()
     const char *xmodifiers = SDL_getenv("XMODIFIERS");
 #endif
 
-    if (inited == SDL_TRUE)
+    if (inited == SDL_TRUE) {
         return;
+    }
 
     inited = SDL_TRUE;
 
     /* See if fcitx IME support is being requested */
 #ifdef HAVE_FCITX
-    if (!SDL_IME_Init_Real &&
+    if (SDL_IME_Init_Real == NULL &&
         ((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
-         (!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
+         (im_module == NULL && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
         SDL_IME_Init_Real = SDL_Fcitx_Init;
         SDL_IME_Quit_Real = SDL_Fcitx_Quit;
         SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
@@ -71,7 +72,7 @@ InitIME()
 
     /* default to IBus */
 #ifdef HAVE_IBUS_IBUS_H
-    if (!SDL_IME_Init_Real) {
+    if (SDL_IME_Init_Real == NULL) {
         SDL_IME_Init_Real = SDL_IBus_Init;
         SDL_IME_Quit_Real = SDL_IBus_Quit;
         SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
@@ -109,29 +110,33 @@ SDL_IME_Init(void)
 void
 SDL_IME_Quit(void)
 {
-    if (SDL_IME_Quit_Real)
+    if (SDL_IME_Quit_Real) {
         SDL_IME_Quit_Real();
+    }
 }
 
 void
 SDL_IME_SetFocus(SDL_bool focused)
 {
-    if (SDL_IME_SetFocus_Real)
+    if (SDL_IME_SetFocus_Real) {
         SDL_IME_SetFocus_Real(focused);
+    }
 }
 
 void
 SDL_IME_Reset(void)
 {
-    if (SDL_IME_Reset_Real)
+    if (SDL_IME_Reset_Real) {
         SDL_IME_Reset_Real();
+    }
 }
 
 SDL_bool
 SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
 {
-    if (SDL_IME_ProcessKeyEvent_Real)
+    if (SDL_IME_ProcessKeyEvent_Real) {
         return SDL_IME_ProcessKeyEvent_Real(keysym, keycode, state);
+    }
 
     return SDL_FALSE;
 }
@@ -139,15 +144,17 @@ SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
 void
 SDL_IME_UpdateTextRect(const SDL_Rect *rect)
 {
-    if (SDL_IME_UpdateTextRect_Real)
+    if (SDL_IME_UpdateTextRect_Real) {
         SDL_IME_UpdateTextRect_Real(rect);
+    }
 }
 
 void
 SDL_IME_PumpEvents()
 {
-    if (SDL_IME_PumpEvents_Real)
+    if (SDL_IME_PumpEvents_Real) {
         SDL_IME_PumpEvents_Real();
+    }
 }
 
 /* vi: set ts=4 sw=4 expandtab: */

+ 22 - 24
src/core/linux/SDL_threadprio.c

@@ -116,20 +116,20 @@ rtkit_initialize()
     dbus_conn = get_rtkit_dbus_connection();
 
     /* Try getting minimum nice level: this is often greater than PRIO_MIN (-20). */
-    if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
-                                            DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
+    if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
+                                                                 DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
         rtkit_min_nice_level = -20;
     }
 
     /* Try getting maximum realtime priority: this can be less than the POSIX default (99). */
-    if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
-                                            DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
+    if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
+                                                                 DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
         rtkit_max_realtime_priority = 99;
     }
 
     /* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */
-    if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
-                                            DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
+    if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
+                                                                 DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
         rtkit_max_rttime_usec = 200000;
     }
 }
@@ -168,8 +168,7 @@ rtkit_initialize_realtime_thread()
 
     // Requirement #1: Set RLIMIT_RTTIME
     err = getrlimit(nLimit, &rlimit);
-    if (err)
-    {
+    if (err) {
         return SDL_FALSE;
     }
 
@@ -177,21 +176,18 @@ rtkit_initialize_realtime_thread()
     rlimit.rlim_max = rtkit_max_rttime_usec;
     rlimit.rlim_cur = rlimit.rlim_max / 2;
     err = setrlimit(nLimit, &rlimit);
-    if (err)
-    {
+    if (err) {
         return SDL_FALSE;
     }
 
     // Requirement #2: Add SCHED_RESET_ON_FORK to the scheduler policy
     err = sched_getparam(nPid, &schedParam);
-    if (err)
-    {
+    if (err) {
         return SDL_FALSE;
     }
 
     err = sched_setscheduler(nPid, nSchedPolicy, &schedParam);
-    if (err)
-    {
+    if (err) {
         return SDL_FALSE;
     }
 
@@ -209,13 +205,14 @@ rtkit_setpriority_nice(pid_t thread, int nice_level)
     pthread_once(&rtkit_initialize_once, rtkit_initialize);
     dbus_conn = get_rtkit_dbus_connection();
 
-    if (nice < rtkit_min_nice_level)
+    if (nice < rtkit_min_nice_level) {
         nice = rtkit_min_nice_level;
+    }
 
-    if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
-            rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
-            DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
-            DBUS_TYPE_INVALID)) {
+    if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
+                                                              rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
+                                                              DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
+                                                              DBUS_TYPE_INVALID)) {
         return SDL_FALSE;
     }
     return SDL_TRUE;
@@ -232,8 +229,9 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
     pthread_once(&rtkit_initialize_once, rtkit_initialize);
     dbus_conn = get_rtkit_dbus_connection();
 
-    if (priority > rtkit_max_realtime_priority)
+    if (priority > rtkit_max_realtime_priority) {
         priority = rtkit_max_realtime_priority;
+    }
 
     // We always perform the thread state changes necessary for rtkit.
     // This wastes some system calls if the state is already set but
@@ -243,10 +241,10 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
     // go through to determine whether it really needs to fail or not.
     rtkit_initialize_realtime_thread();
 
-    if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
-            rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
-            DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
-            DBUS_TYPE_INVALID)) {
+    if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
+                                                              rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
+                                                              DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
+                                                              DBUS_TYPE_INVALID)) {
         return SDL_FALSE;
     }
     return SDL_TRUE;

+ 5 - 6
src/core/linux/SDL_udev.c

@@ -115,7 +115,7 @@ SDL_UDEV_Init(void)
 
     if (_this == NULL) {
         _this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
-        if(_this == NULL) {
+        if (_this == NULL) {
             return SDL_OutOfMemory();
         }
 
@@ -323,14 +323,13 @@ SDL_UDEV_LoadLibrary(void)
 #endif
 
     if (_this->udev_handle == NULL) {
-        for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
+        for ( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
             _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
             if (_this->udev_handle != NULL) {
                 retval = SDL_UDEV_load_syms();
                 if (retval < 0) {
                     SDL_UDEV_UnloadLibrary();
-                }
-                else {
+                } else {
                     break;
                 }
             }
@@ -355,7 +354,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
 
     SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
     value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
-    if (!value) {
+    if (value == NULL) {
         return;
     }
 
@@ -390,7 +389,7 @@ guess_device_class(struct udev_device *dev)
     while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) {
         pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
     }
-    if (!pdev) {
+    if (pdev == NULL) {
         return 0;
     }
 

+ 110 - 45
src/core/openbsd/SDL_wscons_kbd.c

@@ -229,14 +229,15 @@ static struct SDL_wscons_compose_tab_s {
 
 static keysym_t ksym_upcase(keysym_t ksym)
 {
-    if (ksym >= KS_f1 && ksym <= KS_f20)
-        return(KS_F1 - KS_f1 + ksym);
+    if (ksym >= KS_f1 && ksym <= KS_f20) {
+        return KS_F1 - KS_f1 + ksym;
+    }
 
-    if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff &&
-            latin1_to_upper[ksym] != 0x00)
-        return(latin1_to_upper[ksym]);
+    if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff && latin1_to_upper[ksym] != 0x00) {
+        return latin1_to_upper[ksym];
+    }
 
-    return(ksym);
+    return ksym;
 }
 static struct wscons_keycode_to_SDL {
     keysym_t sourcekey;
@@ -410,7 +411,7 @@ static SDL_WSCONS_input_data* SDL_WSCONS_Init_Keyboard(const char* dev)
 #endif
     SDL_WSCONS_input_data* input = (SDL_WSCONS_input_data*)SDL_calloc(1, sizeof(SDL_WSCONS_input_data));
 
-    if (!input) {
+    if (input == NULL) {
         return input;
     }
     input->fd = open(dev,O_RDWR | O_NONBLOCK | O_CLOEXEC);
@@ -487,10 +488,12 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
         put_queue(input, 0xc0 | (c >> 6));
         put_queue(input, 0x80 | (c & 0x3f));
     } else if (c < 0x10000) {
-        if (c >= 0xD800 && c <= 0xF500)
+        if (c >= 0xD800 && c <= 0xF500) {
             return;
-        if (c == 0xFFFF)
+        }
+        if (c == 0xFFFF) {
             return;
+        }
         /* 1110**** 10****** 10****** */
         put_queue(input, 0xe0 | (c >> 12));
         put_queue(input, 0x80 | ((c >> 6) & 0x3f));
@@ -507,7 +510,9 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
 static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym)
 {
     if (KS_GROUP(ksym) == KS_GROUP_Keypad) {
-        if (SDL_isprint(ksym & 0xFF)) ksym &= 0xFF;
+        if (SDL_isprint(ksym & 0xFF)) {
+            ksym &= 0xFF;
+        }
     }
     switch(ksym) {
     case KS_Escape:
@@ -565,7 +570,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
     keysym_t *group;
     keysym_t ksym, result;
 
-    if (!input) return;
+    if (input == NULL) {
+        return;
+    }
     if ((n = read(input->fd, events, sizeof(events))) > 0) {
         n /= sizeof(struct wscons_event);
         for (i = 0; i < n; i++) {
@@ -574,21 +581,27 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
             case WSCONS_EVENT_KEY_DOWN: {
                 switch (input->keymap.map[events[i].value].group1[0]) {
                 case KS_Hold_Screen: {
-                    if (input->lockheldstate[0] >= 1) break;
+                    if (input->lockheldstate[0] >= 1) {
+                                break;
+                    }
                     input->ledstate ^= LED_SCR;
                     ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
                     input->lockheldstate[0] = 1;
                     break;
                 }
                 case KS_Num_Lock: {
-                    if (input->lockheldstate[1] >= 1) break;
+                    if (input->lockheldstate[1] >= 1) {
+                                break;
+                    }
                     input->ledstate ^= LED_NUM;
                     ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
                     input->lockheldstate[1] = 1;
                     break;
                 }
                 case KS_Caps_Lock: {
-                    if (input->lockheldstate[2] >= 1) break;
+                    if (input->lockheldstate[2] >= 1) {
+                                break;
+                    }
                     input->ledstate ^= LED_CAP;
                     ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
                     input->lockheldstate[2] = 1;
@@ -596,7 +609,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
                 }
 #ifndef __NetBSD__
                 case KS_Mode_Lock: {
-                    if (input->lockheldstate[3] >= 1) break;
+                    if (input->lockheldstate[3] >= 1) {
+                                break;
+                    }
                     input->ledstate ^= 1 << 4;
                     ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
                     input->lockheldstate[3] = 1;
@@ -604,50 +619,66 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
                 }
 #endif
                 case KS_Shift_Lock: {
-                    if (input->lockheldstate[4] >= 1) break;
+                    if (input->lockheldstate[4] >= 1) {
+                                break;
+                    }
                     input->ledstate ^= 1 << 5;
                     ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
                     input->lockheldstate[4] = 1;
                     break;
                 }
                 case KS_Shift_L: {
-                    if (input->shiftheldstate[0]) break;
+                    if (input->shiftheldstate[0]) {
+                                break;
+                    }
                     input->shiftstate[0]++;
                     input->shiftheldstate[0] = 1;
                     break;
                 }
                 case KS_Shift_R: {
-                    if (input->shiftheldstate[1]) break;
+                    if (input->shiftheldstate[1]) {
+                                break;
+                    }
                     input->shiftstate[0]++;
                     input->shiftheldstate[1] = 1;
                     break;
                 }
                 case KS_Alt_L: {
-                    if (input->shiftheldstate[2]) break;
+                    if (input->shiftheldstate[2]) {
+                                break;
+                    }
                     input->shiftstate[1]++;
                     input->shiftheldstate[2] = 1;
                     break;
                 }
                 case KS_Alt_R: {
-                    if (input->shiftheldstate[3]) break;
+                    if (input->shiftheldstate[3]) {
+                                break;
+                    }
                     input->shiftstate[1]++;
                     input->shiftheldstate[3] = 1;
                     break;
                 }
                 case KS_Control_L: {
-                    if (input->shiftheldstate[4]) break;
+                    if (input->shiftheldstate[4]) {
+                                break;
+                    }
                     input->shiftstate[2]++;
                     input->shiftheldstate[4] = 1;
                     break;
                 }
                 case KS_Control_R: {
-                    if (input->shiftheldstate[5]) break;
+                    if (input->shiftheldstate[5]) {
+                                break;
+                    }
                     input->shiftstate[2]++;
                     input->shiftheldstate[5] = 1;
                     break;
                 }
                 case KS_Mode_switch: {
-                    if (input->shiftheldstate[6]) break;
+                    if (input->shiftheldstate[6]) {
+                                break;
+                    }
                     input->shiftstate[3]++;
                     input->shiftheldstate[6] = 1;
                     break;
@@ -658,60 +689,84 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
             case WSCONS_EVENT_KEY_UP: {
                 switch(input->keymap.map[events[i].value].group1[0]) {
                 case KS_Hold_Screen: {
-                    if (input->lockheldstate[0]) input->lockheldstate[0] = 0;
+                    if (input->lockheldstate[0]) {
+                                input->lockheldstate[0] = 0;
+                    }
                 }
                 break;
                 case KS_Num_Lock: {
-                    if (input->lockheldstate[1]) input->lockheldstate[1] = 0;
+                    if (input->lockheldstate[1]) {
+                                input->lockheldstate[1] = 0;
+                    }
                 }
                 break;
                 case KS_Caps_Lock: {
-                    if (input->lockheldstate[2]) input->lockheldstate[2] = 0;
+                    if (input->lockheldstate[2]) {
+                                input->lockheldstate[2] = 0;
+                    }
                 }
                 break;
 #ifndef __NetBSD__
                 case KS_Mode_Lock: {
-                    if (input->lockheldstate[3]) input->lockheldstate[3] = 0;
+                    if (input->lockheldstate[3]) {
+                                input->lockheldstate[3] = 0;
+                    }
                 }
                 break;
 #endif
                 case KS_Shift_Lock: {
-                    if (input->lockheldstate[4]) input->lockheldstate[4] = 0;
+                    if (input->lockheldstate[4]) {
+                                input->lockheldstate[4] = 0;
+                    }
                 }
                 break;
                 case KS_Shift_L: {
                     input->shiftheldstate[0] = 0;
-                    if (input->shiftstate[0]) input->shiftstate[0]--;
+                    if (input->shiftstate[0]) {
+                                input->shiftstate[0]--;
+                    }
                     break;
                 }
                 case KS_Shift_R: {
                     input->shiftheldstate[1] = 0;
-                    if (input->shiftstate[0]) input->shiftstate[0]--;
+                    if (input->shiftstate[0]) {
+                                input->shiftstate[0]--;
+                    }
                     break;
                 }
                 case KS_Alt_L: {
                     input->shiftheldstate[2] = 0;
-                    if (input->shiftstate[1]) input->shiftstate[1]--;
+                    if (input->shiftstate[1]) {
+                                input->shiftstate[1]--;
+                    }
                     break;
                 }
                 case KS_Alt_R: {
                     input->shiftheldstate[3] = 0;
-                    if (input->shiftstate[1]) input->shiftstate[1]--;
+                    if (input->shiftstate[1]) {
+                                input->shiftstate[1]--;
+                    }
                     break;
                 }
                 case KS_Control_L: {
                     input->shiftheldstate[4] = 0;
-                    if (input->shiftstate[2]) input->shiftstate[2]--;
+                    if (input->shiftstate[2]) {
+                                input->shiftstate[2]--;
+                    }
                     break;
                 }
                 case KS_Control_R: {
                     input->shiftheldstate[5] = 0;
-                    if (input->shiftstate[2]) input->shiftstate[2]--;
+                    if (input->shiftstate[2]) {
+                                input->shiftstate[2]--;
+                    }
                     break;
                 }
                 case KS_Mode_switch: {
                     input->shiftheldstate[6] = 0;
-                    if (input->shiftstate[3]) input->shiftstate[3]--;
+                    if (input->shiftstate[3]) {
+                                input->shiftstate[3]--;
+                    }
                     break;
                 }
                 }
@@ -729,7 +784,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
             else 
                 Translate_to_keycode(input, type, events[i].value);
 
-            if (type == WSCONS_EVENT_KEY_UP) continue;
+            if (type == WSCONS_EVENT_KEY_UP) {
+                continue;
+            }
 
             if (IS_ALTGR_MODE && !IS_CONTROL_HELD)
                 group = &input->keymap.map[events[i].value].group2[0];
@@ -774,7 +831,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
                 } else result = ksym;
                 break;
             }
-            if (result == KS_voidSymbol) continue;
+            if (result == KS_voidSymbol) {
+                continue;
+            }
 
             if (input->composelen > 0) {
                 if (input->composelen == 2 && group == &input->keymap.map[events[i].value].group2[0]) {
@@ -805,21 +864,24 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
 
             if (KS_GROUP(result) == KS_GROUP_Ascii) {
                 if (IS_CONTROL_HELD) {
-                    if ((result >= KS_at && result <= KS_z) || result == KS_space)
+                    if ((result >= KS_at && result <= KS_z) || result == KS_space) {
                         result = result & 0x1f;
-                    else if (result == KS_2)
+                    } else if (result == KS_2) {
                         result = 0x00;
-                    else if (result >= KS_3 && result <= KS_7)
+                    } else if (result >= KS_3 && result <= KS_7) {
                         result = KS_Escape + (result - KS_3);
-                    else if (result == KS_8)
-                        result = KS_Delete;
+                    } else if (result == KS_8) {
+                       result = KS_Delete;
+                    }
                 }
                 if (IS_ALT_HELD) {
                     if (input->encoding & KB_METAESC) {
                         Translate_to_keycode(input, WSCONS_EVENT_KEY_DOWN, KS_Escape);
                         Translate_to_text(input, result);
                         continue;
-                    } else result |= 0x80;
+                    } else {
+                       result |= 0x80;
+                    }
                 }
             }
             Translate_to_text(input,result);
@@ -831,7 +893,10 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
 void SDL_WSCONS_PumpEvents()
 {
     int i = 0;
-    for (i = 0; i < 4; i++)
+    for (i = 0; i < 4; i++) {
         updateKeyboard(inputs[i]);
-    if (mouseInputData != NULL) updateMouse(mouseInputData);
+    }
+    if (mouseInputData != NULL) {
+        updateMouse(mouseInputData);
+    }
 }

+ 8 - 6
src/core/openbsd/SDL_wscons_mouse.c

@@ -41,7 +41,9 @@ SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse()
 #endif
     SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data));
 
-    if (!mouseInputData) return NULL;
+    if (mouseInputData == NULL) {
+        return NULL;
+    }
     mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK | O_CLOEXEC);
     if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; }
 #ifdef WSMOUSEIO_SETMODE
@@ -60,11 +62,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
     int n,i;
     SDL_Mouse* mouse = SDL_GetMouse();
 
-    if ((n = read(inputData->fd, events, sizeof(events))) > 0)
-    {
+    if ((n = read(inputData->fd, events, sizeof(events))) > 0) {
         n /= sizeof(struct wscons_event);
-        for (i = 0; i < n; i++)
-        {
+        for (i = 0; i < n; i++) {
             type = events[i].type;
             switch(type)
             {
@@ -127,7 +127,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
 
 void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data* inputData)
 {
-    if (!inputData) return;
+    if (inputData == NULL) {
+        return;
+    }
     close(inputData->fd);
     free(inputData);
 }

+ 3 - 3
src/core/windows/SDL_hid.c

@@ -61,9 +61,9 @@ WIN_LoadHIDDLL(void)
     SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps");
     SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength");
     SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData");
-    if (!SDL_HidD_GetManufacturerString || !SDL_HidD_GetProductString ||
-        !SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps ||
-        !SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) {
+    if (SDL_HidD_GetManufacturerString == NULL || SDL_HidD_GetProductString == NULL ||
+        SDL_HidP_GetCaps == NULL || SDL_HidP_GetButtonCaps == NULL ||
+        SDL_HidP_GetValueCaps == NULL || SDL_HidP_MaxDataListLength == NULL || SDL_HidP_GetData == NULL) {
         WIN_UnloadHIDDLL();
         return -1;
     }

+ 2 - 2
src/core/windows/SDL_immdevice.c

@@ -136,7 +136,7 @@ SDL_IMMDevice_Add(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTEN
     }
 
     devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist));
-    if (!devidlist) {
+    if (devidlist == NULL) {
         return;  /* oh well. */
     }
 
@@ -442,7 +442,7 @@ EnumerateEndpointsForFlow(const SDL_bool iscapture)
     }
 
     items = (EndpointItem *)SDL_calloc(total, sizeof(EndpointItem));
-    if (!items) {
+    if (items == NULL) {
         return;  /* oh well. */
     }
 

+ 3 - 3
src/core/windows/SDL_windows.c

@@ -290,7 +290,7 @@ WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
     }
 
     strw = (WCHAR *) SDL_malloc(len + sizeof (WCHAR));
-    if (!strw) {
+    if (strw == NULL) {
         RegCloseKey(hkey);
         return WIN_StringToUTF8(name);  /* oh well. */
     }
@@ -313,13 +313,13 @@ WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
 BOOL
 WIN_IsEqualGUID(const GUID * a, const GUID * b)
 {
-    return (SDL_memcmp(a, b, sizeof (*a)) == 0);
+    return SDL_memcmp(a, b, sizeof(*a)) == 0;
 }
 
 BOOL
 WIN_IsEqualIID(REFIID a, REFIID b)
 {
-    return (SDL_memcmp(a, b, sizeof (*a)) == 0);
+    return SDL_memcmp(a, b, sizeof(*a)) == 0;
 }
 
 void

+ 2 - 2
src/core/windows/SDL_xinput.c

@@ -110,13 +110,13 @@ WIN_LoadXInputDLL(void)
 
     /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */
     SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, (LPCSTR)100);
-    if (!SDL_XInputGetState) {
+    if (SDL_XInputGetState == NULL) {
         SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetState");
     }
     SDL_XInputSetState = (XInputSetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputSetState");
     SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetCapabilities");
     SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetBatteryInformation" );
-    if (!SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities) {
+    if (SDL_XInputGetState == NULL || SDL_XInputSetState == NULL || SDL_XInputGetCapabilities == NULL) {
         WIN_UnloadXInputDLL();
         return -1;
     }

+ 3 - 8
src/core/winrt/SDL_winrtapp_common.cpp

@@ -47,16 +47,11 @@ SDL_WinRTGetDeviceFamily()
 #if NTDDI_VERSION >= NTDDI_WIN10  /* !!! FIXME: I have no idea if this is the right test. This is a UWP API, I think. Older windows should...just return "mobile"? I don't know. --ryan. */
     Platform::String^ deviceFamily = Windows::System::Profile::AnalyticsInfo::VersionInfo->DeviceFamily;
 
-    if (deviceFamily->Equals("Windows.Desktop"))
-    {
+    if (deviceFamily->Equals("Windows.Desktop")) {
         return SDL_WINRT_DEVICEFAMILY_DESKTOP;
-    }
-    else if (deviceFamily->Equals("Windows.Mobile"))
-    {
+    } else if (deviceFamily->Equals("Windows.Mobile")) {
         return SDL_WINRT_DEVICEFAMILY_MOBILE;
-    }
-    else if (deviceFamily->Equals("Windows.Xbox"))
-    {
+    } else if (deviceFamily->Equals("Windows.Xbox")) {
         return SDL_WINRT_DEVICEFAMILY_XBOX;
     }
 #endif

+ 3 - 5
src/core/winrt/SDL_winrtapp_direct3d.cpp

@@ -99,8 +99,7 @@ IFrameworkView^ SDLApplicationSource::CreateView()
     // SDL_WinRTGlobalApp more than once.
     SDL_assert(!SDL_WinRTGlobalApp);
     SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
-    if (!SDL_WinRTGlobalApp)
-    {
+    if (!SDL_WinRTGlobalApp) {
         SDL_WinRTGlobalApp = app;
     }
     return app;
@@ -348,13 +347,12 @@ void SDL_WinRTApp::Load(Platform::String^ entryPoint)
 void SDL_WinRTApp::Run()
 {
     SDL_SetMainReady();
-    if (WINRT_SDLAppEntryPoint)
-    {
+    if (WINRT_SDLAppEntryPoint) {
         // TODO, WinRT: pass the C-style main() a reasonably realistic
         // representation of command line arguments.
         int argc = 1;
         char **argv = (char **)SDL_malloc(2 * sizeof(*argv));
-        if (!argv) {
+        if (argv == NULL) {
             return;
         }
         argv[0] = SDL_strdup("WinRTApp");

+ 21 - 20
src/cpuinfo/SDL_cpuinfo.c

@@ -320,8 +320,9 @@ CPU_haveAltiVec(void)
     int hasVectorUnit = 0;
     size_t length = sizeof(hasVectorUnit);
     int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
-    if (0 == error)
+    if (0 == error) {
         altivec = (hasVectorUnit != 0);
+    }
 #elif defined(__FreeBSD__) && defined(__powerpc__)
     unsigned long cpufeatures = 0;
     elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
@@ -362,13 +363,10 @@ CPU_haveARMSIMD(void)
     int fd;
 
     fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
-    if (fd >= 0)
-    {
+    if (fd >= 0) {
         Elf32_auxv_t aux;
-        while (read(fd, &aux, sizeof aux) == sizeof aux)
-        {
-            if (aux.a_type == AT_PLATFORM)
-            {
+        while (read(fd, &aux, sizeof aux) == sizeof aux) {
+            if (aux.a_type == AT_PLATFORM) {
                 const char *plat = (const char *) aux.a_un.a_val;
                 if (plat) {
                     arm_simd = SDL_strncmp(plat, "v6l", 3) == 0 ||
@@ -387,16 +385,19 @@ CPU_haveARMSIMD(void)
 {
     _kernel_swi_regs regs;
     regs.r[0] = 0;
-    if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
+    if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL) {
         return 0;
+    }
 
-    if (!(regs.r[0] & (1<<31)))
+    if (!(regs.r[0] & (1 << 31))) {
         return 0;
+    }
 
     regs.r[0] = 34;
     regs.r[1] = 29;
-    if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
+    if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL) {
         return 0;
+    }
 
     return regs.r[0];
 }
@@ -418,8 +419,7 @@ readProcAuxvForNeon(void)
     int fd;
 
     fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
-    if (fd >= 0)
-    {
+    if (fd >= 0) {
         Elf32_auxv_t aux;
         while (read(fd, &aux, sizeof (aux)) == sizeof (aux)) {
             if (aux.a_type == AT_HWCAP) {
@@ -465,11 +465,12 @@ CPU_haveNEON(void)
     return 1;  /* OpenBSD only supports ARMv7 CPUs that have NEON. */
 #elif defined(HAVE_ELF_AUX_INFO)
     unsigned long hasneon = 0;
-    if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0)
+    if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0) {
         return 0;
-    return ((hasneon & HWCAP_NEON) == HWCAP_NEON);
+    }
+    return (hasneon & HWCAP_NEON) == HWCAP_NEON;
 #elif (defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_GETAUXVAL)
-    return ((getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON);
+    return (getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON;
 #elif defined(__LINUX__)
     return readProcAuxvForNeon();
 #elif defined(__ANDROID__)
@@ -538,7 +539,7 @@ CPU_have3DNow(void)
         cpuid(0x80000000, a, b, c, d);
         if (a >= 0x80000001) {
             cpuid(0x80000001, a, b, c, d);
-            return (d & 0x80000000);
+            return d & 0x80000000;
         }
     }
     return 0;
@@ -611,7 +612,7 @@ CPU_haveAVX2(void)
         int a, b, c, d;
         (void) a; (void) b; (void) c; (void) d;  /* compiler warnings... */
         cpuid(7, a, b, c, d);
-        return (b & 0x00000020);
+        return b & 0x00000020;
     }
     return 0;
 }
@@ -631,7 +632,7 @@ CPU_haveAVX512F(void)
         int a, b, c, d;
         (void) a; (void) b; (void) c; (void) d;  /* compiler warnings... */
         cpuid(7, a, b, c, d);
-        return (b & 0x00010000);
+        return b & 0x00010000;
     }
     return 0;
 }
@@ -815,10 +816,10 @@ SDL_GetCPUCacheLineSize(void)
     (void) a; (void) b; (void) c; (void) d;
    if (SDL_strcmp(cpuType, "GenuineIntel") == 0 || SDL_strcmp(cpuType, "CentaurHauls") == 0 || SDL_strcmp(cpuType, "  Shanghai  ") == 0) {
         cpuid(0x00000001, a, b, c, d);
-        return (((b >> 8) & 0xff) * 8);
+        return ((b >> 8) & 0xff) * 8;
     } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0 || SDL_strcmp(cpuType, "HygonGenuine") == 0) {
         cpuid(0x80000005, a, b, c, d);
-        return (c & 0xff);
+        return c & 0xff;
     } else {
         /* Just make a guess here... */
         return SDL_CACHELINE_SIZE;

+ 1 - 1
src/events/SDL_clipboardevents.c

@@ -39,7 +39,7 @@ SDL_SendClipboardUpdate(void)
 
         posted = (SDL_PushEvent(&event) > 0);
     }
-    return (posted);
+    return posted;
 }
 
 /* vi: set ts=4 sw=4 expandtab: */

+ 2 - 2
src/events/SDL_displayevents.c

@@ -30,7 +30,7 @@ SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1)
 {
     int posted;
 
-    if (!display) {
+    if (display == NULL) {
         return 0;
     }
     switch (displayevent) {
@@ -53,7 +53,7 @@ SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1)
         posted = (SDL_PushEvent(&event) > 0);
     }
 
-    return (posted);
+    return posted;
 }
 
 /* vi: set ts=4 sw=4 expandtab: */

+ 16 - 16
src/events/SDL_events.c

@@ -553,7 +553,7 @@ SDL_StartEventLoop(void)
     }
     SDL_LockMutex(SDL_EventQ.lock);
 
-    if (!SDL_event_watchers_lock) {
+    if (SDL_event_watchers_lock == NULL) {
         SDL_event_watchers_lock = SDL_CreateMutex();
         if (SDL_event_watchers_lock == NULL) {
             SDL_UnlockMutex(SDL_EventQ.lock);
@@ -594,7 +594,7 @@ SDL_AddEvent(SDL_Event * event)
 
     if (SDL_EventQ.free == NULL) {
         entry = (SDL_EventEntry *)SDL_malloc(sizeof(*entry));
-        if (!entry) {
+        if (entry == NULL) {
             return 0;
         }
     } else {
@@ -669,7 +669,7 @@ static int
 SDL_SendWakeupEvent()
 {
     SDL_VideoDevice *_this = SDL_GetVideoDevice();
-    if (!_this || !_this->SendWakeupEvent) {
+    if (_this == NULL || !_this->SendWakeupEvent) {
         return 0;
     }
     if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) {
@@ -705,7 +705,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
             if (action == SDL_GETEVENT) {
                 SDL_SetError("The event system has been shut down");
             }
-            return (-1);
+            return -1;
         }
         if (action == SDL_ADDEVENT) {
             for (i = 0; i < numevents; ++i) {
@@ -728,7 +728,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
                 SDL_EventQ.wmmsg_used = NULL;
             }
 
-            for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
+            for (entry = SDL_EventQ.head; entry && (events == NULL || used < numevents); entry = next) {
                 next = entry->next;
                 type = entry->event.type;
                 if (minType <= type && type <= maxType) {
@@ -761,7 +761,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
                             /* Skip it, we don't want to include it */
                             continue;
                         }
-                        if (!events || action != SDL_GETEVENT) {
+                        if (events == NULL || action != SDL_GETEVENT) {
                             ++sentinels_expected;
                         }
                         if (SDL_AtomicGet(&SDL_sentinel_pending) > sentinels_expected) {
@@ -784,7 +784,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action
         SDL_SendWakeupEvent();
     }
 
-    return (used);
+    return used;
 }
 int
 SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
@@ -796,13 +796,13 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
 SDL_bool
 SDL_HasEvent(Uint32 type)
 {
-    return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0);
+    return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0;
 }
 
 SDL_bool
 SDL_HasEvents(Uint32 minType, Uint32 maxType)
 {
-    return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0);
+    return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0;
 }
 
 void
@@ -1125,7 +1125,7 @@ SDL_PushEvent(SDL_Event * event)
     event->common.timestamp = SDL_GetTicks();
 
     if (SDL_EventOK.callback || SDL_event_watchers_count > 0) {
-        if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+        if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
             if (SDL_EventOK.callback && !SDL_EventOK.callback(SDL_EventOK.userdata, event)) {
                 if (SDL_event_watchers_lock) {
                     SDL_UnlockMutex(SDL_event_watchers_lock);
@@ -1176,7 +1176,7 @@ SDL_PushEvent(SDL_Event * event)
 void
 SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
 {
-    if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+    if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
         /* Set filter and discard pending events */
         SDL_EventOK.callback = filter;
         SDL_EventOK.userdata = userdata;
@@ -1193,7 +1193,7 @@ SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
 {
     SDL_EventWatcher event_ok;
 
-    if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+    if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
         event_ok = SDL_EventOK;
 
         if (SDL_event_watchers_lock) {
@@ -1215,7 +1215,7 @@ SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
 void
 SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
 {
-    if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+    if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
         SDL_EventWatcher *event_watchers;
 
         event_watchers = SDL_realloc(SDL_event_watchers, (SDL_event_watchers_count + 1) * sizeof(*event_watchers));
@@ -1239,7 +1239,7 @@ SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
 void
 SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
 {
-    if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+    if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
         int i;
 
         for (i = 0; i < SDL_event_watchers_count; ++i) {
@@ -1352,7 +1352,7 @@ SDL_SendAppEvent(SDL_EventType eventType)
         event.type = eventType;
         posted = (SDL_PushEvent(&event) > 0);
     }
-    return (posted);
+    return posted;
 }
 
 int
@@ -1369,7 +1369,7 @@ SDL_SendSysWMEvent(SDL_SysWMmsg * message)
         posted = (SDL_PushEvent(&event) > 0);
     }
     /* Update internal event state */
-    return (posted);
+    return posted;
 }
 
 int

+ 54 - 36
src/events/SDL_gesture.c

@@ -90,15 +90,18 @@ static void PrintPath(SDL_FloatPoint *path)
 int SDL_RecordGesture(SDL_TouchID touchId)
 {
     int i;
-    if (touchId < 0) recordAll = SDL_TRUE;
+    if (touchId < 0) {
+        recordAll = SDL_TRUE;
+    }
     for (i = 0; i < SDL_numGestureTouches; i++) {
         if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
             SDL_gestureTouch[i].recording = SDL_TRUE;
-            if (touchId >= 0)
+            if (touchId >= 0) {
                 return 1;
+            }
         }
     }
-    return (touchId < 0);
+    return touchId < 0;
 }
 
 void SDL_GestureQuit()
@@ -193,7 +196,7 @@ static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* p
         (SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
                                           (index + 1) *
                                           sizeof(SDL_DollarTemplate));
-    if (!dollarTemplate) {
+    if (dollarTemplate == NULL) {
         return SDL_OutOfMemory();
     }
     inTouch->dollarTemplate = dollarTemplate;
@@ -211,12 +214,15 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
     int index = -1;
     int i = 0;
     if (inTouch == NULL) {
-        if (SDL_numGestureTouches == 0) return SDL_SetError("no gesture touch devices registered");
+        if (SDL_numGestureTouches == 0) {
+            return SDL_SetError("no gesture touch devices registered");
+        }
         for (i = 0; i < SDL_numGestureTouches; i++) {
             inTouch = &SDL_gestureTouch[i];
             index = SDL_AddDollarGesture_one(inTouch, path);
-            if (index < 0)
+            if (index < 0) {
                 return -1;
+            }
         }
         /* Use the index of the last one added. */
         return index;
@@ -228,7 +234,9 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
 {
     int i,loaded = 0;
     SDL_GestureTouch *touch = NULL;
-    if (src == NULL) return 0;
+    if (src == NULL) {
+        return 0;
+    }
     if (touchId >= 0) {
         for (i = 0; i < SDL_numGestureTouches; i++) {
             if (SDL_gestureTouch[i].id == touchId) {
@@ -260,10 +268,10 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
 
         if (touchId >= 0) {
             /* printf("Adding loaded gesture to 1 touch\n"); */
-            if (SDL_AddDollarGesture(touch, templ.path) >= 0)
+            if (SDL_AddDollarGesture(touch, templ.path) >= 0) {
                 loaded++;
-        }
-        else {
+            }
+        } else {
             /* printf("Adding to: %i touches\n",SDL_numGestureTouches); */
             for (i = 0; i < SDL_numGestureTouches; i++) {
                 touch = &SDL_gestureTouch[i];
@@ -292,7 +300,7 @@ static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float
         dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
                                  (p.y-templ[i].y)*(p.y-templ[i].y)));
     }
-    return dist/DOLLARNPOINTS;
+    return dist / DOLLARNPOINTS;
 
 }
 
@@ -316,8 +324,7 @@ static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
             f2 = f1;
             x1 = (float)(PHI*ta + (1-PHI)*tb);
             f1 = dollarDifference(points,templ,x1);
-        }
-        else {
+        } else {
             ta = x1;
             x1 = x2;
             f1 = f2;
@@ -331,7 +338,7 @@ static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
       else if (f1 >  f2)
           printf("Min angle (x2): %f\n",x2);
     */
-    return SDL_min(f1,f2);
+    return SDL_min(f1, f2);
 }
 
 /* DollarPath contains raw points, plus (possibly) the calculated length */
@@ -412,10 +419,18 @@ static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points, SD
                               (py - centroid.y)*SDL_cos(ang) + centroid.y);
 
 
-        if (points[i].x < xmin) xmin = points[i].x;
-        if (points[i].x > xmax) xmax = points[i].x;
-        if (points[i].y < ymin) ymin = points[i].y;
-        if (points[i].y > ymax) ymax = points[i].y;
+        if (points[i].x < xmin) {
+            xmin = points[i].x;
+        }
+        if (points[i].x > xmax) {
+            xmax = points[i].x;
+        }
+        if (points[i].y < ymin) {
+            ymin = points[i].y;
+        }
+        if (points[i].y > ymax) {
+            ymax = points[i].y;
+        }
     }
 
     /* Scale points to DOLLARSIZE, and translate to the origin */
@@ -455,7 +470,7 @@ int SDL_GestureAddTouch(SDL_TouchID touchId)
                                                                      (SDL_numGestureTouches + 1) *
                                                                      sizeof(SDL_GestureTouch));
 
-    if (!gestureTouch) {
+    if (gestureTouch == NULL) {
         return SDL_OutOfMemory();
     }
 
@@ -496,8 +511,9 @@ static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
     int i;
     for (i = 0; i < SDL_numGestureTouches; i++) {
         /* printf("%i ?= %i\n",SDL_gestureTouch[i].id,id); */
-        if (SDL_gestureTouch[i].id == id)
+        if (SDL_gestureTouch[i].id == id) {
             return &SDL_gestureTouch[i];
+        }
     }
     return NULL;
 }
@@ -569,7 +585,9 @@ void SDL_GestureProcessEvent(SDL_Event* event)
         SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
 
         /* Shouldn't be possible */
-        if (inTouch == NULL) return;
+        if (inTouch == NULL) {
+            return;
+        }
 
         x = event->tfinger.x;
         y = event->tfinger.y;
@@ -589,26 +607,24 @@ void SDL_GestureProcessEvent(SDL_Event* event)
                 /* PrintPath(path); */
                 if (recordAll) {
                     index = SDL_AddDollarGesture(NULL,path);
-                    for (i = 0; i < SDL_numGestureTouches; i++)
+                    for (i = 0; i < SDL_numGestureTouches; i++) {
                         SDL_gestureTouch[i].recording = SDL_FALSE;
-                }
-                else {
+                    }
+                } else {
                     index = SDL_AddDollarGesture(inTouch,path);
                 }
 
                 if (index >= 0) {
                     SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
-                }
-                else {
+                } else {
                     SDL_SendDollarRecord(inTouch,-1);
                 }
-            }
-            else {
+            } else {
                 int bestTempl;
                 float error;
                 error = dollarRecognize(&inTouch->dollarPath,
                                         &bestTempl,inTouch);
-                if (bestTempl >= 0){
+                if (bestTempl >= 0) {
                     /* Send Event */
                     unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
                     SDL_SendGestureDollar(inTouch,gestureId,error);
@@ -623,8 +639,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
                 inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
                                        y)/inTouch->numDownFingers;
             }
-        }
-        else if (event->type == SDL_FINGERMOTION) {
+        } else if (event->type == SDL_FINGERMOTION) {
             float dx = event->tfinger.dx;
             float dy = event->tfinger.dy;
 #if defined(ENABLE_DOLLAR)
@@ -669,7 +684,12 @@ void SDL_GestureProcessEvent(SDL_Event* event)
                 dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
 
                 dDist = (Dist - lDist);
-                if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
+                if (lDist == 0) {
+                    /* To avoid impossible values */
+                    dDist = 0;
+                    dtheta = 0;
+                }
+
 
                 /* inTouch->gestureLast[j].dDist = dDist;
                 inTouch->gestureLast[j].dtheta = dtheta;
@@ -682,8 +702,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
                 printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
                 printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */
                 SDL_SendGestureMulti(inTouch,dtheta,dDist);
-            }
-            else {
+            } else {
                 /* inTouch->gestureLast[j].dDist = 0;
                 inTouch->gestureLast[j].dtheta = 0;
                 inTouch->gestureLast[j].cv.x = 0;
@@ -693,8 +712,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
             inTouch->gestureLast[j].f.p.y = y;
             break;
             pressure? */
-        }
-        else if (event->type == SDL_FINGERDOWN) {
+        } else if (event->type == SDL_FINGERDOWN) {
 
             inTouch->numDownFingers++;
             inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+

+ 8 - 9
src/events/SDL_keyboard.c

@@ -751,7 +751,7 @@ SDL_SetKeyboardFocus(SDL_Window * window)
 {
     SDL_Keyboard *keyboard = &SDL_keyboard;
 
-    if (keyboard->focus && !window) {
+    if (keyboard->focus && window == NULL) {
         /* We won't get anymore keyboard messages, so reset keyboard state */
         SDL_ResetKeyboard();
     }
@@ -760,7 +760,7 @@ SDL_SetKeyboardFocus(SDL_Window * window)
     if (keyboard->focus && keyboard->focus != window) {
 
         /* new window shouldn't think it has mouse captured. */
-        SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
+        SDL_assert(window == NULL || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
 
         /* old window must lose an existing mouse capture. */
         if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
@@ -936,7 +936,7 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode, SD
         SDL_MinimizeWindow(keyboard->focus);
     }
 
-    return (posted);
+    return posted;
 }
 
 int
@@ -1042,7 +1042,7 @@ SDL_SendKeyboardText(const char *text)
             posted |= (SDL_PushEvent(&event) > 0);
         }
     }
-    return (posted);
+    return posted;
 }
 
 int
@@ -1073,7 +1073,7 @@ SDL_SendEditingText(const char *text, int start, int length)
 
         posted = (SDL_PushEvent(&event) > 0);
     }
-    return (posted);
+    return posted;
 }
 
 void
@@ -1097,7 +1097,7 @@ SDL_GetModState(void)
 {
     SDL_Keyboard *keyboard = &SDL_keyboard;
 
-    return (SDL_Keymod) keyboard->modstate;
+    return (SDL_Keymod)keyboard->modstate;
 }
 
 void
@@ -1180,7 +1180,7 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name)
 {
     int i;
 
-    if (!name || !*name) {
+    if (name == NULL || !*name) {
             SDL_InvalidParamError("name");
         return SDL_SCANCODE_UNKNOWN;
     }
@@ -1205,8 +1205,7 @@ SDL_GetKeyName(SDL_Keycode key)
     char *end;
 
     if (key & SDLK_SCANCODE_MASK) {
-        return
-            SDL_GetScancodeName((SDL_Scancode) (key & ~SDLK_SCANCODE_MASK));
+        return SDL_GetScancodeName((SDL_Scancode)(key & ~SDLK_SCANCODE_MASK));
     }
 
     switch (key) {

+ 14 - 14
src/events/SDL_mouse.c

@@ -216,7 +216,7 @@ SDL_MouseInit(void)
 
     mouse->cursor_shown = SDL_TRUE;
 
-    return (0);
+    return 0;
 }
 
 void
@@ -453,7 +453,7 @@ SDL_SetMouseSystemScale(int num_values, const float *values)
     }
 
     v = (float *)SDL_realloc(mouse->system_scale_values, num_values * sizeof(*values));
-    if (!v) {
+    if (v == NULL) {
         return SDL_OutOfMemory();
     }
     SDL_memcpy(v, values, num_values * sizeof(*values));
@@ -676,7 +676,7 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
     if (button >= mouse->num_clickstates) {
         int i, count = button + 1;
         SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
-        if (!clickstate) {
+        if (clickstate == NULL) {
             return NULL;
         }
         mouse->clickstate = clickstate;
@@ -699,7 +699,7 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
     SDL_MouseInputSource *source;
 
     source = GetMouseInputSource(mouse, mouseID);
-    if (!source) {
+    if (source == NULL) {
         return 0;
     }
     buttonstate = source->buttonstate;
@@ -996,10 +996,10 @@ SDL_GetGlobalMouseState(int *x, int *y)
         int tmpx, tmpy;
 
         /* make sure these are never NULL for the backend implementations... */
-        if (!x) {
+        if (x == NULL) {
             x = &tmpx;
         }
-        if (!y) {
+        if (y == NULL) {
             y = &tmpy;
         }
 
@@ -1259,7 +1259,7 @@ SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
                                    0x0000FF00,
                                    0x000000FF,
                                    0xFF000000);
-    if (!surface) {
+    if (surface == NULL) {
         return NULL;
     }
     for (y = 0; y < h; ++y) {
@@ -1293,7 +1293,7 @@ SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
     SDL_Surface *temp = NULL;
     SDL_Cursor *cursor;
 
-    if (!surface) {
+    if (surface == NULL) {
         SDL_InvalidParamError("surface");
         return NULL;
     }
@@ -1312,7 +1312,7 @@ SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
 
     if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
         temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
-        if (!temp) {
+        if (temp == NULL) {
             return NULL;
         }
         surface = temp;
@@ -1368,7 +1368,7 @@ SDL_SetCursor(SDL_Cursor * cursor)
                     break;
                 }
             }
-            if (!found) {
+            if (found == NULL) {
                 SDL_SetError("Cursor not associated with the current mouse");
                 return;
             }
@@ -1398,7 +1398,7 @@ SDL_GetCursor(void)
 {
     SDL_Mouse *mouse = SDL_GetMouse();
 
-    if (!mouse) {
+    if (mouse == NULL) {
         return NULL;
     }
     return mouse->cur_cursor;
@@ -1409,7 +1409,7 @@ SDL_GetDefaultCursor(void)
 {
     SDL_Mouse *mouse = SDL_GetMouse();
 
-    if (!mouse) {
+    if (mouse == NULL) {
         return NULL;
     }
     return mouse->def_cursor;
@@ -1421,7 +1421,7 @@ SDL_FreeCursor(SDL_Cursor * cursor)
     SDL_Mouse *mouse = SDL_GetMouse();
     SDL_Cursor *curr, *prev;
 
-    if (!cursor) {
+    if (cursor == NULL) {
         return;
     }
 
@@ -1455,7 +1455,7 @@ SDL_ShowCursor(int toggle)
     SDL_Mouse *mouse = SDL_GetMouse();
     SDL_bool shown;
 
-    if (!mouse) {
+    if (mouse == NULL) {
         return 0;
     }
 

+ 33 - 17
src/events/SDL_touch.c

@@ -43,7 +43,7 @@ static SDL_TouchID  track_touchid;
 int
 SDL_TouchInit(void)
 {
-    return (0);
+    return 0;
 }
 
 int
@@ -149,7 +149,7 @@ SDL_Finger *
 SDL_GetTouchFinger(SDL_TouchID touchID, int index)
 {
     SDL_Touch *touch = SDL_GetTouch(touchID);
-    if (!touch) {
+    if (touch == NULL) {
         return NULL;
     }
     if (index < 0 || index >= touch->num_fingers) {
@@ -173,7 +173,7 @@ SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
     /* Add the touch to the list of touch */
     touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
                                       (SDL_num_touch + 1) * sizeof(*touchDevices));
-    if (!touchDevices) {
+    if (touchDevices == NULL) {
         return SDL_OutOfMemory();
     }
 
@@ -211,7 +211,7 @@ SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float p
     if (touch->num_fingers == touch->max_fingers) {
         SDL_Finger **new_fingers;
         new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers));
-        if (!new_fingers) {
+        if (new_fingers == NULL) {
             return SDL_OutOfMemory();
         }
         touch->fingers = new_fingers;
@@ -256,7 +256,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
     SDL_Mouse *mouse;
 
     SDL_Touch* touch = SDL_GetTouch(id);
-    if (!touch) {
+    if (touch == NULL) {
         return -1;
     }
 
@@ -278,10 +278,18 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
                         if (finger_touching == SDL_FALSE) {
                             int pos_x = (int)(x * (float)window->w);
                             int pos_y = (int)(y * (float)window->h);
-                            if (pos_x < 0) pos_x = 0;
-                            if (pos_x > window->w - 1) pos_x = window->w - 1;
-                            if (pos_y < 0) pos_y = 0;
-                            if (pos_y > window->h - 1) pos_y = window->h - 1;
+                            if (pos_x < 0) {
+                                pos_x = 0;
+                            }
+                            if (pos_x > window->w - 1) {
+                                pos_x = window->w - 1;
+                            }
+                            if (pos_y < 0) {
+                                pos_y = 0;
+                            }
+                            if (pos_y > window->h - 1) {
+                                pos_y = window->h - 1;
+                            }
                             SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
                             SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
                         }
@@ -341,7 +349,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
             posted = (SDL_PushEvent(&event) > 0);
         }
     } else {
-        if (!finger) {
+        if (finger == NULL) {
             /* This finger is already up */
             return 0;
         }
@@ -378,7 +386,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
     float xrel, yrel, prel;
 
     touch = SDL_GetTouch(id);
-    if (!touch) {
+    if (touch == NULL) {
         return -1;
     }
 
@@ -393,10 +401,18 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
                     if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
                         int pos_x = (int)(x * (float)window->w);
                         int pos_y = (int)(y * (float)window->h);
-                        if (pos_x < 0) pos_x = 0;
-                        if (pos_x > window->w - 1) pos_x = window->w - 1;
-                        if (pos_y < 0) pos_y = 0;
-                        if (pos_y > window->h - 1) pos_y = window->h - 1;
+                        if (pos_x < 0) {
+                            pos_x = 0;
+                        }
+                        if (pos_x > window->w - 1) {
+                            pos_x = window->w - 1;
+                        }
+                        if (pos_y < 0) {
+                            pos_y = 0;
+                        }
+                        if (pos_y > window->h - 1) {
+                            pos_y = window->h - 1;
+                        }
                         SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
                     }
                 }
@@ -413,7 +429,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
     }
 
     finger = SDL_GetFinger(touch,fingerid);
-    if (!finger) {
+    if (finger == NULL) {
         return SDL_SendTouch(id, fingerid, window, SDL_TRUE, x, y, pressure);
     }
 
@@ -465,7 +481,7 @@ SDL_DelTouch(SDL_TouchID id)
 
     index = SDL_GetTouchIndex(id);
     touch = SDL_GetTouch(id);
-    if (!touch) {
+    if (touch == NULL) {
         return;
     }
 

+ 1 - 1
src/events/SDL_windowevents.c

@@ -86,7 +86,7 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
 {
     int posted;
 
-    if (!window) {
+    if (window == NULL) {
         return 0;
     }
     switch (windowevent) {

+ 33 - 26
src/file/SDL_rwops.c

@@ -75,8 +75,9 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
     DWORD must_exist, truncate;
     int a_mode;
 
-    if (!context)
-        return -1;              /* failed (invalid call) */
+    if (context == NULL) {
+        return -1; /* failed (invalid call) */
+    }
 
     context->hidden.windowsio.h = INVALID_HANDLE_VALUE;   /* mark this as unusable */
     context->hidden.windowsio.buffer.data = NULL;
@@ -98,8 +99,10 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
     w_right = (a_mode || SDL_strchr(mode, '+')
                || truncate) ? GENERIC_WRITE : 0;
 
-    if (!r_right && !w_right)   /* inconsistent mode */
-        return -1;              /* failed (invalid call) */
+    if (!r_right && !w_right) {
+        return -1; /* inconsistent mode */
+    }
+                  /* failed (invalid call) */
 
     context->hidden.windowsio.buffer.data =
         (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
@@ -143,7 +146,7 @@ windows_file_size(SDL_RWops * context)
 {
     LARGE_INTEGER size;
 
-    if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
+    if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
         return SDL_SetError("windows_file_size: invalid context/file not opened");
     }
 
@@ -160,7 +163,7 @@ windows_file_seek(SDL_RWops * context, Sint64 offset, int whence)
     DWORD windowswhence;
     LARGE_INTEGER windowsoffset;
 
-    if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
+    if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
         return SDL_SetError("windows_file_seek: invalid context/file not opened");
     }
 
@@ -201,7 +204,7 @@ windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
 
     total_need = size * maxnum;
 
-    if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !total_need) {
+    if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !total_need) {
         return 0;
     }
 
@@ -242,7 +245,7 @@ windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
         }
         total_read += byte_read;
     }
-    return (total_read / size);
+    return total_read / size;
 }
 
 static size_t SDLCALL
@@ -256,7 +259,7 @@ windows_file_write(SDL_RWops * context, const void *ptr, size_t size,
 
     total_bytes = size * num;
 
-    if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !size || !total_bytes) {
+    if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !size || !total_bytes) {
         return 0;
     }
 
@@ -509,7 +512,7 @@ mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
     SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
     context->hidden.mem.here += total_bytes;
 
-    return (total_bytes / size);
+    return total_bytes / size;
 }
 
 static size_t SDLCALL
@@ -546,7 +549,7 @@ SDL_RWops *
 SDL_RWFromFile(const char *file, const char *mode)
 {
     SDL_RWops *rwops = NULL;
-    if (!file || !*file || !mode || !*mode) {
+    if (file == NULL || !*file || mode == NULL || !*mode) {
         SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
         return NULL;
     }
@@ -579,8 +582,10 @@ SDL_RWFromFile(const char *file, const char *mode)
 
     /* Try to open the file from the asset system */
     rwops = SDL_AllocRW();
-    if (!rwops)
-        return NULL;            /* SDL_SetError already setup by SDL_AllocRW() */
+    if (rwops == NULL) {
+        return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
+    }
+
     if (Android_JNI_FileOpen(rwops, file, mode) < 0) {
         SDL_FreeRW(rwops);
         return NULL;
@@ -594,8 +599,10 @@ SDL_RWFromFile(const char *file, const char *mode)
 
 #elif defined(__WIN32__) || defined(__GDK__)
     rwops = SDL_AllocRW();
-    if (!rwops)
-        return NULL;            /* SDL_SetError already setup by SDL_AllocRW() */
+    if (rwops == NULL) {
+        return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
+    }
+
     if (windows_file_open(rwops, file, mode) < 0) {
         SDL_FreeRW(rwops);
         return NULL;
@@ -635,7 +642,7 @@ SDL_RWops *
 SDL_RWFromMem(void *mem, int size)
 {
     SDL_RWops *rwops = NULL;
-    if (!mem) {
+    if (mem == NULL) {
       SDL_InvalidParamError("mem");
       return rwops;
     }
@@ -663,7 +670,7 @@ SDL_RWops *
 SDL_RWFromConstMem(const void *mem, int size)
 {
     SDL_RWops *rwops = NULL;
-    if (!mem) {
+    if (mem == NULL) {
       SDL_InvalidParamError("mem");
       return rwops;
     }
@@ -716,7 +723,7 @@ SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc)
     size_t size_read, size_total;
     void *data = NULL, *newdata;
 
-    if (!src) {
+    if (src == NULL) {
         SDL_InvalidParamError("src");
         return NULL;
     }
@@ -732,7 +739,7 @@ SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc)
         if ((((Sint64)size_total) + FILE_CHUNK_SIZE) > size) {
             size = (size_total + FILE_CHUNK_SIZE);
             newdata = SDL_realloc(data, (size_t)(size + 1));
-            if (!newdata) {
+            if (newdata == NULL) {
                 SDL_free(data);
                 data = NULL;
                 SDL_OutOfMemory();
@@ -870,49 +877,49 @@ SDL_ReadBE64(SDL_RWops * src)
 size_t
 SDL_WriteU8(SDL_RWops * dst, Uint8 value)
 {
-    return SDL_RWwrite(dst, &value, sizeof (value), 1);
+    return SDL_RWwrite(dst, &value, sizeof(value), 1);
 }
 
 size_t
 SDL_WriteLE16(SDL_RWops * dst, Uint16 value)
 {
     const Uint16 swapped = SDL_SwapLE16(value);
-    return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+    return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
 }
 
 size_t
 SDL_WriteBE16(SDL_RWops * dst, Uint16 value)
 {
     const Uint16 swapped = SDL_SwapBE16(value);
-    return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+    return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
 }
 
 size_t
 SDL_WriteLE32(SDL_RWops * dst, Uint32 value)
 {
     const Uint32 swapped = SDL_SwapLE32(value);
-    return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+    return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
 }
 
 size_t
 SDL_WriteBE32(SDL_RWops * dst, Uint32 value)
 {
     const Uint32 swapped = SDL_SwapBE32(value);
-    return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+    return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
 }
 
 size_t
 SDL_WriteLE64(SDL_RWops * dst, Uint64 value)
 {
     const Uint64 swapped = SDL_SwapLE64(value);
-    return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+    return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
 }
 
 size_t
 SDL_WriteBE64(SDL_RWops * dst, Uint64 value)
 {
     const Uint64 swapped = SDL_SwapBE64(value);
-    return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+    return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1);
 }
 
 /* vi: set ts=4 sw=4 expandtab: */

+ 1 - 1
src/filesystem/android/SDL_sysfilesystem.c

@@ -44,7 +44,7 @@ SDL_GetPrefPath(const char *org, const char *app)
     if (path) {
         size_t pathlen = SDL_strlen(path)+2;
         char *fullpath = (char *)SDL_malloc(pathlen);
-        if (!fullpath) {
+        if (fullpath == NULL) {
             SDL_OutOfMemory();
             return NULL;
         }

+ 5 - 4
src/filesystem/emscripten/SDL_sysfilesystem.c

@@ -45,17 +45,17 @@ SDL_GetPrefPath(const char *org, const char *app)
     char *ptr = NULL;
     size_t len = 0;
 
-    if (!app) {
+    if (app == NULL) {
         SDL_InvalidParamError("app");
         return NULL;
     }
-    if (!org) {
+    if (org == NULL) {
         org = "";
     }
 
     len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
     retval = (char *) SDL_malloc(len);
-    if (!retval) {
+    if (retval == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -69,8 +69,9 @@ SDL_GetPrefPath(const char *org, const char *app)
     for (ptr = retval+1; *ptr; ptr++) {
         if (*ptr == '/') {
             *ptr = '\0';
-            if (mkdir(retval, 0700) != 0 && errno != EEXIST)
+            if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
                 goto error;
+            }
             *ptr = '/';
         }
     }

+ 4 - 4
src/filesystem/haiku/SDL_sysfilesystem.cc

@@ -54,7 +54,7 @@ SDL_GetBasePath(void)
 
     const size_t len = SDL_strlen(str);
     char *retval = (char *) SDL_malloc(len + 2);
-    if (!retval) {
+    if (retval == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -74,11 +74,11 @@ SDL_GetPrefPath(const char *org, const char *app)
     const char *append = "/config/settings/";
     size_t len = SDL_strlen(home);
 
-    if (!app) {
+    if (app == NULL) {
         SDL_InvalidParamError("app");
         return NULL;
     }
-    if (!org) {
+    if (org == NULL) {
         org = "";
     }
 
@@ -87,7 +87,7 @@ SDL_GetPrefPath(const char *org, const char *app)
     }
     len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
     char *retval = (char *) SDL_malloc(len);
-    if (!retval) {
+    if (retval == NULL) {
         SDL_OutOfMemory();
     } else {
         if (*org) {

+ 8 - 5
src/filesystem/ps2/SDL_sysfilesystem.c

@@ -39,8 +39,9 @@ SDL_GetBasePath(void)
   getcwd(cwd, sizeof(cwd));
   len = SDL_strlen(cwd) + 1;
   retval = (char *) SDL_malloc(len);
-  if (retval)
+  if (retval) {
     SDL_memcpy(retval, cwd, len);
+  }
 
   return retval;
 }
@@ -54,15 +55,17 @@ static void recursive_mkdir(const char *dir) {
 
   snprintf(tmp, sizeof(tmp),"%s",dir);
   len = strlen(tmp);
-  if (tmp[len - 1] == '/')
+  if (tmp[len - 1] == '/') {
       tmp[len - 1] = 0;
+  }
 
   for (p = tmp + 1; *p; p++) {
     if (*p == '/') {
       *p = 0;
       // Just creating subfolders from current path
-      if (strstr(tmp, base) != NULL)
+      if (strstr(tmp, base) != NULL) {
         mkdir(tmp, S_IRWXU);
+      }
 
       *p = '/';
     }
@@ -78,11 +81,11 @@ SDL_GetPrefPath(const char *org, const char *app)
   char *retval = NULL;
   size_t len;
   char *base = SDL_GetBasePath();
-  if (!app) {
+  if (app == NULL) {
     SDL_InvalidParamError("app");
     return NULL;
   }
-  if(!org) {
+  if (org == NULL) {
     org = "";
   }
 

+ 2 - 2
src/filesystem/psp/SDL_sysfilesystem.c

@@ -50,11 +50,11 @@ SDL_GetPrefPath(const char *org, const char *app)
     char *retval = NULL;
     size_t len;
     char *base = SDL_GetBasePath();
-    if (!app) {
+    if (app == NULL) {
         SDL_InvalidParamError("app");
         return NULL;
     }
-    if(!org) {
+    if (org == NULL) {
         org = "";
     }
 

+ 14 - 11
src/filesystem/riscos/SDL_sysfilesystem.c

@@ -36,22 +36,23 @@ SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, int filetype)
 {
     const char *const in_buf = buffer; /* = NULL if we allocate the buffer.  */
 
-    if (!buffer) {
+    if (buffer == NULL) {
         /* This matches the logic in __unixify, with an additional byte for the
          * extra path separator.
          */
         buf_len = SDL_strlen(ro_path) + 14 + 1;
         buffer = SDL_malloc(buf_len);
 
-        if (!buffer) {
+        if (buffer == NULL) {
             SDL_OutOfMemory();
             return NULL;
         }
     }
 
     if (!__unixify_std(ro_path, buffer, buf_len, filetype)) {
-        if (!in_buf)
+        if (in_buf == NULL) {
             SDL_free(buffer);
+        }
 
         SDL_SetError("Could not convert '%s' to a Unix-style path", ro_path);
         return NULL;
@@ -90,7 +91,7 @@ canonicalisePath(const char *path, const char *pathVar)
 
     regs.r[5] = 1 - regs.r[5];
     buf = SDL_malloc(regs.r[5]);
-    if (!buf) {
+    if (buf == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -120,8 +121,9 @@ createDirectoryRecursive(char *path)
             *ptr = '\0';
             error = _kernel_swi(OS_File, &regs, &regs);
             *ptr = '.';
-            if (error != NULL)
+            if (error != NULL) {
                 return error;
+            }
         }
     }
     return _kernel_swi(OS_File, &regs, &regs);
@@ -140,14 +142,15 @@ SDL_GetBasePath(void)
     }
 
     canon = canonicalisePath((const char *)regs.r[0], "Run$Path");
-    if (!canon) {
+    if (canon == NULL) {
         return NULL;
     }
 
     /* chop off filename. */
     ptr = SDL_strrchr(canon, '.');
-    if (ptr != NULL)
+    if (ptr != NULL) {
         *ptr = '\0';
+    }
 
     retval = SDL_unixify_std(canon, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED);
     SDL_free(canon);
@@ -161,22 +164,22 @@ SDL_GetPrefPath(const char *org, const char *app)
     size_t len;
     _kernel_oserror *error;
 
-    if (!app) {
+    if (app == NULL) {
         SDL_InvalidParamError("app");
         return NULL;
     }
-    if (!org) {
+    if (org == NULL) {
         org = "";
     }
 
     canon = canonicalisePath("<Choices$Write>", "Run$Path");
-    if (!canon) {
+    if (canon == NULL) {
         return NULL;
     }
 
     len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4;
     dir = (char *) SDL_malloc(len);
-    if (!dir) {
+    if (dir == NULL) {
         SDL_OutOfMemory();
         SDL_free(canon);
         return NULL;

+ 21 - 19
src/filesystem/unix/SDL_sysfilesystem.c

@@ -46,8 +46,7 @@ readSymLink(const char *path)
     ssize_t len = 64;
     ssize_t rc = -1;
 
-    while (1)
-    {
+    while (1) {
         char *ptr = (char *) SDL_realloc(retval, (size_t) len);
         if (ptr == NULL) {
             SDL_OutOfMemory();
@@ -80,13 +79,13 @@ static char *search_path_for_binary(const char *bin)
     char *start = envr;
     char *ptr;
 
-    if (!envr) {
+    if (envr == NULL) {
         SDL_SetError("No $PATH set");
         return NULL;
     }
 
     envr = SDL_strdup(envr);
-    if (!envr) {
+    if (envr == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -135,7 +134,7 @@ SDL_GetBasePath(void)
     const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
     if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
         retval = SDL_strdup(fullpath);
-        if (!retval) {
+        if (retval == NULL) {
             SDL_OutOfMemory();
             return NULL;
         }
@@ -149,13 +148,13 @@ SDL_GetBasePath(void)
     if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
         char *exe, *pwddst;
         char *realpathbuf = (char *) SDL_malloc(PATH_MAX + 1);
-        if (!realpathbuf) {
+        if (realpathbuf == NULL) {
             SDL_OutOfMemory();
             return NULL;
         }
 
         cmdline = SDL_malloc(len);
-        if (!cmdline) {
+        if (cmdline == NULL) {
             SDL_free(realpathbuf);
             SDL_OutOfMemory();
             return NULL;
@@ -193,7 +192,7 @@ SDL_GetBasePath(void)
             }
         }
 
-        if (!retval) {
+        if (retval == NULL) {
             SDL_free(realpathbuf);
         }
 
@@ -204,7 +203,7 @@ SDL_GetBasePath(void)
     const char *path = getexecname();
     if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
         retval = SDL_strdup(path);
-        if (!retval) {
+        if (retval == NULL) {
             SDL_OutOfMemory();
             return NULL;
         }
@@ -212,7 +211,7 @@ SDL_GetBasePath(void)
 #endif
 
     /* is a Linux-style /proc filesystem available? */
-    if (!retval && (access("/proc", F_OK) == 0)) {
+    if (retval == NULL && (access("/proc", F_OK) == 0)) {
         /* !!! FIXME: after 2.0.6 ships, let's delete this code and just
                       use the /proc/%llu version. There's no reason to have
                       two copies of this plus all the #ifdefs. --ryan. */
@@ -251,8 +250,9 @@ SDL_GetBasePath(void)
     if (retval != NULL) {
         /* try to shrink buffer... */
         char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1);
-        if (ptr != NULL)
-            retval = ptr;  /* oh well if it failed. */
+        if (ptr != NULL) {
+            retval = ptr; /* oh well if it failed. */
+        }
     }
 
     return retval;
@@ -274,18 +274,18 @@ SDL_GetPrefPath(const char *org, const char *app)
     char *ptr = NULL;
     size_t len = 0;
 
-    if (!app) {
+    if (app == NULL) {
         SDL_InvalidParamError("app");
         return NULL;
     }
-    if (!org) {
+    if (org == NULL) {
         org = "";
     }
 
-    if (!envr) {
+    if (envr == NULL) {
         /* You end up with "$HOME/.local/share/Game Name 2" */
         envr = SDL_getenv("HOME");
-        if (!envr) {
+        if (envr == NULL) {
             /* we could take heroic measures with /etc/passwd, but oh well. */
             SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
             return NULL;
@@ -296,12 +296,13 @@ SDL_GetPrefPath(const char *org, const char *app)
     }
 
     len = SDL_strlen(envr);
-    if (envr[len - 1] == '/')
+    if (envr[len - 1] == '/') {
         append += 1;
+    }
 
     len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
     retval = (char *) SDL_malloc(len);
-    if (!retval) {
+    if (retval == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -315,8 +316,9 @@ SDL_GetPrefPath(const char *org, const char *app)
     for (ptr = retval+1; *ptr; ptr++) {
         if (*ptr == '/') {
             *ptr = '\0';
-            if (mkdir(retval, 0700) != 0 && errno != EEXIST)
+            if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
                 goto error;
+            }
             *ptr = '/';
         }
     }

+ 3 - 3
src/filesystem/vita/SDL_sysfilesystem.c

@@ -51,11 +51,11 @@ SDL_GetPrefPath(const char *org, const char *app)
     char *ptr = NULL;
     size_t len = 0;
 
-    if (!app) {
+    if (app == NULL) {
         SDL_InvalidParamError("app");
         return NULL;
     }
-    if (!org) {
+    if (org == NULL) {
         org = "";
     }
 
@@ -63,7 +63,7 @@ SDL_GetPrefPath(const char *org, const char *app)
 
     len += SDL_strlen(org) + SDL_strlen(app) + 3;
     retval = (char *) SDL_malloc(len);
-    if (!retval) {
+    if (retval == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }

+ 3 - 3
src/filesystem/windows/SDL_sysfilesystem.c

@@ -40,7 +40,7 @@ SDL_GetBasePath(void)
 
     while (SDL_TRUE) {
         void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR));
-        if (!ptr) {
+        if (ptr == NULL) {
             SDL_free(path);
             SDL_OutOfMemory();
             return NULL;
@@ -98,11 +98,11 @@ SDL_GetPrefPath(const char *org, const char *app)
     size_t new_wpath_len = 0;
     BOOL api_result = FALSE;
 
-    if (!app) {
+    if (app == NULL) {
         SDL_InvalidParamError("app");
         return NULL;
     }
-    if (!org) {
+    if (org == NULL) {
         org = "";
     }
 

+ 6 - 6
src/filesystem/winrt/SDL_sysfilesystem.cpp

@@ -106,7 +106,7 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
     }
 
     const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
-    if (!ucs2Path) {
+    if (ucs2Path == NULL) {
         return NULL;
     }
 
@@ -123,14 +123,14 @@ SDL_GetBasePath(void)
     size_t destPathLen;
     char * destPath = NULL;
 
-    if (!srcPath) {
+    if (srcPath == NULL) {
         SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
         return NULL;
     }
 
     destPathLen = SDL_strlen(srcPath) + 2;
     destPath = (char *) SDL_malloc(destPathLen);
-    if (!destPath) {
+    if (destPath == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -156,16 +156,16 @@ SDL_GetPrefPath(const char *org, const char *app)
     size_t new_wpath_len = 0;
     BOOL api_result = FALSE;
 
-    if (!app) {
+    if (app == NULL) {
         SDL_InvalidParamError("app");
         return NULL;
     }
-    if (!org) {
+    if (org == NULL) {
         org = "";
     }
 
     srcPath = SDL_WinRTGetFSPathUNICODE(SDL_WINRT_PATH_LOCAL_FOLDER);
-    if ( ! srcPath) {
+    if (srcPath == NULL) {
         SDL_SetError("Unable to find a source path");
         return NULL;
     }

+ 20 - 24
src/haptic/SDL_haptic.c

@@ -60,8 +60,7 @@ ValidHaptic(SDL_Haptic * haptic)
     valid = 0;
     if (haptic != NULL) {
         hapticlist = SDL_haptics;
-        while ( hapticlist )
-        {
+        while ( hapticlist ) {
             if (hapticlist == haptic) {
                 valid = 1;
                 break;
@@ -123,8 +122,7 @@ SDL_HapticOpen(int device_index)
     /* If the haptic is already open, return it
     * TODO: Should we create haptic instance IDs like the Joystick API?
     */
-    while ( hapticlist )
-    {
+    while ( hapticlist ) {
         if (device_index == hapticlist->index) {
             haptic = hapticlist;
             ++haptic->ref_count;
@@ -156,10 +154,12 @@ SDL_HapticOpen(int device_index)
     SDL_haptics = haptic;
 
     /* Disable autocenter and set gain to max. */
-    if (haptic->supported & SDL_HAPTIC_GAIN)
+    if (haptic->supported & SDL_HAPTIC_GAIN) {
         SDL_HapticSetGain(haptic, 100);
-    if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
+    }
+    if (haptic->supported & SDL_HAPTIC_AUTOCENTER) {
         SDL_HapticSetAutocenter(haptic, 0);
+    }
 
     return haptic;
 }
@@ -184,8 +184,7 @@ SDL_HapticOpened(int device_index)
     opened = 0;
     hapticlist = SDL_haptics;
     /* TODO Should this use an instance ID? */
-    while ( hapticlist )
-    {
+    while ( hapticlist ) {
         if (hapticlist->index == (Uint8) device_index) {
             opened = 1;
             break;
@@ -216,8 +215,9 @@ SDL_HapticIndex(SDL_Haptic * haptic)
 int
 SDL_MouseIsHaptic(void)
 {
-    if (SDL_SYS_HapticMouse() < 0)
+    if (SDL_SYS_HapticMouse() < 0) {
         return SDL_FALSE;
+    }
     return SDL_TRUE;
 }
 
@@ -295,8 +295,7 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
 
     hapticlist = SDL_haptics;
     /* Check to see if joystick's haptic is already open */
-    while ( hapticlist )
-    {
+    while ( hapticlist ) {
         if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) {
             haptic = hapticlist;
             ++haptic->ref_count;
@@ -362,17 +361,12 @@ SDL_HapticClose(SDL_Haptic * haptic)
     /* Remove from the list */
     hapticlist = SDL_haptics;
     hapticlistprev = NULL;
-    while ( hapticlist )
-    {
-        if (haptic == hapticlist)
-        {
-            if ( hapticlistprev )
-            {
+    while ( hapticlist ) {
+        if (haptic == hapticlist) {
+            if ( hapticlistprev ) {
                 /* unlink this entry */
                 hapticlistprev->next = hapticlist->next;
-            }
-            else
-            {
+            } else {
                 SDL_haptics = haptic->next;
             }
 
@@ -464,8 +458,9 @@ SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
         return -1;
     }
 
-    if ((haptic->supported & effect->type) != 0)
+    if ((haptic->supported & effect->type) != 0) {
         return SDL_TRUE;
+    }
     return SDL_FALSE;
 }
 
@@ -646,10 +641,11 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
         max_gain = SDL_atoi(env);
 
         /* Check for sanity. */
-        if (max_gain < 0)
+        if (max_gain < 0) {
             max_gain = 0;
-        else if (max_gain > 100)
+        } else if (max_gain > 100) {
             max_gain = 100;
+        }
 
         /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
         real_gain = (gain * max_gain) / 100;
@@ -747,7 +743,7 @@ SDL_HapticRumbleSupported(SDL_Haptic * haptic)
     }
 
     /* Most things can use SINE, but XInput only has LEFTRIGHT. */
-    return ((haptic->supported & (SDL_HAPTIC_SINE|SDL_HAPTIC_LEFTRIGHT)) != 0);
+    return (haptic->supported & (SDL_HAPTIC_SINE | SDL_HAPTIC_LEFTRIGHT)) != 0;
 }
 
 /*

+ 7 - 7
src/haptic/android/SDL_syshaptic.c

@@ -54,13 +54,13 @@ SDL_SYS_HapticInit(void)
         timeout = SDL_GetTicks() + 3000;
         Android_JNI_PollHapticDevices();
     }
-    return (numhaptics);
+    return numhaptics;
 }
 
 int
 SDL_SYS_NumHaptics(void)
 {
-    return (numhaptics);
+    return numhaptics;
 }
 
 static SDL_hapticlist_item *
@@ -133,19 +133,19 @@ OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item)
 static SDL_hapticlist_item *
 OpenHapticByOrder(SDL_Haptic *haptic, int index)
 {
-    return OpenHaptic (haptic, HapticByOrder(index));
+    return OpenHaptic(haptic, HapticByOrder(index));
 }
 
 static SDL_hapticlist_item *
 OpenHapticByDevId(SDL_Haptic *haptic, int device_id)
 {
-    return OpenHaptic (haptic, HapticByDevId(device_id));
+    return OpenHaptic(haptic, HapticByDevId(device_id));
 }
 
 int
 SDL_SYS_HapticOpen(SDL_Haptic *haptic)
 {
-    return (OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0);
+    return OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0;
 }
 
 
@@ -168,14 +168,14 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
 int
 SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
 {
-    return (OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0);
+    return OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0;
 }
 
 
 int
 SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
 {
-    return (((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0);
+    return ((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0;
 }
 
 

+ 1 - 2
src/haptic/darwin/SDL_syshaptic.c

@@ -226,8 +226,7 @@ MacHaptic_MaybeAddDevice( io_object_t device )
     }
 
     /* Make sure we don't already have it */
-    for (item = SDL_hapticlist; item ; item = item->next)
-    {
+    for (item = SDL_hapticlist; item ; item = item->next) {
         if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
             /* Already added */
             return -1;

+ 21 - 13
src/haptic/linux/SDL_syshaptic.c

@@ -78,8 +78,10 @@ static SDL_hapticlist_item *SDL_hapticlist = NULL;
 static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
 static int numhaptics = 0;
 
-#define EV_TEST(ev,f) \
-   if (test_bit((ev), features)) ret |= (f);
+#define EV_TEST(ev,f)                \
+   if (test_bit((ev), features)) {   \
+       ret |= (f);                   \
+   }
 /*
  * Test whether a device has haptic properties.
  * Returns available properties or 0 if there are none.
@@ -753,8 +755,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
 
         /* Header */
         dest->type = FF_CONSTANT;
-        if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1)
+        if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1) {
             return -1;
+        }
 
         /* Replay */
         dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
@@ -788,8 +791,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
 
         /* Header */
         dest->type = FF_PERIODIC;
-        if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1)
+        if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1) {
             return -1;
+        }
 
         /* Replay */
         dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ?
@@ -801,17 +805,18 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
         dest->trigger.interval = CLAMP(periodic->interval);
 
         /* Periodic */
-        if (periodic->type == SDL_HAPTIC_SINE)
+        if (periodic->type == SDL_HAPTIC_SINE) {
             dest->u.periodic.waveform = FF_SINE;
         /* !!! FIXME: put this back when we have more bits in 2.1 */
         /* else if (periodic->type == SDL_HAPTIC_SQUARE)
             dest->u.periodic.waveform = FF_SQUARE; */
-        else if (periodic->type == SDL_HAPTIC_TRIANGLE)
+        } else if (periodic->type == SDL_HAPTIC_TRIANGLE) {
             dest->u.periodic.waveform = FF_TRIANGLE;
-        else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP)
+        } else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP) {
             dest->u.periodic.waveform = FF_SAW_UP;
-        else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)
+        } else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN) {
             dest->u.periodic.waveform = FF_SAW_DOWN;
+        }
         dest->u.periodic.period = CLAMP(periodic->period);
         dest->u.periodic.magnitude = periodic->magnitude;
         dest->u.periodic.offset = periodic->offset;
@@ -835,14 +840,16 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
         condition = &src->condition;
 
         /* Header */
-        if (condition->type == SDL_HAPTIC_SPRING)
+        if (condition->type == SDL_HAPTIC_SPRING) {
             dest->type = FF_SPRING;
-        else if (condition->type == SDL_HAPTIC_DAMPER)
+        } else if (condition->type == SDL_HAPTIC_DAMPER) {
             dest->type = FF_DAMPER;
-        else if (condition->type == SDL_HAPTIC_INERTIA)
+        } else if (condition->type == SDL_HAPTIC_INERTIA) {
             dest->type = FF_INERTIA;
-        else if (condition->type == SDL_HAPTIC_FRICTION)
+        } else if (condition->type == SDL_HAPTIC_FRICTION) {
             dest->type = FF_FRICTION;
+        }
+        
         dest->direction = 0;    /* Handled by the condition-specifics. */
 
         /* Replay */
@@ -881,8 +888,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
 
         /* Header */
         dest->type = FF_RAMP;
-        if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1)
+        if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1) {
             return -1;
+        }
 
         /* Replay */
         dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ?

+ 10 - 5
src/haptic/windows/SDL_dinputhaptic.c

@@ -569,18 +569,22 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
     case SDL_HAPTIC_CARTESIAN:
         effect->dwFlags |= DIEFF_CARTESIAN;
         rglDir[0] = dir->dir[0];
-        if (naxes > 1)
+        if (naxes > 1) {
             rglDir[1] = dir->dir[1];
-        if (naxes > 2)
+        }
+        if (naxes > 2) {
             rglDir[2] = dir->dir[2];
+        }
         return 0;
     case SDL_HAPTIC_SPHERICAL:
         effect->dwFlags |= DIEFF_SPHERICAL;
         rglDir[0] = dir->dir[0];
-        if (naxes > 1)
+        if (naxes > 1) {
             rglDir[1] = dir->dir[1];
-        if (naxes > 2)
+        }
+        if (naxes > 2) {
             rglDir[2] = dir->dir[2];
+        }
         return 0;
     case SDL_HAPTIC_STEERING_AXIS:
         effect->dwFlags |= DIEFF_CARTESIAN;
@@ -1092,8 +1096,9 @@ SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effe
         return DI_SetError("Getting effect status", ret);
     }
 
-    if (status == 0)
+    if (status == 0) {
         return SDL_FALSE;
+    }
     return SDL_TRUE;
 }
 

+ 1 - 1
src/haptic/windows/SDL_xinputhaptic.c

@@ -228,7 +228,7 @@ SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
 int
 SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
 {
-    return (haptic->hwdata->userid == joystick->hwdata->userid);
+    return haptic->hwdata->userid == joystick->hwdata->userid;
 }
 
 int

+ 14 - 20
src/hidapi/SDL_hidapi.c

@@ -182,7 +182,9 @@ static int SDL_inotify_init1(void) {
 #else
 static int SDL_inotify_init1(void) {
     int fd = inotify_init();
-    if (fd  < 0) return -1;
+    if (fd < 0) {
+        return -1;
+    }
     fcntl(fd, F_SETFL, O_NONBLOCK);
     fcntl(fd, F_SETFD, FD_CLOEXEC);
     return fd;
@@ -192,7 +194,7 @@ static int SDL_inotify_init1(void) {
 static int
 StrHasPrefix(const char *string, const char *prefix)
 {
-    return (SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0);
+    return SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0;
 }
 
 static int
@@ -321,8 +323,7 @@ HIDAPI_InitializeDiscovery()
                 SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE;
             }
         }
-    }
-    else
+    } else
 #endif /* SDL_USE_LIBUDEV */
     {
 #if defined(HAVE_INOTIFY)
@@ -418,15 +419,14 @@ HIDAPI_UpdateDiscovery()
                 if (pUdevDevice) {
                     const char *action = NULL;
                     action = usyms->udev_device_get_action(pUdevDevice);
-                    if (!action || SDL_strcmp(action, "add") == 0 || SDL_strcmp(action, "remove") == 0) {
+                    if (action == NULL || SDL_strcmp(action, "add") == 0 || SDL_strcmp(action, "remove") == 0) {
                         ++SDL_HIDAPI_discovery.m_unDeviceChangeCounter;
                     }
                     usyms->udev_device_unref(pUdevDevice);
                 }
             }
         }
-    }
-    else
+    } else
 #endif /* SDL_USE_LIBUDEV */
     {
 #if defined(HAVE_INOTIFY)
@@ -478,8 +478,9 @@ HIDAPI_ShutdownDiscovery()
     }
 
 #if defined(__WIN32__) || defined(__WINGDK__)
-    if (SDL_HIDAPI_discovery.m_hNotify)
+    if (SDL_HIDAPI_discovery.m_hNotify) {
         UnregisterDeviceNotification(SDL_HIDAPI_discovery.m_hNotify);
+    }
 
     if (SDL_HIDAPI_discovery.m_hwndMsg) {
         DestroyWindow(SDL_HIDAPI_discovery.m_hwndMsg);
@@ -506,8 +507,7 @@ HIDAPI_ShutdownDiscovery()
             SDL_UDEV_ReleaseUdevSyms();
             usyms = NULL;
         }
-    }
-    else
+    } else
 #endif /* SDL_USE_LIBUDEV */
     {
 #if defined(HAVE_INOTIFY)
@@ -805,14 +805,8 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
                                  uint8_t descriptor_index, uint16_t lang_id,
                                  unsigned char *data, int length)
 {
-    return libusb_control_transfer(dev,
-                                   LIBUSB_ENDPOINT_IN | 0x0, /* Endpoint 0 IN */
-                                   LIBUSB_REQUEST_GET_DESCRIPTOR,
-                                   (LIBUSB_DT_STRING << 8) | descriptor_index,
-                                   lang_id,
-                                   data,
-                                   (uint16_t) length,
-                                   1000);
+    return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id,
+                                   data, (uint16_t)length, 1000); /* Endpoint 0 IN */
 }
 #define libusb_get_string_descriptor SDL_libusb_get_string_descriptor
 #endif /* __FreeBSD__ */
@@ -1237,7 +1231,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
 #endif
         for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) {
             new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
-            if (!new_dev) {
+            if (new_dev == NULL) {
                 LIBUSB_hid_free_enumeration(usb_devs);
                 SDL_hid_free_enumeration(devs);
                 SDL_OutOfMemory();
@@ -1310,7 +1304,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
 #endif
             if (!bFound) {
                 new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
-                if (!new_dev) {
+                if (new_dev == NULL) {
 #ifdef HAVE_LIBUSB
                     if (libusb_ctx.libhandle) {
                         LIBUSB_hid_free_enumeration(usb_devs);

+ 80 - 74
src/joystick/SDL_gamecontroller.c

@@ -164,7 +164,7 @@ SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list)
         spot = (char *)hint;
     }
 
-    if (!spot) {
+    if (spot == NULL) {
         return;
     }
 
@@ -172,7 +172,7 @@ SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list)
         entry = (Uint16)SDL_strtol(spot, &spot, 0);
         entry <<= 16;
         spot = SDL_strstr(spot, "0x");
-        if (!spot) {
+        if (spot == NULL) {
             break;
         }
         entry |= (Uint16)SDL_strtol(spot, &spot, 0);
@@ -218,9 +218,9 @@ static SDL_bool HasSameOutput(SDL_ExtendedGameControllerBind *a, SDL_ExtendedGam
     }
 
     if (a->outputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
-        return (a->output.axis.axis == b->output.axis.axis);
+        return a->output.axis.axis == b->output.axis.axis;
     } else {
-        return (a->output.button == b->output.button);
+        return a->output.button == b->output.button;
     }
 }
 
@@ -262,7 +262,7 @@ static void HandleJoystickAxis(SDL_GameController *gamecontroller, int axis, int
         }
     }
 
-    if (last_match && (!match || !HasSameOutput(last_match, match))) {
+    if (last_match && (match == NULL || !HasSameOutput(last_match, match))) {
         /* Clear the last input that this axis generated */
         ResetOutput(gamecontroller, last_match);
     }
@@ -545,8 +545,7 @@ static ControllerMapping_t *SDL_CreateMappingForAndroidController(SDL_JoystickGU
         SDL_strlcat(mapping_string, "righttrigger:a5,", sizeof(mapping_string));
     }
 
-    return SDL_PrivateAddMappingForGUID(guid, mapping_string,
-                      &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
+    return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
 }
 #endif /* __ANDROID__ */
 
@@ -677,8 +676,7 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI
         }
     }
 
-    return SDL_PrivateAddMappingForGUID(guid, mapping_string,
-                      &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
+    return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
 }
 
 /*
@@ -692,8 +690,7 @@ static ControllerMapping_t *SDL_CreateMappingForRAWINPUTController(SDL_JoystickG
     SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
     SDL_strlcat(mapping_string, "a:b0,b:b1,x:b2,y:b3,back:b6,guide:b10,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", sizeof(mapping_string));
 
-    return SDL_PrivateAddMappingForGUID(guid, mapping_string,
-                      &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
+    return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
 }
 
 /*
@@ -711,8 +708,7 @@ static ControllerMapping_t *SDL_CreateMappingForWGIController(SDL_JoystickGUID g
     SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
     SDL_strlcat(mapping_string, "a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:b10,dpdown:b12,dpleft:b13,dpright:b11,leftx:a1,lefty:a0~,rightx:a3,righty:a2~,lefttrigger:a4,righttrigger:a5,", sizeof(mapping_string));
 
-    return SDL_PrivateAddMappingForGUID(guid, mapping_string,
-                      &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
+    return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
 }
 
 /*
@@ -804,7 +800,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
         return s_pXInputMapping;
     }
 #endif
-    if (!mapping) {
+    if (mapping == NULL) {
         if (SDL_IsJoystickHIDAPI(guid)) {
             mapping = SDL_CreateMappingForHIDAPIController(guid);
         } else if (SDL_IsJoystickRAWINPUT(guid)) {
@@ -843,13 +839,14 @@ SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(const char *pchString
         ++pchString;
     }
 
-    if (!pchString || !pchString[0]) {
+    if (pchString == NULL || !pchString[0]) {
         return SDL_CONTROLLER_AXIS_INVALID;
     }
 
     for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
-        if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry]))
-            return (SDL_GameControllerAxis) entry;
+        if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry])) {
+            return (SDL_GameControllerAxis)entry;
+        }
     }
     return SDL_CONTROLLER_AXIS_INVALID;
 }
@@ -896,12 +893,14 @@ static const char* map_StringForControllerButton[] = {
 SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchString)
 {
     int entry;
-    if (!pchString || !pchString[0])
+    if (pchString == NULL || !pchString[0]) {
         return SDL_CONTROLLER_BUTTON_INVALID;
+    }
 
     for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
-        if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0)
-            return (SDL_GameControllerButton) entry;
+        if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0) {
+            return (SDL_GameControllerButton)entry;
+        }
     }
     return SDL_CONTROLLER_BUTTON_INVALID;
 }
@@ -1110,7 +1109,7 @@ static char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping)
     const char *pFirstComma = SDL_strchr(pMapping, ',');
     if (pFirstComma) {
         char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
-        if (!pchGUID) {
+        if (pchGUID == NULL) {
             SDL_OutOfMemory();
             return NULL;
         }
@@ -1150,15 +1149,17 @@ static char *SDL_PrivateGetControllerNameFromMappingString(const char *pMapping)
     char *pchName;
 
     pFirstComma = SDL_strchr(pMapping, ',');
-    if (!pFirstComma)
+    if (pFirstComma == NULL) {
         return NULL;
+    }
 
     pSecondComma = SDL_strchr(pFirstComma + 1, ',');
-    if (!pSecondComma)
+    if (pSecondComma == NULL) {
         return NULL;
+    }
 
     pchName = SDL_malloc(pSecondComma - pFirstComma);
-    if (!pchName) {
+    if (pchName == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -1176,12 +1177,14 @@ static char *SDL_PrivateGetControllerMappingFromMappingString(const char *pMappi
     const char *pFirstComma, *pSecondComma;
 
     pFirstComma = SDL_strchr(pMapping, ',');
-    if (!pFirstComma)
+    if (pFirstComma == NULL) {
         return NULL;
+    }
 
     pSecondComma = SDL_strchr(pFirstComma + 1, ',');
-    if (!pSecondComma)
+    if (pSecondComma == NULL) {
         return NULL;
+    }
 
     return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */
 }
@@ -1221,13 +1224,13 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString,
     Uint16 crc;
 
     pchName = SDL_PrivateGetControllerNameFromMappingString(mappingString);
-    if (!pchName) {
+    if (pchName == NULL) {
         SDL_SetError("Couldn't parse name from %s", mappingString);
         return NULL;
     }
 
     pchMapping = SDL_PrivateGetControllerMappingFromMappingString(mappingString);
-    if (!pchMapping) {
+    if (pchMapping == NULL) {
         SDL_free(pchName);
         SDL_SetError("Couldn't parse %s", mappingString);
         return NULL;
@@ -1284,7 +1287,7 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString,
         *existing = SDL_TRUE;
     } else {
         pControllerMapping = SDL_malloc(sizeof(*pControllerMapping));
-        if (!pControllerMapping) {
+        if (pControllerMapping == NULL) {
             SDL_free(pchName);
             SDL_free(pchMapping);
             SDL_OutOfMemory();
@@ -1327,7 +1330,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
 
     mapping = SDL_PrivateGetControllerMappingForGUID(guid);
 #ifdef __LINUX__
-    if (!mapping && name) {
+    if (mapping == NULL && name) {
         if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
             /* The Linux driver xpad.c maps the wireless dpad to buttons */
             SDL_bool existing;
@@ -1340,7 +1343,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
     }
 #endif /* __LINUX__ */
 
-    if (!mapping) {
+    if (mapping == NULL) {
         mapping = s_pDefaultMapping;
     }
     return mapping;
@@ -1422,8 +1425,7 @@ static ControllerMapping_t *SDL_PrivateGenerateAutomaticControllerMapping(const
     SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "lefttrigger", &raw_map->lefttrigger);
     SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "righttrigger", &raw_map->righttrigger);
 
-    return SDL_PrivateAddMappingForGUID(guid, mapping,
-                      &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
+    return SDL_PrivateAddMappingForGUID(guid, mapping, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
 }
 
 static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
@@ -1437,13 +1439,13 @@ static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
     if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
         SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
         SDL_UnlockJoysticks();
-        return (NULL);
+        return NULL;
     }
 
     name = SDL_JoystickNameForIndex(device_index);
     guid = SDL_JoystickGetDeviceGUID(device_index);
     mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
-    if (!mapping) {
+    if (mapping == NULL) {
         SDL_GamepadMapping raw_map;
 
         SDL_zero(raw_map);
@@ -1540,7 +1542,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
     SDL_bool existing = SDL_FALSE;
     ControllerMapping_t *pControllerMapping;
 
-    if (!mappingString) {
+    if (mappingString == NULL) {
         return SDL_InvalidParamError("mappingString");
     }
 
@@ -1607,7 +1609,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
 #endif
 
     pchGUID = SDL_PrivateGetControllerGUIDFromMappingString(mappingString);
-    if (!pchGUID) {
+    if (pchGUID == NULL) {
         return SDL_SetError("Couldn't parse GUID from %s", mappingString);
     }
     if (!SDL_strcasecmp(pchGUID, "default")) {
@@ -1619,7 +1621,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
     SDL_free(pchGUID);
 
     pControllerMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing, priority);
-    if (!pControllerMapping) {
+    if (pControllerMapping == NULL) {
         return -1;
     }
 
@@ -1687,7 +1689,7 @@ CreateMappingString(ControllerMapping_t *mapping, SDL_JoystickGUID guid)
     }
 
     pMappingString = SDL_malloc(needed);
-    if (!pMappingString) {
+    if (pMappingString == NULL) {
         SDL_OutOfMemory();
         return NULL;
     }
@@ -1774,8 +1776,9 @@ SDL_GameControllerLoadHints()
             char *pchNewLine = NULL;
 
             pchNewLine = SDL_strchr(pUserMappings, '\n');
-            if (pchNewLine)
+            if (pchNewLine) {
                 *pchNewLine = '\0';
+            }
 
             SDL_PrivateGameControllerAddMapping(pUserMappings, SDL_CONTROLLER_MAPPING_PRIORITY_USER);
 
@@ -1837,7 +1840,7 @@ SDL_GameControllerInitMappings(void)
     SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT,
                         SDL_GameControllerIgnoreDevicesExceptChanged, NULL);
 
-    return (0);
+    return 0;
 }
 
 int
@@ -1858,7 +1861,7 @@ SDL_GameControllerInit(void)
         }
     }
 
-    return (0);
+    return 0;
 }
 
 
@@ -1926,7 +1929,7 @@ SDL_GameControllerMappingForDeviceIndex(int joystick_index)
         /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
         needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
         pMappingString = SDL_malloc(needed);
-        if (!pMappingString) {
+        if (pMappingString == NULL) {
             SDL_OutOfMemory();
             SDL_UnlockJoysticks();
             return NULL;
@@ -2081,14 +2084,14 @@ SDL_GameControllerOpen(int device_index)
                 gamecontroller = gamecontrollerlist;
                 ++gamecontroller->ref_count;
                 SDL_UnlockJoysticks();
-                return (gamecontroller);
+                return gamecontroller;
         }
         gamecontrollerlist = gamecontrollerlist->next;
     }
 
     /* Find a controller mapping */
     pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
-    if (!pSupportedController) {
+    if (pSupportedController == NULL) {
         SDL_SetError("Couldn't find mapping for device (%d)", device_index);
         SDL_UnlockJoysticks();
         return NULL;
@@ -2142,7 +2145,7 @@ SDL_GameControllerOpen(int device_index)
 
     SDL_UnlockJoysticks();
 
-    return (gamecontroller);
+    return gamecontroller;
 }
 
 /*
@@ -2373,7 +2376,7 @@ int SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_S
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
     int i;
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return -1;
     }
 
@@ -2435,7 +2438,7 @@ SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_Sens
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
     int i;
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return 0.0f;
     }
 
@@ -2467,7 +2470,7 @@ SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller,
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
     int i;
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return -1;
     }
 
@@ -2503,7 +2506,7 @@ SDL_GameControllerPath(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return NULL;
     }
     return SDL_JoystickPath(joystick);
@@ -2514,7 +2517,7 @@ SDL_GameControllerGetType(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return SDL_CONTROLLER_TYPE_UNKNOWN;
     }
     return SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGetGUID(joystick), SDL_JoystickName(joystick));
@@ -2525,7 +2528,7 @@ SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return -1;
     }
     return SDL_JoystickGetPlayerIndex(joystick);
@@ -2539,7 +2542,7 @@ SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return;
     }
     SDL_JoystickSetPlayerIndex(joystick, player_index);
@@ -2550,7 +2553,7 @@ SDL_GameControllerGetVendor(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return 0;
     }
     return SDL_JoystickGetVendor(joystick);
@@ -2561,7 +2564,7 @@ SDL_GameControllerGetProduct(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return 0;
     }
     return SDL_JoystickGetProduct(joystick);
@@ -2572,7 +2575,7 @@ SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return 0;
     }
     return SDL_JoystickGetProductVersion(joystick);
@@ -2583,7 +2586,7 @@ SDL_GameControllerGetFirmwareVersion(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return 0;
     }
     return SDL_JoystickGetFirmwareVersion(joystick);
@@ -2594,7 +2597,7 @@ SDL_GameControllerGetSerial(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return NULL;
     }
     return SDL_JoystickGetSerial(joystick);
@@ -2670,8 +2673,9 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController
 
     CHECK_GAMECONTROLLER_MAGIC(gamecontroller, bind);
 
-    if (axis == SDL_CONTROLLER_AXIS_INVALID)
+    if (axis == SDL_CONTROLLER_AXIS_INVALID) {
         return bind;
+    }
 
     for (i = 0; i < gamecontroller->num_bindings; ++i) {
         SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
@@ -2704,8 +2708,9 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameControll
 
     CHECK_GAMECONTROLLER_MAGIC(gamecontroller, bind);
 
-    if (button == SDL_CONTROLLER_BUTTON_INVALID)
+    if (button == SDL_CONTROLLER_BUTTON_INVALID) {
         return bind;
+    }
 
     for (i = 0; i < gamecontroller->num_bindings; ++i) {
         SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
@@ -2731,7 +2736,7 @@ SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequenc
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return -1;
     }
     return SDL_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
@@ -2742,7 +2747,7 @@ SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return -1;
     }
     return SDL_JoystickRumbleTriggers(joystick, left_rumble, right_rumble, duration_ms);
@@ -2753,7 +2758,7 @@ SDL_GameControllerHasLED(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return SDL_FALSE;
     }
     return SDL_JoystickHasLED(joystick);
@@ -2764,7 +2769,7 @@ SDL_GameControllerHasRumble(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return SDL_FALSE;
     }
     return SDL_JoystickHasRumble(joystick);
@@ -2775,7 +2780,7 @@ SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller)
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return SDL_FALSE;
     }
     return SDL_JoystickHasRumbleTriggers(joystick);
@@ -2786,7 +2791,7 @@ SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 gr
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return -1;
     }
     return SDL_JoystickSetLED(joystick, red, green, blue);
@@ -2797,7 +2802,7 @@ SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *dat
 {
     SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
 
-    if (!joystick) {
+    if (joystick == NULL) {
         return -1;
     }
     return SDL_JoystickSendEffect(joystick, data, size);
@@ -2808,8 +2813,9 @@ SDL_GameControllerClose(SDL_GameController *gamecontroller)
 {
     SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev;
 
-    if (!gamecontroller || gamecontroller->magic != &gamecontroller_magic)
+    if (gamecontroller == NULL || gamecontroller->magic != &gamecontroller_magic) {
         return;
+    }
 
     SDL_LockJoysticks();
 
@@ -2913,7 +2919,7 @@ SDL_PrivateGameControllerAxis(SDL_GameController *gamecontroller, SDL_GameContro
         posted = SDL_PushEvent(&event) == 1;
     }
 #endif /* !SDL_EVENTS_DISABLED */
-    return (posted);
+    return posted;
 }
 
 
@@ -2942,7 +2948,7 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont
         break;
     default:
         /* Invalid state -- bail */
-        return (0);
+        return 0;
     }
 #endif /* !SDL_EVENTS_DISABLED */
 
@@ -2953,12 +2959,12 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont
 
             if (gamecontroller->joystick->delayed_guide_button) {
                 /* Skip duplicate press */
-                return (0);
+                return 0;
             }
         } else {
             if (!SDL_TICKS_PASSED(now, gamecontroller->guide_button_down+SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS)) {
                 gamecontroller->joystick->delayed_guide_button = SDL_TRUE;
-                return (0);
+                return 0;
             }
             gamecontroller->joystick->delayed_guide_button = SDL_FALSE;
         }
@@ -2974,7 +2980,7 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont
         posted = SDL_PushEvent(&event) == 1;
     }
 #endif /* !SDL_EVENTS_DISABLED */
-    return (posted);
+    return posted;
 }
 
 /*
@@ -3009,7 +3015,7 @@ SDL_GameControllerEventState(int state)
         }
         break;
     }
-    return (state);
+    return state;
 #endif /* SDL_EVENTS_DISABLED */
 }
 

+ 19 - 22
src/joystick/SDL_joystick.c

@@ -257,7 +257,7 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id)
 
     if (player_index >= SDL_joystick_player_count) {
         SDL_JoystickID *new_players = (SDL_JoystickID *)SDL_realloc(SDL_joystick_players, (player_index + 1)*sizeof(*SDL_joystick_players));
-        if (!new_players) {
+        if (new_players == NULL) {
             SDL_OutOfMemory();
             return SDL_FALSE;
         }
@@ -309,7 +309,7 @@ SDL_JoystickInit(void)
     int i, status;
 
     /* Create the joystick list lock */
-    if (!SDL_joystick_lock) {
+    if (SDL_joystick_lock == NULL) {
         SDL_joystick_lock = SDL_CreateMutex();
     }
 
@@ -403,7 +403,7 @@ SDL_JoystickPathForIndex(int device_index)
     SDL_UnlockJoysticks();
 
     /* FIXME: Really we should reference count this path so it doesn't go away after unlock */
-    if (!path) {
+    if (path == NULL) {
         SDL_Unsupported();
     }
     return path;
@@ -1382,7 +1382,7 @@ static void UpdateEventsForDeviceRemoval(int device_index, Uint32 type)
     }
 
     events = SDL_small_alloc(SDL_Event, num_events, &isstack);
-    if (!events) {
+    if (events == NULL) {
         return;
     }
 
@@ -1903,10 +1903,10 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
         return SDL_strdup(custom_name);
     }
 
-    if (!vendor_name) {
+    if (vendor_name == NULL) {
         vendor_name = "";
     }
-    if (!product_name) {
+    if (product_name == NULL) {
         product_name = "";
     }
 
@@ -1958,7 +1958,7 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
         name = SDL_strdup("Controller");
     }
 
-    if (!name) {
+    if (name == NULL) {
         return NULL;
     }
 
@@ -2023,7 +2023,7 @@ SDL_CreateJoystickGUID(Uint16 bus, Uint16 vendor, Uint16 product, Uint16 version
 
     SDL_zero(guid);
 
-    if (!name) {
+    if (name == NULL) {
         name = "";
     }
 
@@ -2213,7 +2213,7 @@ SDL_bool
 SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_XBoxOneController);
+    return eType == k_eControllerType_XBoxOneController;
 }
 
 SDL_bool
@@ -2287,71 +2287,68 @@ SDL_bool
 SDL_IsJoystickPS4(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_PS4Controller);
+    return eType == k_eControllerType_PS4Controller;
 }
 
 SDL_bool
 SDL_IsJoystickPS5(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_PS5Controller);
+    return eType == k_eControllerType_PS5Controller;
 }
 
 SDL_bool
 SDL_IsJoystickNintendoSwitchPro(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_SwitchProController ||
-            eType == k_eControllerType_SwitchInputOnlyController);
+    return eType == k_eControllerType_SwitchProController || eType == k_eControllerType_SwitchInputOnlyController;
 }
 
 SDL_bool
 SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_SwitchInputOnlyController);
+    return eType == k_eControllerType_SwitchInputOnlyController;
 }
 
 SDL_bool
 SDL_IsJoystickNintendoSwitchJoyCon(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_SwitchJoyConLeft ||
-            eType == k_eControllerType_SwitchJoyConRight);
+    return eType == k_eControllerType_SwitchJoyConLeft || eType == k_eControllerType_SwitchJoyConRight;
 }
 
 SDL_bool
 SDL_IsJoystickNintendoSwitchJoyConLeft(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_SwitchJoyConLeft);
+    return eType == k_eControllerType_SwitchJoyConLeft;
 }
 
 SDL_bool
 SDL_IsJoystickNintendoSwitchJoyConRight(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_SwitchJoyConRight);
+    return eType == k_eControllerType_SwitchJoyConRight;
 }
 
 SDL_bool
 SDL_IsJoystickNintendoSwitchJoyConGrip(Uint16 vendor_id, Uint16 product_id)
 {
-    return (vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP);
+    return vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP;
 }
 
 SDL_bool
 SDL_IsJoystickNintendoSwitchJoyConPair(Uint16 vendor_id, Uint16 product_id)
 {
-    return (vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR);
+    return vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR;
 }
 
 SDL_bool
 SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id)
 {
     EControllerType eType = GuessControllerType(vendor_id, product_id);
-    return (eType == k_eControllerType_SteamController ||
-            eType == k_eControllerType_SteamControllerV2);
+    return eType == k_eControllerType_SteamController || eType == k_eControllerType_SteamControllerV2;
 }
 
 SDL_bool

+ 1 - 1
src/joystick/android/SDL_sysjoystick.c

@@ -615,7 +615,7 @@ ANDROID_JoystickOpen(SDL_Joystick *joystick, int device_index)
     joystick->nbuttons = item->nbuttons;
     joystick->naxes = item->naxes;
 
-    return (0);
+    return 0;
 }
 
 static int

+ 14 - 13
src/joystick/bsd/SDL_bsdjoystick.c

@@ -320,8 +320,9 @@ CreateHwData(const char *path)
         hw->type = BSDJOY_UHID;
         {
             int ax;
-            for (ax = 0; ax < JOYAXE_count; ax++)
+            for (ax = 0; ax < JOYAXE_count; ax++) {
                 hw->axis_map[ax] = -1;
+            }
         }
         hw->repdesc = hid_get_report_desc(fd);
         if (hw->repdesc == NULL) {
@@ -355,8 +356,9 @@ CreateHwData(const char *path)
             SDL_SetError("%s: Cannot start HID parser", path);
             goto usberr;
         }
-        for (i = 0; i < JOYAXE_count; i++)
+        for (i = 0; i < JOYAXE_count; i++) {
             hw->axis_map[i] = -1;
+        }
 
         while (hid_get_item(hdata, &hitem) > 0) {
             switch (hitem.kind) {
@@ -394,9 +396,11 @@ CreateHwData(const char *path)
             }
         }
         hid_end_parse(hdata);
-        for (i = 0; i < JOYAXE_count; i++)
-            if (hw->axis_map[i] > 0)
+        for (i = 0; i < JOYAXE_count; i++) {
+            if (hw->axis_map[i] > 0) {
                 hw->axis_map[i] = hw->naxes++;
+            }
+        }
 
         if (hw->naxes == 0 && hw->nbuttons == 0 && hw->nhats == 0) {
             SDL_SetError("%s: Not a joystick, ignoring", path);
@@ -446,7 +450,7 @@ MaybeAddDevice(const char *path)
     }
 
     hw = CreateHwData(path);
-    if (!hw) {
+    if (hw == NULL) {
         return -1;
     }
 
@@ -476,7 +480,7 @@ MaybeAddDevice(const char *path)
         }
 #endif /* USB_GET_DEVICEINFO */
     }
-    if (!name) {
+    if (name == NULL) {
         name = SDL_strdup(path);
         guid = SDL_CreateJoystickGUIDForName(name);
     }
@@ -633,7 +637,7 @@ BSD_JoystickOpen(SDL_Joystick *joy, int device_index)
     }
 
     hw = CreateHwData(item->path);
-    if (!hw) {
+    if (hw == NULL) {
         return -1;
     }
 
@@ -738,16 +742,13 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
                         else if (usage == HUG_DPAD_UP) {
                             dpad[0] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
                             SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
-                        }
-                        else if (usage == HUG_DPAD_DOWN) {
+                        } else if (usage == HUG_DPAD_DOWN) {
                             dpad[1] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
                             SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
-                        }
-                        else if (usage == HUG_DPAD_RIGHT) {
+                        } else if (usage == HUG_DPAD_RIGHT) {
                             dpad[2] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
                             SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
-                        }
-                        else if (usage == HUG_DPAD_LEFT) {
+                        } else if (usage == HUG_DPAD_LEFT) {
                             dpad[3] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
                             SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
                         }

+ 12 - 14
src/joystick/darwin/SDL_iokitjoystick.c

@@ -41,7 +41,7 @@ static recDevice *gpDeviceList = NULL;
 
 void FreeRumbleEffectData(FFEFFECT *effect)
 {
-    if (!effect) {
+    if (effect == NULL) {
         return;
     }
     SDL_free(effect->rgdwAxes);
@@ -57,7 +57,7 @@ FFEFFECT *CreateRumbleEffectData(Sint16 magnitude)
 
     /* Create the effect */
     effect = (FFEFFECT *)SDL_calloc(1, sizeof(*effect));
-    if (!effect) {
+    if (effect == NULL) {
         return NULL;
     }
     effect->dwSize = sizeof(*effect);
@@ -81,7 +81,7 @@ FFEFFECT *CreateRumbleEffectData(Sint16 magnitude)
     effect->dwFlags |= FFEFF_CARTESIAN;
 
     periodic = (FFPERIODIC *)SDL_calloc(1, sizeof(*periodic));
-    if (!periodic) {
+    if (periodic == NULL) {
         FreeRumbleEffectData(effect);
         return NULL;
     }
@@ -99,8 +99,9 @@ static recDevice *GetDeviceForIndex(int device_index)
     recDevice *device = gpDeviceList;
     while (device) {
         if (!device->removed) {
-            if (device_index == 0)
+            if (device_index == 0) {
                 break;
+            }
 
             --device_index;
         }
@@ -206,13 +207,10 @@ GetHIDScaledCalibratedState(recDevice * pDevice, recElement * pElement, SInt32 m
     const float deviceScale = max - min;
     const float readScale = pElement->maxReport - pElement->minReport;
     int returnValue = SDL_FALSE;
-    if (GetHIDElementState(pDevice, pElement, pValue))
-    {
+    if (GetHIDElementState(pDevice, pElement, pValue)) {
         if (readScale == 0) {
             returnValue = SDL_TRUE;           /* no scaling at all */
-        }
-        else
-        {
+        } else {
             *pValue = ((*pValue - pElement->minReport) * deviceScale / readScale) + min;
             returnValue = SDL_TRUE;
         }
@@ -545,7 +543,7 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic
     }
 
     device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
-    if (!device) {
+    if (device == NULL) {
         SDL_OutOfMemory();
         return;
     }
@@ -578,7 +576,7 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic
     }
 
     /* Add device to the end of the list */
-    if ( !gpDeviceList ) {
+    if (gpDeviceList == NULL) {
         gpDeviceList = device;
     } else {
         recDevice *curdevice;
@@ -889,7 +887,7 @@ DARWIN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint1
     /* Scale and average the two rumble strengths */
     Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2);
     
-    if (!device) {
+    if (device == NULL) {
         return SDL_SetError("Rumble failed, device disconnected");
     }
 
@@ -932,7 +930,7 @@ DARWIN_JoystickGetCapabilities(SDL_Joystick *joystick)
     recDevice *device = joystick->hwdata;
     Uint32 result = 0;
 
-    if (!device) {
+    if (device == NULL) {
         return 0;
     }
 
@@ -969,7 +967,7 @@ DARWIN_JoystickUpdate(SDL_Joystick *joystick)
     SInt32 value, range;
     int i, goodRead = SDL_FALSE;
 
-    if (!device) {
+    if (device == NULL) {
         return;
     }
 

+ 12 - 12
src/joystick/emscripten/SDL_sysjoystick.c

@@ -73,11 +73,11 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa
 
     item->timestamp = gamepadEvent->timestamp;
 
-    for( i = 0; i < item->naxes; i++) {
+    for ( i = 0; i < item->naxes; i++) {
         item->axis[i] = gamepadEvent->axis[i];
     }
 
-    for( i = 0; i < item->nbuttons; i++) {
+    for ( i = 0; i < item->nbuttons; i++) {
         item->analogButton[i] = gamepadEvent->analogButton[i];
         item->digitalButton[i] = gamepadEvent->digitalButton[i];
     }
@@ -195,7 +195,7 @@ EMSCRIPTEN_JoystickInit(void)
 
     /* handle already connected gamepads */
     if (numjs > 0) {
-        for(i = 0; i < numjs; i++) {
+        for (i = 0; i < numjs; i++) {
             retval = emscripten_get_gamepad_status(i, &gamepadState);
             if (retval == EMSCRIPTEN_RESULT_SUCCESS) {
                 Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED,
@@ -209,7 +209,7 @@ EMSCRIPTEN_JoystickInit(void)
                                                       0,
                                                       Emscripten_JoyStickConnected);
 
-    if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
+    if (retval != EMSCRIPTEN_RESULT_SUCCESS) {
         EMSCRIPTEN_JoystickQuit();
         return SDL_SetError("Could not set gamepad connect callback");
     }
@@ -217,7 +217,7 @@ EMSCRIPTEN_JoystickInit(void)
     retval = emscripten_set_gamepaddisconnected_callback(NULL,
                                                          0,
                                                          Emscripten_JoyStickDisconnected);
-    if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
+    if (retval != EMSCRIPTEN_RESULT_SUCCESS) {
         EMSCRIPTEN_JoystickQuit();
         return SDL_SetError("Could not set gamepad disconnect callback");
     }
@@ -328,7 +328,7 @@ EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
     joystick->nbuttons = item->nbuttons;
     joystick->naxes = item->naxes;
 
-    return (0);
+    return 0;
 }
 
 /* Function to update the state of a joystick - called as a device poll.
@@ -347,10 +347,10 @@ EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
 
     if (item) {
         result = emscripten_get_gamepad_status(item->index, &gamepadState);
-        if( result == EMSCRIPTEN_RESULT_SUCCESS) {
-            if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
-                for(i = 0; i < item->nbuttons; i++) {
-                    if(item->digitalButton[i] != gamepadState.digitalButton[i]) {
+        if ( result == EMSCRIPTEN_RESULT_SUCCESS) {
+            if (gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
+                for (i = 0; i < item->nbuttons; i++) {
+                    if (item->digitalButton[i] != gamepadState.digitalButton[i]) {
                         buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
                         SDL_PrivateJoystickButton(item->joystick, i, buttonState);
                     }
@@ -360,8 +360,8 @@ EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
                     item->digitalButton[i] = gamepadState.digitalButton[i];
                 }
 
-                for(i = 0; i < item->naxes; i++) {
-                    if(item->axis[i] != gamepadState.axis[i]) {
+                for (i = 0; i < item->naxes; i++) {
+                    if (item->axis[i] != gamepadState.axis[i]) {
                         /* do we need to do conversion? */
                         SDL_PrivateJoystickAxis(item->joystick, i,
                                                   (Sint16) (32767.*gamepadState.axis[i]));

+ 1 - 2
src/joystick/haiku/SDL_haikujoystick.cc

@@ -67,8 +67,7 @@ extern "C"
         numjoysticks = 0;
         SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
         SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
-        for (i = 0; (numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
-        {
+        for (i = 0; (numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i) {
             if (joystick.GetDeviceName(i, name) == B_OK) {
                 if (joystick.Open(name) != B_ERROR) {
                       BString stick_name;

+ 2 - 2
src/joystick/hidapi/SDL_hidapi_gamecube.c

@@ -141,7 +141,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
 #endif
 
     ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -253,7 +253,7 @@ HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_Driver
     }
 
     joystick = SDL_JoystickFromInstanceID(ctx->joysticks[i]);
-    if (!joystick) {
+    if (joystick == NULL) {
         /* Hasn't been opened yet, skip */
         return;
     }

+ 7 - 12
src/joystick/hidapi/SDL_hidapi_luna.c

@@ -63,9 +63,7 @@ HIDAPI_DriverLuna_UnregisterHints(SDL_HintCallback callback, void *userdata)
 static SDL_bool
 HIDAPI_DriverLuna_IsEnabled(void)
 {
-    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_LUNA,
-               SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
-                   SDL_HIDAPI_DEFAULT));
+    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_LUNA, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
 }
 
 static SDL_bool
@@ -80,7 +78,7 @@ HIDAPI_DriverLuna_InitDevice(SDL_HIDAPI_Device *device)
     SDL_DriverLuna_Context *ctx;
 
     ctx = (SDL_DriverLuna_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -286,14 +284,11 @@ HIDAPI_DriverLuna_HandleBluetoothStatePacket(SDL_Joystick *joystick, SDL_DriverL
         int level = data[1] * 100 / 0xFF;
         if (level == 0) {
             SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_EMPTY);
-        }
-        else if (level <= 20) {
+        } else if (level <= 20) {
             SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_LOW);
-        }
-        else if (level <= 70) {
+        } else if (level <= 70) {
             SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_MEDIUM);
-        }
-        else {
+        } else {
             SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_FULL);
         }
 
@@ -413,7 +408,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device)
 #ifdef DEBUG_LUNA_PROTOCOL
         HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size);
 #endif
-        if (!joystick) {
+        if (joystick == NULL) {
             continue;
         }
 
@@ -431,7 +426,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Read error, device is disconnected */
         HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
     }
-    return (size >= 0);
+    return size >= 0;
 }
 
 static void

+ 7 - 7
src/joystick/hidapi/SDL_hidapi_ps3.c

@@ -140,7 +140,7 @@ HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
     }
 
     ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -223,7 +223,7 @@ HIDAPI_DriverPS3_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID
 {
     SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context;
 
-    if (!ctx) {
+    if (ctx == NULL) {
         return;
     }
 
@@ -506,7 +506,7 @@ HIDAPI_DriverPS3_UpdateDevice(SDL_HIDAPI_Device *device)
 #ifdef DEBUG_PS3_PROTOCOL
         HIDAPI_DumpPacket("PS3 packet: size = %d", data, size);
 #endif
-        if (!joystick) {
+        if (joystick == NULL) {
             continue;
         }
 
@@ -548,7 +548,7 @@ HIDAPI_DriverPS3_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Read error, device is disconnected */
         HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
     }
-    return (size >= 0);
+    return size >= 0;
 }
 
 static void
@@ -629,7 +629,7 @@ HIDAPI_DriverPS3ThirdParty_InitDevice(SDL_HIDAPI_Device *device)
     SDL_DriverPS3_Context *ctx;
 
     ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -837,7 +837,7 @@ HIDAPI_DriverPS3ThirdParty_UpdateDevice(SDL_HIDAPI_Device *device)
 #ifdef DEBUG_PS3_PROTOCOL
         HIDAPI_DumpPacket("PS3 packet: size = %d", data, size);
 #endif
-        if (!joystick) {
+        if (joystick == NULL) {
             continue;
         }
 
@@ -854,7 +854,7 @@ HIDAPI_DriverPS3ThirdParty_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Read error, device is disconnected */
         HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
     }
-    return (size >= 0);
+    return size >= 0;
 }
 
 static void

+ 5 - 7
src/joystick/hidapi/SDL_hidapi_ps4.c

@@ -167,9 +167,7 @@ HIDAPI_DriverPS4_UnregisterHints(SDL_HintCallback callback, void *userdata)
 static SDL_bool
 HIDAPI_DriverPS4_IsEnabled(void)
 {
-    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4,
-               SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
-                   SDL_HIDAPI_DEFAULT));
+    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
 }
 
 static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
@@ -244,7 +242,7 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
     SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
 
     ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -421,7 +419,7 @@ HIDAPI_DriverPS4_LoadCalibrationData(SDL_HIDAPI_Device *device)
         return;
     }
 
-    for( tries = 0; tries < 5; ++tries ) {
+    for ( tries = 0; tries < 5; ++tries ) {
         /* For Bluetooth controllers, this report switches them into advanced report mode */
         size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdGyroCalibration_USB, data, sizeof(data));
         if (size < 35) {
@@ -1072,7 +1070,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
         ++packet_count;
         ctx->last_packet = now;
 
-        if (!joystick) {
+        if (joystick == NULL) {
             continue;
         }
 
@@ -1146,7 +1144,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Read error, device is disconnected */
         HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
     }
-    return (size >= 0);
+    return size >= 0;
 }
 
 static void

+ 4 - 6
src/joystick/hidapi/SDL_hidapi_ps5.c

@@ -250,9 +250,7 @@ HIDAPI_DriverPS5_UnregisterHints(SDL_HintCallback callback, void *userdata)
 static SDL_bool
 HIDAPI_DriverPS5_IsEnabled(void)
 {
-    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5,
-               SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
-                   SDL_HIDAPI_DEFAULT));
+    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
 }
 
 static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
@@ -345,7 +343,7 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
     SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
 
     ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -1350,7 +1348,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
         ++packet_count;
         ctx->last_packet = now;
 
-        if (!joystick) {
+        if (joystick == NULL) {
             continue;
         }
 
@@ -1410,7 +1408,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Read error, device is disconnected */
         HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
     }
-    return (size >= 0);
+    return size >= 0;
 }
 
 static void

+ 1 - 1
src/joystick/hidapi/SDL_hidapi_rumble.c

@@ -213,7 +213,7 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const
     }
 
     request = (SDL_HIDAPI_RumbleRequest *)SDL_calloc(1, sizeof(*request));
-    if (!request) {
+    if (request == NULL) {
         SDL_HIDAPI_UnlockRumble();
         return SDL_OutOfMemory();
     }

+ 5 - 7
src/joystick/hidapi/SDL_hidapi_shield.c

@@ -103,9 +103,7 @@ HIDAPI_DriverShield_UnregisterHints(SDL_HintCallback callback, void *userdata)
 static SDL_bool
 HIDAPI_DriverShield_IsEnabled(void)
 {
-    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SHIELD,
-               SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
-                   SDL_HIDAPI_DEFAULT));
+    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SHIELD, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
 }
 
 static SDL_bool
@@ -120,7 +118,7 @@ HIDAPI_DriverShield_InitDevice(SDL_HIDAPI_Device *device)
     SDL_DriverShield_Context *ctx;
 
     ctx = (SDL_DriverShield_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -504,7 +502,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Byte 0 is HID report ID */
         switch (data[0]) {
             case k_ShieldReportIdControllerState:
-                if (!joystick) {
+                if (joystick == NULL) {
                     break;
                 }
                 if (size == 16) {
@@ -514,7 +512,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
                 }
                 break;
             case k_ShieldReportIdControllerTouch:
-                if (!joystick) {
+                if (joystick == NULL) {
                     break;
                 }
                 HIDAPI_DriverShield_HandleTouchPacketV103(joystick, ctx, data, size);
@@ -578,7 +576,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Read error, device is disconnected */
         HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
     }
-    return (size >= 0);
+    return size >= 0;
 }
 
 static void

+ 4 - 6
src/joystick/hidapi/SDL_hidapi_stadia.c

@@ -59,9 +59,7 @@ HIDAPI_DriverStadia_UnregisterHints(SDL_HintCallback callback, void *userdata)
 static SDL_bool
 HIDAPI_DriverStadia_IsEnabled(void)
 {
-    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STADIA,
-               SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
-                   SDL_HIDAPI_DEFAULT));
+    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STADIA, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
 }
 
 static SDL_bool
@@ -76,7 +74,7 @@ HIDAPI_DriverStadia_InitDevice(SDL_HIDAPI_Device *device)
     SDL_DriverStadia_Context *ctx;
 
     ctx = (SDL_DriverStadia_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -280,7 +278,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device)
 #ifdef DEBUG_STADIA_PROTOCOL
         HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size);
 #endif
-        if (!joystick) {
+        if (joystick == NULL) {
             continue;
         }
 
@@ -291,7 +289,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Read error, device is disconnected */
         HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
     }
-    return (size >= 0);
+    return size >= 0;
 }
 
 static void

+ 93 - 138
src/joystick/hidapi/SDL_hidapi_steam.c

@@ -199,8 +199,9 @@ static uint8_t GetSegmentHeader( int nSegmentNumber, bool bLastPacket )
 {
     uint8_t header = REPORT_SEGMENT_DATA_FLAG;
     header |= nSegmentNumber;
-    if ( bLastPacket )
+    if (bLastPacket) {
         header |= REPORT_SEGMENT_LAST_FLAG;
+    }
     
     return header;
 }
@@ -208,8 +209,9 @@ static uint8_t GetSegmentHeader( int nSegmentNumber, bool bLastPacket )
 static void hexdump( const uint8_t *ptr, int len )
 {
     int i;
-    for ( i = 0; i < len ; ++i )
+    for (i = 0; i < len; ++i) {
         printf("%02x ", ptr[i]);
+    }
     printf("\n");
 }
 
@@ -232,21 +234,18 @@ static void InitializeSteamControllerPacketAssembler( SteamControllerPacketAssem
 //     Complete packet size on completion
 static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAssembler *pAssembler, const uint8_t *pSegment, int nSegmentLength )
 {
-    if ( pAssembler->bIsBle )
-    {
+    if ( pAssembler->bIsBle ) {
         uint8_t uSegmentHeader = pSegment[ 1 ];
         int nSegmentNumber = uSegmentHeader & 0x07;
 
         HEXDUMP( pSegment, nSegmentLength );
 
-        if ( pSegment[ 0 ] != BLE_REPORT_NUMBER )
-        {
+        if ( pSegment[ 0 ] != BLE_REPORT_NUMBER ) {
             // We may get keyboard/mouse input events until controller stops sending them
             return 0;
         }
         
-        if ( nSegmentLength != MAX_REPORT_SEGMENT_SIZE )
-        {
+        if ( nSegmentLength != MAX_REPORT_SEGMENT_SIZE ) {
             printf( "Bad segment size! %d\n", (int)nSegmentLength );
             hexdump( pSegment, nSegmentLength );
             ResetSteamControllerPacketAssembler( pAssembler );
@@ -255,18 +254,15 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs
         
         DPRINTF("GOT PACKET HEADER = 0x%x\n", uSegmentHeader);
         
-        if ( ( uSegmentHeader & REPORT_SEGMENT_DATA_FLAG ) == 0 )
-        {
+        if ( ( uSegmentHeader & REPORT_SEGMENT_DATA_FLAG ) == 0 ) {
             // We get empty segments, just ignore them
             return 0;
         }
         
-        if ( nSegmentNumber != pAssembler->nExpectedSegmentNumber )
-        {
+        if ( nSegmentNumber != pAssembler->nExpectedSegmentNumber ) {
             ResetSteamControllerPacketAssembler( pAssembler );
             
-            if ( nSegmentNumber )
-            {
+            if ( nSegmentNumber ) {
                 // This happens occasionally
                 DPRINTF("Bad segment number, got %d, expected %d\n",
                     nSegmentNumber, pAssembler->nExpectedSegmentNumber );
@@ -278,16 +274,13 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs
                pSegment + 2, // ignore header and report number
                MAX_REPORT_SEGMENT_PAYLOAD_SIZE );
         
-        if ( uSegmentHeader & REPORT_SEGMENT_LAST_FLAG )
-        {
+        if ( uSegmentHeader & REPORT_SEGMENT_LAST_FLAG ) {
             pAssembler->nExpectedSegmentNumber = 0;
             return ( nSegmentNumber + 1 ) * MAX_REPORT_SEGMENT_PAYLOAD_SIZE;
         }
         
         pAssembler->nExpectedSegmentNumber++;
-    }
-    else
-    {
+    } else {
         // Just pass through
         SDL_memcpy( pAssembler->uBuffer,
                pSegment,
@@ -307,20 +300,19 @@ static int SetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65], int
     
     DPRINTF("SetFeatureReport %p %p %d\n", dev, uBuffer, nActualDataLen);
 
-    if ( bBle )
-    {
+    if ( bBle ) {
         int nSegmentNumber = 0;
         uint8_t uPacketBuffer[ MAX_REPORT_SEGMENT_SIZE ];
         unsigned char *pBufferPtr = uBuffer + 1;
 
-        if ( nActualDataLen < 1 )
+        if (nActualDataLen < 1) {
             return -1;
+        }
         
         // Skip report number in data
         nActualDataLen--;
         
-        while ( nActualDataLen > 0 )
-        {
+        while ( nActualDataLen > 0 ) {
             int nBytesInPacket = nActualDataLen > MAX_REPORT_SEGMENT_PAYLOAD_SIZE ? MAX_REPORT_SEGMENT_PAYLOAD_SIZE : nActualDataLen;
             
             nActualDataLen -= nBytesInPacket;
@@ -349,8 +341,7 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
 
     DPRINTF("GetFeatureReport( %p %p )\n", dev, uBuffer );
 
-    if ( bBle )
-    {
+    if ( bBle ) {
         int nRetries = 0;
         uint8_t uSegmentBuffer[ MAX_REPORT_SEGMENT_SIZE + 1 ];
         uint8_t ucBytesToRead = MAX_REPORT_SEGMENT_SIZE;
@@ -367,8 +358,7 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
         ++ucDataStartOffset;
 #endif
 
-        while( nRetries < BLE_MAX_READ_RETRIES )
-        {
+        while ( nRetries < BLE_MAX_READ_RETRIES ) {
             SDL_memset( uSegmentBuffer, 0, sizeof( uSegmentBuffer ) );
             uSegmentBuffer[ 0 ] = BLE_REPORT_NUMBER;
             nRet = SDL_hid_get_feature_report( dev, uSegmentBuffer, ucBytesToRead );
@@ -382,14 +372,12 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
             else
                 nRetries++;
 
-            if ( nRet > 0 )
-            {
+            if ( nRet > 0 ) {
                 int nPacketLength = WriteSegmentToSteamControllerPacketAssembler( &assembler,
                                                                                  uSegmentBuffer + ucDataStartOffset,
                                                                                  nRet - ucDataStartOffset );
                 
-                if ( nPacketLength > 0 && nPacketLength < 65 )
-                {
+                if ( nPacketLength > 0 && nPacketLength < 65 ) {
                     // Leave space for "report number"
                     uBuffer[ 0 ] = 0;
                     SDL_memcpy( uBuffer + 1, assembler.uBuffer, nPacketLength );
@@ -412,14 +400,16 @@ static int ReadResponse( SDL_hid_device *dev, uint8_t uBuffer[65], int nExpected
 
     DPRINTF("ReadResponse( %p %p %d )\n", dev, uBuffer, nExpectedResponse );
 
-    if ( nRet < 0 )
+    if (nRet < 0) {
         return nRet;
+    }
     
     DPRINTF("ReadResponse got %d bytes of data: ", nRet );
     HEXDUMP( uBuffer, nRet );
     
-    if ( uBuffer[1] != nExpectedResponse )
+    if (uBuffer[1] != nExpectedResponse) {
         return -1;
+    }
     
     return nRet;
 }
@@ -443,35 +433,34 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew,
     buf[0] = 0;
     buf[1] = ID_GET_ATTRIBUTES_VALUES;
     res = SetFeatureReport( dev, buf, 2 );
-    if ( res < 0 )
-    {
-        if ( !bSuppressErrorSpew )
-            printf( "GET_ATTRIBUTES_VALUES failed for controller %p\n", dev );
+    if ( res < 0 ) {
+        if (!bSuppressErrorSpew) {
+            printf("GET_ATTRIBUTES_VALUES failed for controller %p\n", dev);
+        }
         return false;
     }
     
     // Retrieve GET_ATTRIBUTES_VALUES result
     // Wireless controller endpoints without a connected controller will return nAttrs == 0
     res = ReadResponse( dev, buf, ID_GET_ATTRIBUTES_VALUES );
-    if ( res < 0 || buf[1] != ID_GET_ATTRIBUTES_VALUES )
-    {
+    if ( res < 0 || buf[1] != ID_GET_ATTRIBUTES_VALUES ) {
         HEXDUMP(buf, res);
-        if ( !bSuppressErrorSpew )
-            printf( "Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev );
+        if (!bSuppressErrorSpew) {
+            printf("Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev);
+        }
         return false;
     }
     
     nAttributesLength = buf[ 2 ];
-    if ( nAttributesLength > res )
-    {
-        if ( !bSuppressErrorSpew )
-            printf( "Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev );
+    if ( nAttributesLength > res ) {
+        if (!bSuppressErrorSpew) {
+            printf("Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev);
+        }
         return false;
     }
 
     msg = (FeatureReportMsg *)&buf[1];
-    for ( i = 0; i < (int)msg->header.length / sizeof( ControllerAttribute ); ++i )
-    {
+    for ( i = 0; i < (int)msg->header.length / sizeof( ControllerAttribute ); ++i ) {
         uint8_t unAttribute = msg->payload.getAttributes.attributes[i].attributeTag;
         uint32_t unValue = msg->payload.getAttributes.attributes[i].attributeValue;
 
@@ -490,8 +479,7 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew,
             break;
         }
     }
-    if ( punUpdateRateUS )
-    {
+    if ( punUpdateRateUS ) {
         *punUpdateRateUS = unUpdateRateUS;
     }
 
@@ -499,10 +487,10 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew,
     buf[0] = 0;
     buf[1] = ID_CLEAR_DIGITAL_MAPPINGS;
     res = SetFeatureReport( dev, buf, 2 );
-    if ( res < 0 )
-    {
-        if ( !bSuppressErrorSpew )
-            printf( "CLEAR_DIGITAL_MAPPINGS failed for controller %p\n", dev );
+    if ( res < 0 ) {
+        if (!bSuppressErrorSpew) {
+            printf("CLEAR_DIGITAL_MAPPINGS failed for controller %p\n", dev);
+        }
         return false;
     }
     
@@ -511,10 +499,10 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew,
     buf[1] = ID_LOAD_DEFAULT_SETTINGS;
     buf[2] = 0;
     res = SetFeatureReport( dev, buf, 3 );
-    if ( res < 0 )
-    {
-        if ( !bSuppressErrorSpew )
-            printf( "LOAD_DEFAULT_SETTINGS failed for controller %p\n", dev );
+    if ( res < 0 ) {
+        if (!bSuppressErrorSpew) {
+            printf("LOAD_DEFAULT_SETTINGS failed for controller %p\n", dev);
+        }
         return false;
     }
     
@@ -541,10 +529,10 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
     buf[2] = nSettings*3;
     
     res = SetFeatureReport( dev, buf, 3+nSettings*3 );
-    if ( res < 0 )
-    {
-        if ( !bSuppressErrorSpew )
-            printf( "SET_SETTINGS failed for controller %p\n", dev );
+    if ( res < 0 ) {
+        if (!bSuppressErrorSpew) {
+            printf("SET_SETTINGS failed for controller %p\n", dev);
+        }
         return false;
     }
     
@@ -552,37 +540,32 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
     // Wait for ID_CLEAR_DIGITAL_MAPPINGS to be processed on the controller
     bool bMappingsCleared = false;
     int iRetry;
-    for ( iRetry = 0; iRetry < 2; ++iRetry )
-    {
+    for ( iRetry = 0; iRetry < 2; ++iRetry ) {
         SDL_memset( buf, 0, 65 );
         buf[1] = ID_GET_DIGITAL_MAPPINGS;
         buf[2] = 1; // one byte - requesting from index 0
         buf[3] = 0;
         res = SetFeatureReport( dev, buf, 4 );
-        if ( res < 0 )
-        {
+        if ( res < 0 ) {
             printf( "GET_DIGITAL_MAPPINGS failed for controller %p\n", dev );
             return false;
         }
         
         res = ReadResponse( dev, buf, ID_GET_DIGITAL_MAPPINGS );
-        if ( res < 0 || buf[1] != ID_GET_DIGITAL_MAPPINGS )
-        {
+        if ( res < 0 || buf[1] != ID_GET_DIGITAL_MAPPINGS ) {
             printf( "Bad GET_DIGITAL_MAPPINGS response for controller %p\n", dev );
             return false;
         }
         
         // If the length of the digital mappings result is not 1 (index byte, no mappings) then clearing hasn't executed
-        if ( buf[2] == 1 && buf[3] == 0xFF )
-        {
+        if ( buf[2] == 1 && buf[3] == 0xFF ) {
             bMappingsCleared = true;
             break;
         }
         usleep( CONTROLLER_CONFIGURATION_DELAY_US );
     }
     
-    if ( !bMappingsCleared && !bSuppressErrorSpew )
-    {
+    if ( !bMappingsCleared && !bSuppressErrorSpew ) {
         printf( "Warning: CLEAR_DIGITAL_MAPPINGS never completed for controller %p\n", dev );
     }
     
@@ -598,10 +581,10 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
     buf[8] = MOUSE_BTN_RIGHT;
     
     res = SetFeatureReport( dev, buf, 9 );
-    if ( res < 0 )
-    {
-        if ( !bSuppressErrorSpew )
-            printf( "SET_DIGITAL_MAPPINGS failed for controller %p\n", dev );
+    if ( res < 0 ) {
+        if (!bSuppressErrorSpew) {
+            printf("SET_DIGITAL_MAPPINGS failed for controller %p\n", dev);
+        }
         return false;
     }
 #endif // ENABLE_MOUSE_MODE
@@ -655,12 +638,9 @@ static void CloseSteamController( SDL_hid_device *dev )
 //---------------------------------------------------------------------------
 static float RemapValClamped( float val, float A, float B, float C, float D)
 {
-    if ( A == B )
-    {
+    if ( A == B ) {
         return ( val - B ) >= 0.0f ? D : C;
-    }
-    else
-    {
+    } else {
         float cVal = (val - A) / (B - A);
         cVal = clamp( cVal, 0.0f, 1.0f );
 
@@ -713,65 +693,52 @@ static void FormatStatePacketUntilGyro( SteamControllerStateInternal_t *pState,
     pState->ulButtons &= ~0xFFFF000000LL;
 
     // The firmware uses this bit to tell us what kind of data is packed into the left two axises
-    if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK)
-    {
+    if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) {
         // Finger-down bit not set; "left pad" is actually trackpad
         pState->sLeftPadX = pState->sPrevLeftPad[0] = pStatePacket->sLeftPadX;
         pState->sLeftPadY = pState->sPrevLeftPad[1] = pStatePacket->sLeftPadY;
 
-        if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK)
-        {
+        if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) {
             // The controller is interleaving both stick and pad data, both are active
             pState->sLeftStickX = pState->sPrevLeftStick[0];
             pState->sLeftStickY = pState->sPrevLeftStick[1];
-        }
-        else
-        {
+        } else {
             // The stick is not active
             pState->sPrevLeftStick[0] = 0;
             pState->sPrevLeftStick[1] = 0;
         }
-    }
-    else
-    {
+    } else {
         // Finger-down bit not set; "left pad" is actually joystick
 
         // XXX there's a firmware bug where sometimes padX is 0 and padY is a large number (acutally the battery voltage)
         // If that happens skip this packet and report last frames stick
 /*
-        if ( m_eControllerType == k_eControllerType_SteamControllerV2 && pStatePacket->sLeftPadY > 900 )
-        {
+        if ( m_eControllerType == k_eControllerType_SteamControllerV2 && pStatePacket->sLeftPadY > 900 ) {
             pState->sLeftStickX = pState->sPrevLeftStick[0];
             pState->sLeftStickY = pState->sPrevLeftStick[1];
-        }
-        else
+        } else
 */
         {
             pState->sPrevLeftStick[0] = pState->sLeftStickX = pStatePacket->sLeftPadX;
             pState->sPrevLeftStick[1] = pState->sLeftStickY = pStatePacket->sLeftPadY;
         }
 /*
-        if (m_eControllerType == k_eControllerType_SteamControllerV2)
-        {
+        if (m_eControllerType == k_eControllerType_SteamControllerV2) {
             UpdateV2JoystickCap(&state);
         }
 */
 
-        if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK)
-        {
+        if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) {
             // The controller is interleaving both stick and pad data, both are active
             pState->sLeftPadX = pState->sPrevLeftPad[0];
             pState->sLeftPadY = pState->sPrevLeftPad[1];
-        }
-        else
-        {
+        } else {
             // The trackpad is not active
             pState->sPrevLeftPad[0] = 0;
             pState->sPrevLeftPad[1] = 0;
 
             // Old controllers send trackpad click for joystick button when trackpad is not active
-            if (pState->ulButtons & STEAM_BUTTON_LEFTPAD_CLICKED_MASK)
-            {
+            if (pState->ulButtons & STEAM_BUTTON_LEFTPAD_CLICKED_MASK) {
                 pState->ulButtons &= ~STEAM_BUTTON_LEFTPAD_CLICKED_MASK;
                 pState->ulButtons |= STEAM_JOYSTICK_BUTTON_MASK;
             }
@@ -780,8 +747,9 @@ static void FormatStatePacketUntilGyro( SteamControllerStateInternal_t *pState,
 
     // Fingerdown bit indicates if the packed left axis data was joystick or pad,
     // but if we are interleaving both, the left finger is definitely on the pad.
-    if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK)
+    if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) {
         pState->ulButtons |= STEAM_LEFTPAD_FINGERDOWN_MASK;
+    }
 
     pState->sRightPadX = pStatePacket->sRightPadX;
     pState->sRightPadY = pStatePacket->sRightPadY;
@@ -827,35 +795,30 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize,
     pState->unPacketNum++;
     ucOptionDataMask = ( *pData++ & 0xF0 );
     ucOptionDataMask |= (uint32_t)(*pData++) << 8;
-    if ( ucOptionDataMask & k_EBLEButtonChunk1 )
-    {
+    if ( ucOptionDataMask & k_EBLEButtonChunk1 ) {
         SDL_memcpy( &pState->ulButtons, pData, 3 );
         pData += 3;
     }
-    if ( ucOptionDataMask & k_EBLEButtonChunk2 )
-    {
+    if ( ucOptionDataMask & k_EBLEButtonChunk2 ) {
         // The middle 2 bytes of the button bits over the wire are triggers when over the wire and non-SC buttons in the internal controller state packet
         pState->sTriggerL = (unsigned short)RemapValClamped( (float)(( pData[ 0 ] << 7 ) | pData[ 0 ]), 0, STEAMCONTROLLER_TRIGGER_MAX_ANALOG, 0, SDL_MAX_SINT16 );
         pState->sTriggerR = (unsigned short)RemapValClamped( (float)(( pData[ 1 ] << 7 ) | pData[ 1 ]), 0, STEAMCONTROLLER_TRIGGER_MAX_ANALOG, 0, SDL_MAX_SINT16 );
         pData += 2;
     }
-    if ( ucOptionDataMask & k_EBLEButtonChunk3 )
-    {
+    if ( ucOptionDataMask & k_EBLEButtonChunk3 ) {
         uint8_t *pButtonByte = (uint8_t *)&pState->ulButtons;
         pButtonByte[ 5 ] = *pData++;
         pButtonByte[ 6 ] = *pData++;
         pButtonByte[ 7 ] = *pData++;
     }
-    if ( ucOptionDataMask & k_EBLELeftJoystickChunk )
-    {
+    if ( ucOptionDataMask & k_EBLELeftJoystickChunk ) {
         // This doesn't handle any of the special headcrab stuff for raw joystick which is OK for now since that FW doesn't support
         // this protocol yet either
         int nLength = sizeof( pState->sLeftStickX ) + sizeof( pState->sLeftStickY );
         SDL_memcpy( &pState->sLeftStickX, pData, nLength );
         pData += nLength;
     }
-    if ( ucOptionDataMask & k_EBLELeftTrackpadChunk )
-    {
+    if ( ucOptionDataMask & k_EBLELeftTrackpadChunk ) {
         int nLength = sizeof( pState->sLeftPadX ) + sizeof( pState->sLeftPadY );
         int nPadOffset;
         SDL_memcpy( &pState->sLeftPadX, pData, nLength );
@@ -869,8 +832,7 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize,
         pState->sLeftPadY = clamp( pState->sLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16 );
         pData += nLength;
     }
-    if ( ucOptionDataMask & k_EBLERightTrackpadChunk )
-    {
+    if ( ucOptionDataMask & k_EBLERightTrackpadChunk ) {
         int nLength = sizeof( pState->sRightPadX ) + sizeof( pState->sRightPadY );
         int nPadOffset = 0;
 
@@ -886,20 +848,17 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize,
         pState->sRightPadY = clamp( pState->sRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16 );
         pData += nLength;
     }
-    if ( ucOptionDataMask & k_EBLEIMUAccelChunk )
-    {
+    if ( ucOptionDataMask & k_EBLEIMUAccelChunk ) {
         int nLength = sizeof( pState->sAccelX ) + sizeof( pState->sAccelY ) + sizeof( pState->sAccelZ );
         SDL_memcpy( &pState->sAccelX, pData, nLength );
         pData += nLength;
     }
-    if ( ucOptionDataMask & k_EBLEIMUGyroChunk )
-    {
+    if ( ucOptionDataMask & k_EBLEIMUGyroChunk ) {
         int nLength = sizeof( pState->sAccelX ) + sizeof( pState->sAccelY ) + sizeof( pState->sAccelZ );
         SDL_memcpy( &pState->sGyroX, pData, nLength );
         pData += nLength;
     }
-    if ( ucOptionDataMask & k_EBLEIMUQuatChunk )
-    {
+    if ( ucOptionDataMask & k_EBLEIMUQuatChunk ) {
         int nLength = sizeof( pState->sGyroQuatW ) + sizeof( pState->sGyroQuatX ) + sizeof( pState->sGyroQuatY ) + sizeof( pState->sGyroQuatZ );
         SDL_memcpy( &pState->sGyroQuatW, pData, nLength );
         pData += nLength;
@@ -915,10 +874,8 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste
 {
     ValveInReport_t *pInReport = (ValveInReport_t*)pData;
 
-    if ( pInReport->header.unReportVersion != k_ValveInReportMsgVersion )
-    {
-        if ( ( pData[ 0 ] & 0x0F ) == k_EBLEReportState )
-        {
+    if ( pInReport->header.unReportVersion != k_ValveInReportMsgVersion ) {
+        if ( ( pData[ 0 ] & 0x0F ) == k_EBLEReportState ) {
             return UpdateBLESteamControllerState( pData, nDataSize, pState );
         }
         return false;
@@ -930,13 +887,13 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste
         return false;
     }
 
-    if ( pInReport->header.ucType == ID_CONTROLLER_STATE )
-    {
+    if ( pInReport->header.ucType == ID_CONTROLLER_STATE ) {
         ValveControllerStatePacket_t *pStatePacket = &pInReport->payload.controllerState;
 
         // No new data to process; indicate that we received a state packet, but otherwise do nothing.
-        if ( pState->unPacketNum == pStatePacket->unPacketNum )
+        if (pState->unPacketNum == pStatePacket->unPacketNum) {
             return true;
+        }
 
         FormatStatePacketUntilGyro( pState, pStatePacket );
 
@@ -953,15 +910,14 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste
         pState->sGyroY = pStatePacket->sGyroY;
         pState->sGyroZ = pStatePacket->sGyroZ;
 
-    }
-    else if ( pInReport->header.ucType == ID_CONTROLLER_BLE_STATE )
-    {
+    } else if ( pInReport->header.ucType == ID_CONTROLLER_BLE_STATE ) {
         ValveControllerBLEStatePacket_t *pBLEStatePacket = &pInReport->payload.controllerBLEState;
         ValveControllerStatePacket_t *pStatePacket = &pInReport->payload.controllerState;
 
         // No new data to process; indicate that we received a state packet, but otherwise do nothing.
-        if ( pState->unPacketNum == pStatePacket->unPacketNum )
+        if (pState->unPacketNum == pStatePacket->unPacketNum) {
             return true;
+        }
 
         FormatStatePacketUntilGyro( pState, pStatePacket );
 
@@ -1037,7 +993,7 @@ HIDAPI_DriverSteam_InitDevice(SDL_HIDAPI_Device *device)
     SDL_DriverSteam_Context *ctx;
 
     ctx = (SDL_DriverSteam_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -1167,8 +1123,7 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
         return SDL_FALSE;
     }
 
-    for (;;)
-    {
+    for (;;) {
         uint8_t data[128];
         int r, nPacketLength;
         const Uint8 *pPacket;
@@ -1178,7 +1133,7 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
             break;
         }
 
-        if (!joystick) {
+        if (joystick == NULL) {
             continue;
         }
 

+ 19 - 22
src/joystick/hidapi/SDL_hidapi_switch.c

@@ -396,9 +396,9 @@ static SDL_bool WritePacket(SDL_DriverSwitch_Context *ctx, void *pBuf, Uint8 ucL
         ucLen = (Uint8)unWriteSize;
     }
     if (ctx->m_bSyncWrite) {
-        return (SDL_hid_write(ctx->device->dev, (Uint8 *)pBuf, ucLen) >= 0);
+        return SDL_hid_write(ctx->device->dev, (Uint8 *)pBuf, ucLen) >= 0;
     } else {
-        return (WriteOutput(ctx, (Uint8 *)pBuf, ucLen) >= 0);
+        return WriteOutput(ctx, (Uint8 *)pBuf, ucLen) >= 0;
     }
 }
 
@@ -407,7 +407,7 @@ static SDL_bool WriteSubcommand(SDL_DriverSwitch_Context *ctx, ESwitchSubcommand
     SwitchSubcommandInputPacket_t *reply = NULL;
     int nTries;
 
-    for (nTries = 1; !reply && nTries <= ctx->m_nMaxWriteAttempts; ++nTries) {
+    for (nTries = 1; reply == NULL && nTries <= ctx->m_nMaxWriteAttempts; ++nTries) {
         SwitchSubcommandOutputPacket_t commandPacket;
         ConstructSubcommand(ctx, ucCommandID, pBuf, ucLen, &commandPacket);
 
@@ -431,7 +431,7 @@ static SDL_bool WriteProprietary(SDL_DriverSwitch_Context *ctx, ESwitchProprieta
     for (nTries = 1; nTries <= ctx->m_nMaxWriteAttempts; ++nTries) {
         SwitchProprietaryOutputPacket_t packet;
 
-        if ((!pBuf && ucLen > 0) || ucLen > sizeof(packet.rgucProprietaryData)) {
+        if ((pBuf == NULL && ucLen > 0) || ucLen > sizeof(packet.rgucProprietaryData)) {
             return SDL_FALSE;
         }
 
@@ -592,8 +592,9 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
 
         ctx->m_eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)status->ucDeviceType);
 
-        for (i = 0; i < sizeof (ctx->m_rgucMACAddress); ++i)
-            ctx->m_rgucMACAddress[i] = status->rgucMACAddress[ sizeof(ctx->m_rgucMACAddress) - i - 1 ];
+        for (i = 0; i < sizeof(ctx->m_rgucMACAddress); ++i) {
+            ctx->m_rgucMACAddress[i] = status->rgucMACAddress[sizeof(ctx->m_rgucMACAddress) - i - 1];
+        }
 
         return SDL_TRUE;
     }
@@ -772,14 +773,14 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_
     }
 
     for (stick = 0; stick < 2; ++stick) {
-        for(axis = 0; axis < 2; ++axis) {
+        for (axis = 0; axis < 2; ++axis) {
             ctx->m_StickExtents[stick].axis[axis].sMin = -(Sint16)(ctx->m_StickCalData[stick].axis[axis].sMin * 0.7f);
             ctx->m_StickExtents[stick].axis[axis].sMax = (Sint16)(ctx->m_StickCalData[stick].axis[axis].sMax * 0.7f);
         }
     }
 
     for (stick = 0; stick < 2; ++stick) {
-        for(axis = 0; axis < 2; ++axis) {
+        for (axis = 0; axis < 2; ++axis) {
             ctx->m_SimpleStickExtents[stick].axis[axis].sMin = (Sint16)(SDL_MIN_SINT16 * 0.5f);
             ctx->m_SimpleStickExtents[stick].axis[axis].sMax = (Sint16)(SDL_MAX_SINT16 * 0.5f);
         }
@@ -865,7 +866,8 @@ static Sint16 ApplyStickCalibration(SDL_DriverSwitch_Context *ctx, int nStick, i
         ctx->m_StickExtents[nStick].axis[nAxis].sMin = sRawValue;
     }
 
-    return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_StickExtents[nStick].axis[nAxis].sMin, ctx->m_StickExtents[nStick].axis[nAxis].sMax, SDL_MIN_SINT16, SDL_MAX_SINT16);
+    return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_StickExtents[nStick].axis[nAxis].sMin, ctx->m_StickExtents[nStick].axis[nAxis].sMax,
+                                   SDL_MIN_SINT16, SDL_MAX_SINT16);
 }
 
 static Sint16 ApplySimpleStickCalibration(SDL_DriverSwitch_Context *ctx, int nStick, int nAxis, Sint16 sRawValue)
@@ -882,7 +884,8 @@ static Sint16 ApplySimpleStickCalibration(SDL_DriverSwitch_Context *ctx, int nSt
         ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin = sRawValue;
     }
 
-    return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMax, SDL_MIN_SINT16, SDL_MAX_SINT16);
+    return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMax,
+                                   SDL_MIN_SINT16, SDL_MAX_SINT16);
 }
 
 static void SDLCALL SDL_GameControllerButtonReportingHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
@@ -1047,9 +1050,7 @@ HIDAPI_DriverNintendoClassic_UnregisterHints(SDL_HintCallback callback, void *us
 static SDL_bool
 HIDAPI_DriverNintendoClassic_IsEnabled(void)
 {
-    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC,
-               SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
-                   SDL_HIDAPI_DEFAULT));
+    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
 }
 
 static SDL_bool
@@ -1093,9 +1094,7 @@ HIDAPI_DriverJoyCons_UnregisterHints(SDL_HintCallback callback, void *userdata)
 static SDL_bool
 HIDAPI_DriverJoyCons_IsEnabled(void)
 {
-    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS,
-               SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
-                   SDL_HIDAPI_DEFAULT));
+    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
 }
 
 static SDL_bool
@@ -1135,9 +1134,7 @@ HIDAPI_DriverSwitch_UnregisterHints(SDL_HintCallback callback, void *userdata)
 static SDL_bool
 HIDAPI_DriverSwitch_IsEnabled(void)
 {
-    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH,
-               SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI,
-                   SDL_HIDAPI_DEFAULT));
+    return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
 }
 
 static SDL_bool
@@ -1228,7 +1225,7 @@ HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device)
     SDL_DriverSwitch_Context *ctx;
 
     ctx = (SDL_DriverSwitch_Context *)SDL_calloc(1, sizeof(*ctx));
-    if (!ctx) {
+    if (ctx == NULL) {
         SDL_OutOfMemory();
         return SDL_FALSE;
     }
@@ -2138,7 +2135,7 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
         ++packet_count;
         ctx->m_unLastInput = now;
 
-        if (!joystick) {
+        if (joystick == NULL) {
             continue;
         }
 
@@ -2197,7 +2194,7 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
         /* Read error, device is disconnected */
         HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
     }
-    return (size >= 0);
+    return size >= 0;
 }
 
 static void

部分文件因文件數量過多而無法顯示