Przeglądaj źródła

Use new parameter validation macro

Sam Lantinga 3 dni temu
rodzic
commit
25b2d2c821
60 zmienionych plików z 1013 dodań i 981 usunięć
  1. 2 2
      src/SDL.c
  2. 7 6
      src/SDL_hashtable.c
  3. 5 4
      src/SDL_hints.c
  4. 1 1
      src/SDL_log.c
  5. 12 12
      src/SDL_properties.c
  6. 14 10
      src/audio/SDL_audio.c
  7. 72 43
      src/audio/SDL_audiocvt.c
  8. 7 4
      src/audio/SDL_wave.c
  9. 38 31
      src/camera/SDL_camera.c
  10. 1 1
      src/core/android/SDL_android.c
  11. 1 1
      src/events/SDL_events.c
  12. 5 4
      src/events/SDL_keymap.c
  13. 3 3
      src/events/SDL_mouse.c
  14. 16 13
      src/filesystem/SDL_filesystem.c
  15. 153 134
      src/gpu/SDL_gpu.c
  16. 15 15
      src/haptic/SDL_haptic.c
  17. 15 10
      src/io/SDL_asyncio.c
  18. 36 23
      src/io/SDL_iostream.c
  19. 8 8
      src/joystick/SDL_gamepad.c
  20. 12 12
      src/joystick/SDL_joystick.c
  21. 2 2
      src/joystick/virtual/SDL_virtualjoystick.c
  22. 1 1
      src/loadso/windows/SDL_sysloadso.c
  23. 1 1
      src/misc/SDL_url.c
  24. 9 9
      src/process/SDL_process.c
  25. 236 348
      src/render/SDL_render.c
  26. 2 2
      src/render/software/SDL_blendfillrect.c
  27. 1 1
      src/render/software/SDL_blendline.c
  28. 2 2
      src/render/software/SDL_blendpoint.c
  29. 2 2
      src/render/software/SDL_drawline.c
  30. 2 2
      src/render/software/SDL_drawpoint.c
  31. 3 3
      src/render/software/SDL_render_sw.c
  32. 2 2
      src/render/software/SDL_triangle.c
  33. 5 5
      src/sensor/SDL_sensor.c
  34. 9 6
      src/stdlib/SDL_getenv.c
  35. 4 4
      src/stdlib/SDL_malloc.c
  36. 54 29
      src/storage/SDL_storage.c
  37. 2 2
      src/thread/SDL_thread.c
  38. 3 3
      src/time/SDL_time.c
  39. 2 2
      src/time/n3ds/SDL_systime.c
  40. 1 1
      src/time/ngage/SDL_systime.cpp
  41. 2 2
      src/time/ps2/SDL_systime.c
  42. 2 2
      src/time/psp/SDL_systime.c
  43. 2 2
      src/time/unix/SDL_systime.c
  44. 2 2
      src/time/vita/SDL_systime.c
  45. 2 2
      src/time/windows/SDL_systime.c
  46. 4 4
      src/timer/SDL_timer.c
  47. 11 11
      src/tray/cocoa/SDL_tray.m
  48. 10 10
      src/tray/unix/SDL_tray.c
  49. 11 11
      src/tray/windows/SDL_tray.c
  50. 3 3
      src/video/SDL_bmp.c
  51. 2 2
      src/video/SDL_clipboard.c
  52. 9 9
      src/video/SDL_fillrect.c
  53. 5 5
      src/video/SDL_pixels.c
  54. 9 5
      src/video/SDL_rect.c
  55. 45 26
      src/video/SDL_rect_impl.h
  56. 2 2
      src/video/SDL_stb.c
  57. 2 2
      src/video/SDL_stretch.c
  58. 85 77
      src/video/SDL_surface.c
  59. 36 37
      src/video/SDL_video.c
  60. 3 3
      src/video/windows/SDL_windowsvideo.c

+ 2 - 2
src/SDL.c

@@ -148,7 +148,7 @@ static bool SDL_ValidMetadataProperty(const char *name)
 
 bool SDL_SetAppMetadataProperty(const char *name, const char *value)
 {
-    if (!SDL_ValidMetadataProperty(name)) {
+    CHECK_PARAM(!SDL_ValidMetadataProperty(name)) {
         return SDL_InvalidParamError("name");
     }
 
@@ -157,7 +157,7 @@ bool SDL_SetAppMetadataProperty(const char *name, const char *value)
 
 const char *SDL_GetAppMetadataProperty(const char *name)
 {
-    if (!SDL_ValidMetadataProperty(name)) {
+    CHECK_PARAM(!SDL_ValidMetadataProperty(name)) {
         SDL_InvalidParamError("name");
         return NULL;
     }

+ 7 - 6
src/SDL_hashtable.c

@@ -292,7 +292,7 @@ static bool maybe_resize(SDL_HashTable *ht)
 
 bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value, bool replace)
 {
-    if (!table) {
+    CHECK_PARAM(!table) {
         return SDL_InvalidParamError("table");
     }
 
@@ -338,7 +338,7 @@ bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *
 
 bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **value)
 {
-    if (!table) {
+    CHECK_PARAM(!table) {
         if (value) {
             *value = NULL;
         }
@@ -364,7 +364,7 @@ bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void
 
 bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
 {
-    if (!table) {
+    CHECK_PARAM(!table) {
         return SDL_InvalidParamError("table");
     }
 
@@ -384,9 +384,10 @@ bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
 
 bool SDL_IterateHashTable(const SDL_HashTable *table, SDL_HashTableIterateCallback callback, void *userdata)
 {
-    if (!table) {
+    CHECK_PARAM(!table) {
         return SDL_InvalidParamError("table");
-    } else if (!callback) {
+    }
+    CHECK_PARAM(!callback) {
         return SDL_InvalidParamError("callback");
     }
 
@@ -410,7 +411,7 @@ bool SDL_IterateHashTable(const SDL_HashTable *table, SDL_HashTableIterateCallba
 
 bool SDL_HashTableEmpty(SDL_HashTable *table)
 {
-    if (!table) {
+    CHECK_PARAM(!table) {
         return SDL_InvalidParamError("table");
     }
 

+ 5 - 4
src/SDL_hints.c

@@ -104,7 +104,7 @@ static const char *GetHintEnvironmentVariable(const char *name)
 
 bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority)
 {
-    if (!name || !*name) {
+    CHECK_PARAM(!name || !*name) {
         return SDL_InvalidParamError("name");
     }
 
@@ -165,7 +165,7 @@ bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriori
 
 bool SDL_ResetHint(const char *name)
 {
-    if (!name || !*name) {
+    CHECK_PARAM(!name || !*name) {
         return SDL_InvalidParamError("name");
     }
 
@@ -316,9 +316,10 @@ bool SDL_GetHintBoolean(const char *name, bool default_value)
 
 bool SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
 {
-    if (!name || !*name) {
+    CHECK_PARAM(!name || !*name) {
         return SDL_InvalidParamError("name");
-    } else if (!callback) {
+    }
+    CHECK_PARAM(!callback) {
         return SDL_InvalidParamError("callback");
     }
 

+ 1 - 1
src/SDL_log.c

@@ -461,7 +461,7 @@ bool SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix)
 {
     char *prefix_copy;
 
-    if (priority <= SDL_LOG_PRIORITY_INVALID || priority >= SDL_LOG_PRIORITY_COUNT) {
+    CHECK_PARAM(priority <= SDL_LOG_PRIORITY_INVALID || priority >= SDL_LOG_PRIORITY_COUNT) {
         return SDL_InvalidParamError("priority");
     }
 

+ 12 - 12
src/SDL_properties.c

@@ -250,10 +250,10 @@ static bool SDLCALL CopyOneProperty(void *userdata, const SDL_HashTable *table,
 
 bool SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst)
 {
-    if (!src) {
+    CHECK_PARAM(!src) {
         return SDL_InvalidParamError("src");
     }
-    if (!dst) {
+    CHECK_PARAM(!dst) {
         return SDL_InvalidParamError("dst");
     }
 
@@ -261,11 +261,11 @@ bool SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst)
     SDL_Properties *dst_properties = NULL;
 
     SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)src, (const void **)&src_properties);
-    if (!src_properties) {
+    CHECK_PARAM(!src_properties) {
         return SDL_InvalidParamError("src");
     }
     SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)dst, (const void **)&dst_properties);
-    if (!dst_properties) {
+    CHECK_PARAM(!dst_properties) {
         return SDL_InvalidParamError("dst");
     }
 
@@ -287,12 +287,12 @@ bool SDL_LockProperties(SDL_PropertiesID props)
 {
     SDL_Properties *properties = NULL;
 
-    if (!props) {
+    CHECK_PARAM(!props) {
         return SDL_InvalidParamError("props");
     }
 
     SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
-    if (!properties) {
+    CHECK_PARAM(!properties) {
         return SDL_InvalidParamError("props");
     }
 
@@ -321,17 +321,17 @@ static bool SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL
     SDL_Properties *properties = NULL;
     bool result = true;
 
-    if (!props) {
+    CHECK_PARAM(!props) {
         SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
         return SDL_InvalidParamError("props");
     }
-    if (!name || !*name) {
+    CHECK_PARAM(!name || !*name) {
         SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
         return SDL_InvalidParamError("name");
     }
 
     SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
-    if (!properties) {
+    CHECK_PARAM(!properties) {
         SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
         return SDL_InvalidParamError("props");
     }
@@ -755,15 +755,15 @@ bool SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCall
 {
     SDL_Properties *properties = NULL;
 
-    if (!props) {
+    CHECK_PARAM(!props) {
         return SDL_InvalidParamError("props");
     }
-    if (!callback) {
+    CHECK_PARAM(!callback) {
         return SDL_InvalidParamError("callback");
     }
 
     SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
-    if (!properties) {
+    CHECK_PARAM(!properties) {
         return SDL_InvalidParamError("props");
     }
 

+ 14 - 10
src/audio/SDL_audio.c

@@ -136,11 +136,11 @@ int SDL_GetNumAudioDrivers(void)
 
 const char *SDL_GetAudioDriver(int index)
 {
-    if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
-        return deduped_bootstrap[index]->name;
+    CHECK_PARAM(index < 0 || index >= SDL_GetNumAudioDrivers()) {
+        SDL_InvalidParamError("index");
+        return NULL;
     }
-    SDL_InvalidParamError("index");
-    return NULL;
+    return deduped_bootstrap[index]->name;
 }
 
 const char *SDL_GetCurrentAudioDriver(void)
@@ -1576,7 +1576,7 @@ const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
 
 bool SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames)
 {
-    if (!spec) {
+    CHECK_PARAM(!spec) {
         return SDL_InvalidParamError("spec");
     }
 
@@ -1937,7 +1937,7 @@ float SDL_GetAudioDeviceGain(SDL_AudioDeviceID devid)
 
 bool SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain)
 {
-    if (gain < 0.0f) {
+    CHECK_PARAM(gain < 0.0f) {
         return SDL_InvalidParamError("gain");
     }
 
@@ -1986,11 +1986,15 @@ bool SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream * const *stre
 
     if (num_streams == 0) {
         return true;  // nothing to do
-    } else if (num_streams < 0) {
+    }
+
+    CHECK_PARAM(num_streams < 0) {
         return SDL_InvalidParamError("num_streams");
-    } else if (!streams) {
+    }
+    CHECK_PARAM(!streams) {
         return SDL_InvalidParamError("streams");
-    } else if (SDL_IsAudioDevicePhysical(devid)) {
+    }
+    CHECK_PARAM(SDL_IsAudioDevicePhysical(devid)) {
         return SDL_SetError("Audio streams are bound to device ids from SDL_OpenAudioDevice, not raw physical devices");
     }
 
@@ -2150,7 +2154,7 @@ SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream *stream)
 {
     SDL_AudioDeviceID result = 0;
 
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         SDL_InvalidParamError("stream");
         return 0;
     }

+ 72 - 43
src/audio/SDL_audiocvt.c

@@ -474,10 +474,11 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_
 
 SDL_PropertiesID SDL_GetAudioStreamProperties(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         SDL_InvalidParamError("stream");
         return 0;
     }
+
     SDL_LockMutex(stream->lock);
     if (stream->props == 0) {
         stream->props = SDL_CreateProperties();
@@ -488,9 +489,10 @@ SDL_PropertiesID SDL_GetAudioStreamProperties(SDL_AudioStream *stream)
 
 bool SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
+
     SDL_LockMutex(stream->lock);
     stream->get_callback = callback;
     stream->get_callback_userdata = userdata;
@@ -500,9 +502,10 @@ bool SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallb
 
 bool SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
+
     SDL_LockMutex(stream->lock);
     stream->put_callback = callback;
     stream->put_callback_userdata = userdata;
@@ -512,25 +515,27 @@ bool SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallb
 
 bool SDL_LockAudioStream(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
+
     SDL_LockMutex(stream->lock);
     return true;
 }
 
 bool SDL_UnlockAudioStream(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
+
     SDL_UnlockMutex(stream->lock);
     return true;
 }
 
 bool SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, SDL_AudioSpec *dst_spec)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         if (src_spec) {
             SDL_zerop(src_spec);
         }
@@ -560,7 +565,7 @@ bool SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec,
 
 bool SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
 
@@ -569,21 +574,25 @@ bool SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_
     // like 196608000Hz. File a bug.  :P
 
     if (src_spec) {
-        if (!SDL_IsSupportedAudioFormat(src_spec->format)) {
+        CHECK_PARAM(!SDL_IsSupportedAudioFormat(src_spec->format)) {
             return SDL_InvalidParamError("src_spec->format");
-        } else if (!SDL_IsSupportedChannelCount(src_spec->channels)) {
+        }
+        CHECK_PARAM(!SDL_IsSupportedChannelCount(src_spec->channels)) {
             return SDL_InvalidParamError("src_spec->channels");
-        } else if (src_spec->freq <= 0) {
+        }
+        CHECK_PARAM(src_spec->freq <= 0) {
             return SDL_InvalidParamError("src_spec->freq");
         }
     }
 
     if (dst_spec) {
-        if (!SDL_IsSupportedAudioFormat(dst_spec->format)) {
+        CHECK_PARAM(!SDL_IsSupportedAudioFormat(dst_spec->format)) {
             return SDL_InvalidParamError("dst_spec->format");
-        } else if (!SDL_IsSupportedChannelCount(dst_spec->channels)) {
+        }
+        CHECK_PARAM(!SDL_IsSupportedChannelCount(dst_spec->channels)) {
             return SDL_InvalidParamError("dst_spec->channels");
-        } else if (dst_spec->freq <= 0) {
+        }
+        CHECK_PARAM(dst_spec->freq <= 0) {
             return SDL_InvalidParamError("dst_spec->freq");
         }
     }
@@ -622,7 +631,7 @@ bool SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_
 
 bool SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, int **stream_chmap, const int *chmap, int channels, int isinput)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
 
@@ -708,7 +717,7 @@ int *SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count)
 
 float SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         SDL_InvalidParamError("stream");
         return 0.0f;
     }
@@ -722,7 +731,7 @@ float SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream)
 
 bool SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float freq_ratio)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
 
@@ -745,7 +754,7 @@ bool SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float freq_ratio)
 
 float SDL_GetAudioStreamGain(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         SDL_InvalidParamError("stream");
         return -1.0f;
     }
@@ -759,9 +768,10 @@ float SDL_GetAudioStreamGain(SDL_AudioStream *stream)
 
 bool SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
-    } else if (gain < 0.0f) {
+    }
+    CHECK_PARAM(gain < 0.0f) {
         return SDL_InvalidParamError("gain");
     }
 
@@ -847,13 +857,17 @@ static void SDLCALL FreeAllocatedAudioBuffer(void *userdata, const void *buf, in
 
 bool SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
-    } else if (!buf) {
+    }
+    CHECK_PARAM(!buf) {
         return SDL_InvalidParamError("buf");
-    } else if (len < 0) {
+    }
+    CHECK_PARAM(len < 0) {
         return SDL_InvalidParamError("len");
-    } else if (len == 0) {
+    }
+
+    if (len == 0) {
         return true; // nothing to do.
     }
 
@@ -965,13 +979,17 @@ static void InterleaveAudioChannels(void *output, const void * const *channel_bu
 
 bool SDL_PutAudioStreamPlanarData(SDL_AudioStream *stream, const void * const *channel_buffers, int num_channels, int num_samples)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
-    } else if (!channel_buffers) {
+    }
+    CHECK_PARAM(!channel_buffers) {
         return SDL_InvalidParamError("channel_buffers");
-    } else if (num_samples < 0) {
+    }
+    CHECK_PARAM(num_samples < 0) {
         return SDL_InvalidParamError("num_samples");
-    } else if (num_samples == 0) {
+    }
+
+    if (num_samples == 0) {
         return true; // nothing to do.
     }
 
@@ -1039,13 +1057,17 @@ static void SDLCALL DontFreeThisAudioBuffer(void *userdata, const void *buf, int
 
 bool SDL_PutAudioStreamDataNoCopy(SDL_AudioStream *stream, const void *buf, int len, SDL_AudioStreamDataCompleteCallback callback, void *userdata)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
-    } else if (!buf) {
+    }
+    CHECK_PARAM(!buf) {
         return SDL_InvalidParamError("buf");
-    } else if (len < 0) {
+    }
+    CHECK_PARAM(len < 0) {
         return SDL_InvalidParamError("len");
-    } else if (len == 0) {
+    }
+
+    if (len == 0) {
         if (callback) {
             callback(userdata, buf, len);
         }
@@ -1057,7 +1079,7 @@ bool SDL_PutAudioStreamDataNoCopy(SDL_AudioStream *stream, const void *buf, int
 
 bool SDL_FlushAudioStream(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
 
@@ -1320,16 +1342,20 @@ int SDL_GetAudioStreamDataAdjustGain(SDL_AudioStream *stream, void *voidbuf, int
     SDL_Log("AUDIOSTREAM: want to get %d converted bytes", len);
 #endif
 
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         SDL_InvalidParamError("stream");
         return -1;
-    } else if (!buf) {
+    }
+    CHECK_PARAM(!buf) {
         SDL_InvalidParamError("buf");
         return -1;
-    } else if (len < 0) {
+    }
+    CHECK_PARAM(len < 0) {
         SDL_InvalidParamError("len");
         return -1;
-    } else if (len == 0) {
+    }
+
+    if (len == 0) {
         return 0; // nothing to do.
     }
 
@@ -1427,7 +1453,7 @@ int SDL_GetAudioStreamData(SDL_AudioStream *stream, void *voidbuf, int len)
 // number of converted/resampled bytes available for output
 int SDL_GetAudioStreamAvailable(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         SDL_InvalidParamError("stream");
         return -1;
     }
@@ -1453,7 +1479,7 @@ int SDL_GetAudioStreamAvailable(SDL_AudioStream *stream)
 // number of sample frames that are currently queued as input.
 int SDL_GetAudioStreamQueued(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         SDL_InvalidParamError("stream");
         return -1;
     }
@@ -1470,7 +1496,7 @@ int SDL_GetAudioStreamQueued(SDL_AudioStream *stream)
 
 bool SDL_ClearAudioStream(SDL_AudioStream *stream)
 {
-    if (!stream) {
+    CHECK_PARAM(!stream) {
         return SDL_InvalidParamError("stream");
     }
 
@@ -1522,13 +1548,16 @@ bool SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_dat
         *dst_len = 0;
     }
 
-    if (!src_data) {
+    CHECK_PARAM(!src_data) {
         return SDL_InvalidParamError("src_data");
-    } else if (src_len < 0) {
+    }
+    CHECK_PARAM(src_len < 0) {
         return SDL_InvalidParamError("src_len");
-    } else if (!dst_data) {
+    }
+    CHECK_PARAM(!dst_data) {
         return SDL_InvalidParamError("dst_data");
-    } else if (!dst_len) {
+    }
+    CHECK_PARAM(!dst_len) {
         return SDL_InvalidParamError("dst_len");
     }
 

+ 7 - 4
src/audio/SDL_wave.c

@@ -2092,16 +2092,19 @@ bool SDL_LoadWAV_IO(SDL_IOStream *src, bool closeio, SDL_AudioSpec *spec, Uint8
     }
 
     // Make sure we are passed a valid data source
-    if (!src) {
+    CHECK_PARAM(!src) {
         SDL_InvalidParamError("src");
         goto done;
-    } else if (!spec) {
+    }
+    CHECK_PARAM(!spec) {
         SDL_InvalidParamError("spec");
         goto done;
-    } else if (!audio_buf) {
+    }
+    CHECK_PARAM(!audio_buf) {
         SDL_InvalidParamError("audio_buf");
         goto done;
-    } else if (!audio_len) {
+    }
+    CHECK_PARAM(!audio_len) {
         SDL_InvalidParamError("audio_len");
         goto done;
     }

+ 38 - 31
src/camera/SDL_camera.c

@@ -69,11 +69,11 @@ int SDL_GetNumCameraDrivers(void)
 
 const char *SDL_GetCameraDriver(int index)
 {
-    if (index >= 0 && index < SDL_GetNumCameraDrivers()) {
-        return bootstrap[index]->name;
+    CHECK_PARAM(index < 0 || index >= SDL_GetNumCameraDrivers()) {
+        SDL_InvalidParamError("index");
+        return NULL;
     }
-    SDL_InvalidParamError("index");
-    return NULL;
+    return bootstrap[index]->name;
 }
 
 const char *SDL_GetCurrentCameraDriver(void)
@@ -657,9 +657,10 @@ bool SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec)
 {
     bool result;
 
-    if (!camera) {
+    CHECK_PARAM(!camera) {
         return SDL_InvalidParamError("camera");
-    } else if (!spec) {
+    }
+    CHECK_PARAM(!spec) {
         return SDL_InvalidParamError("spec");
     }
 
@@ -1255,7 +1256,7 @@ SDL_Surface *SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS)
         *timestampNS = 0;
     }
 
-    if (!camera) {
+    CHECK_PARAM(!camera) {
         SDL_InvalidParamError("camera");
         return NULL;
     }
@@ -1340,49 +1341,55 @@ void SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame)
 
 SDL_CameraID SDL_GetCameraID(SDL_Camera *camera)
 {
-    SDL_CameraID result = 0;
-    if (!camera) {
+    SDL_CameraID result;
+
+    CHECK_PARAM(!camera) {
         SDL_InvalidParamError("camera");
-    } else {
-        SDL_Camera *device = camera;  // currently there's no separation between physical and logical device.
-        ObtainPhysicalCameraObj(device);
-        result = device->instance_id;
-        ReleaseCamera(device);
+        return 0;
     }
 
+    SDL_Camera *device = camera;  // currently there's no separation between physical and logical device.
+    ObtainPhysicalCameraObj(device);
+    result = device->instance_id;
+    ReleaseCamera(device);
+
     return result;
 }
 
 SDL_PropertiesID SDL_GetCameraProperties(SDL_Camera *camera)
 {
-    SDL_PropertiesID result = 0;
-    if (!camera) {
+    SDL_PropertiesID result;
+
+    CHECK_PARAM(!camera) {
         SDL_InvalidParamError("camera");
-    } else {
-        SDL_Camera *device = camera;  // currently there's no separation between physical and logical device.
-        ObtainPhysicalCameraObj(device);
-        if (device->props == 0) {
-            device->props = SDL_CreateProperties();
-        }
-        result = device->props;
-        ReleaseCamera(device);
+        return 0;
     }
 
+    SDL_Camera *device = camera;  // currently there's no separation between physical and logical device.
+    ObtainPhysicalCameraObj(device);
+    if (device->props == 0) {
+        device->props = SDL_CreateProperties();
+    }
+    result = device->props;
+    ReleaseCamera(device);
+
     return result;
 }
 
 SDL_CameraPermissionState SDL_GetCameraPermissionState(SDL_Camera *camera)
 {
     SDL_CameraPermissionState result;
-    if (!camera) {
+
+    CHECK_PARAM(!camera) {
         SDL_InvalidParamError("camera");
-        result = SDL_CAMERA_PERMISSION_STATE_DENIED;
-    } else {
-        SDL_Camera *device = camera;  // currently there's no separation between physical and logical device.
-        ObtainPhysicalCameraObj(device);
-        result = device->permission;
-        ReleaseCamera(device);
+        return SDL_CAMERA_PERMISSION_STATE_DENIED;
     }
+
+    SDL_Camera *device = camera;  // currently there's no separation between physical and logical device.
+    ObtainPhysicalCameraObj(device);
+    result = device->permission;
+    ReleaseCamera(device);
+
     return result;
 }
 

+ 1 - 1
src/core/android/SDL_android.c

@@ -2113,7 +2113,7 @@ void Android_JNI_HapticStop(int device_id)
 
 bool SDL_SendAndroidMessage(Uint32 command, int param)
 {
-    if (command < 0x8000) {
+    CHECK_PARAM(command < 0x8000) {
         return SDL_InvalidParamError("command");
     }
     return Android_JNI_SendMessage(command, param);

+ 1 - 1
src/events/SDL_events.c

@@ -1131,7 +1131,7 @@ static int SDL_PeepEventsInternal(SDL_Event *events, int numevents, SDL_EventAct
             return -1;
         }
         if (action == SDL_ADDEVENT) {
-            if (!events) {
+            CHECK_PARAM(!events) {
                 SDL_UnlockMutex(SDL_EventQ.lock);
                 return SDL_InvalidParamError("events");
             }

+ 5 - 4
src/events/SDL_keymap.c

@@ -290,7 +290,7 @@ static const struct
 
 static SDL_Keycode SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate)
 {
-    if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
+    CHECK_PARAM(((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
         SDL_InvalidParamError("scancode");
         return SDLK_UNKNOWN;
     }
@@ -1053,7 +1053,7 @@ static const char *SDL_extended_key_names[] = {
 
 bool SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
 {
-    if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
+    CHECK_PARAM(((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
         return SDL_InvalidParamError("scancode");
     }
 
@@ -1064,7 +1064,8 @@ bool SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
 const char *SDL_GetScancodeName(SDL_Scancode scancode)
 {
     const char *name;
-    if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
+
+    CHECK_PARAM(((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
         SDL_InvalidParamError("scancode");
         return "";
     }
@@ -1081,7 +1082,7 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name)
 {
     int i;
 
-    if (!name || !*name) {
+    CHECK_PARAM(!name || !*name) {
         SDL_InvalidParamError("name");
         return SDL_SCANCODE_UNKNOWN;
     }

+ 3 - 3
src/events/SDL_mouse.c

@@ -1558,7 +1558,7 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
     SDL_Surface *temp = NULL;
     SDL_Cursor *cursor;
 
-    if (!surface) {
+    CHECK_PARAM(!surface) {
         SDL_InvalidParamError("surface");
         return NULL;
     }
@@ -1569,8 +1569,8 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
     hot_y = (int)SDL_GetNumberProperty(props, SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER, hot_y);
 
     // Sanity check the hot spot
-    if ((hot_x < 0) || (hot_y < 0) ||
-        (hot_x >= surface->w) || (hot_y >= surface->h)) {
+    CHECK_PARAM((hot_x < 0) || (hot_y < 0) ||
+                (hot_x >= surface->w) || (hot_y >= surface->h)) {
         SDL_SetError("Cursor hot spot doesn't lie within cursor");
         return NULL;
     }

+ 16 - 13
src/filesystem/SDL_filesystem.c

@@ -27,7 +27,7 @@
 
 bool SDL_RemovePath(const char *path)
 {
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
     }
     return SDL_SYS_RemovePath(path);
@@ -35,9 +35,10 @@ bool SDL_RemovePath(const char *path)
 
 bool SDL_RenamePath(const char *oldpath, const char *newpath)
 {
-    if (!oldpath) {
+    CHECK_PARAM(!oldpath) {
         return SDL_InvalidParamError("oldpath");
-    } else if (!newpath) {
+    }
+    CHECK_PARAM(!newpath) {
         return SDL_InvalidParamError("newpath");
     }
     return SDL_SYS_RenamePath(oldpath, newpath);
@@ -45,9 +46,10 @@ bool SDL_RenamePath(const char *oldpath, const char *newpath)
 
 bool SDL_CopyFile(const char *oldpath, const char *newpath)
 {
-    if (!oldpath) {
+    CHECK_PARAM(!oldpath) {
         return SDL_InvalidParamError("oldpath");
-    } else if (!newpath) {
+    }
+    CHECK_PARAM(!newpath) {
         return SDL_InvalidParamError("newpath");
     }
     return SDL_SYS_CopyFile(oldpath, newpath);
@@ -55,7 +57,7 @@ bool SDL_CopyFile(const char *oldpath, const char *newpath)
 
 bool SDL_CreateDirectory(const char *path)
 {
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
     }
 
@@ -116,9 +118,10 @@ bool SDL_CreateDirectory(const char *path)
 
 bool SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata)
 {
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
-    } else if (!callback) {
+    }
+    CHECK_PARAM(!callback) {
         return SDL_InvalidParamError("callback");
     }
     return SDL_SYS_EnumerateDirectory(path, callback, userdata);
@@ -133,10 +136,9 @@ bool SDL_GetPathInfo(const char *path, SDL_PathInfo *info)
     }
     SDL_zerop(info);
 
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
     }
-
     return SDL_SYS_GetPathInfo(path, info);
 }
 
@@ -364,7 +366,7 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob
     }
     *count = 0;
 
-    if (!path) {
+    CHECK_PARAM(!path) {
         SDL_InvalidParamError("path");
         return NULL;
     }
@@ -488,7 +490,8 @@ static char *CachedUserFolders[SDL_FOLDER_COUNT];
 const char *SDL_GetUserFolder(SDL_Folder folder)
 {
     const int idx = (int) folder;
-    if ((idx < 0) || (idx >= SDL_arraysize(CachedUserFolders))) {
+
+    CHECK_PARAM((idx < 0) || (idx >= SDL_arraysize(CachedUserFolders))) {
         SDL_InvalidParamError("folder");
         return NULL;
     }
@@ -502,7 +505,7 @@ const char *SDL_GetUserFolder(SDL_Folder folder)
 
 char *SDL_GetPrefPath(const char *org, const char *app)
 {
-    if (!app) {
+    CHECK_PARAM(!app) {
         SDL_InvalidParamError("app");
         return NULL;
     }

Plik diff jest za duży
+ 153 - 134
src/gpu/SDL_gpu.c


+ 15 - 15
src/haptic/SDL_haptic.c

@@ -107,10 +107,10 @@ static int SDL_Haptic_Get_Naxes(Uint16 vid, Uint16 pid)
 
 static SDL_Haptic *SDL_haptics = NULL;
 
-#define CHECK_HAPTIC_MAGIC(haptic, result)                  \
-    if (!SDL_ObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC)) { \
-        SDL_InvalidParamError("haptic");                    \
-        return result;                                      \
+#define CHECK_HAPTIC_MAGIC(haptic, result)                          \
+    CHECK_PARAM(!SDL_ObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC)) { \
+        SDL_InvalidParamError("haptic");                            \
+        return result;                                              \
     }
 
 bool SDL_InitHaptics(void)
@@ -512,7 +512,7 @@ bool SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effec
 {
     CHECK_HAPTIC_MAGIC(haptic, false);
 
-    if (!effect) {
+    CHECK_PARAM(!effect) {
         return false;
     }
 
@@ -528,7 +528,7 @@ SDL_HapticEffectID SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEf
 
     CHECK_HAPTIC_MAGIC(haptic, -1);
 
-    if (!effect) {
+    CHECK_PARAM(!effect) {
         SDL_InvalidParamError("effect");
         return -1;
     }
@@ -577,25 +577,25 @@ bool SDL_UpdateHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, const
 {
     CHECK_HAPTIC_MAGIC(haptic, false);
 
-    #ifdef SDL_JOYSTICK_HIDAPI
-    if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
-        return SDL_HIDAPI_HapticUpdateEffect(haptic, effect, data);
-    }
-    #endif
-
-    if (!ValidEffect(haptic, effect)) {
+    CHECK_PARAM(!ValidEffect(haptic, effect)) {
         return false;
     }
 
-    if (!data) {
+    CHECK_PARAM(!data) {
         return SDL_InvalidParamError("data");
     }
 
     // Can't change type dynamically.
-    if (data->type != haptic->effects[effect].effect.type) {
+    CHECK_PARAM(data->type != haptic->effects[effect].effect.type) {
         return SDL_SetError("Haptic: Updating effect type is illegal.");
     }
 
+    #ifdef SDL_JOYSTICK_HIDAPI
+    if (SDL_HIDAPI_HapticIsHidapi(haptic)) {
+        return SDL_HIDAPI_HapticUpdateEffect(haptic, effect, data);
+    }
+    #endif
+
     // Updates the effect
     if (!SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data)) {
         return false;

+ 15 - 10
src/io/SDL_asyncio.c

@@ -42,10 +42,11 @@ static const char *AsyncFileModeValid(const char *mode)
 
 SDL_AsyncIO *SDL_AsyncIOFromFile(const char *file, const char *mode)
 {
-    if (!file) {
+    CHECK_PARAM(!file) {
         SDL_InvalidParamError("file");
         return NULL;
-    } else if (!mode) {
+    }
+    CHECK_PARAM(!mode) {
         SDL_InvalidParamError("mode");
         return NULL;
     }
@@ -78,7 +79,7 @@ SDL_AsyncIO *SDL_AsyncIOFromFile(const char *file, const char *mode)
 
 Sint64 SDL_GetAsyncIOSize(SDL_AsyncIO *asyncio)
 {
-    if (!asyncio) {
+    CHECK_PARAM(!asyncio) {
         SDL_InvalidParamError("asyncio");
         return -1;
     }
@@ -87,11 +88,13 @@ Sint64 SDL_GetAsyncIOSize(SDL_AsyncIO *asyncio)
 
 static bool RequestAsyncIO(bool reading, SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata)
 {
-    if (!asyncio) {
+    CHECK_PARAM(!asyncio) {
         return SDL_InvalidParamError("asyncio");
-    } else if (!ptr) {
+    }
+    CHECK_PARAM(!ptr) {
         return SDL_InvalidParamError("ptr");
-    } else if (!queue) {
+    }
+    CHECK_PARAM(!queue) {
         return SDL_InvalidParamError("queue");
     }
 
@@ -143,9 +146,10 @@ bool SDL_WriteAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 siz
 
 bool SDL_CloseAsyncIO(SDL_AsyncIO *asyncio, bool flush, SDL_AsyncIOQueue *queue, void *userdata)
 {
-    if (!asyncio) {
+    CHECK_PARAM(!asyncio) {
         return SDL_InvalidParamError("asyncio");
-    } else if (!queue) {
+    }
+    CHECK_PARAM(!queue) {
         return SDL_InvalidParamError("queue");
     }
 
@@ -298,9 +302,10 @@ void SDL_QuitAsyncIO(void)
 
 bool SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata)
 {
-    if (!file) {
+    CHECK_PARAM(!file) {
         return SDL_InvalidParamError("file");
-    } else if (!queue) {
+    }
+    CHECK_PARAM(!queue) {
         return SDL_InvalidParamError("queue");
     }
 

+ 36 - 23
src/io/SDL_iostream.c

@@ -875,11 +875,11 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
 {
     SDL_IOStream *iostr = NULL;
 
-    if (!file || !*file) {
+    CHECK_PARAM(!file || !*file) {
         SDL_InvalidParamError("file");
         return NULL;
     }
-    if (!mode || !*mode) {
+    CHECK_PARAM(!mode || !*mode) {
         SDL_InvalidParamError("mode");
         return NULL;
     }
@@ -991,10 +991,11 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
 
 SDL_IOStream *SDL_IOFromMem(void *mem, size_t size)
 {
-    if (!mem) {
+    CHECK_PARAM(!mem) {
         SDL_InvalidParamError("mem");
         return NULL;
-    } else if (!size) {
+    }
+    CHECK_PARAM(!size) {
         SDL_InvalidParamError("size");
         return NULL;
     }
@@ -1032,10 +1033,11 @@ SDL_IOStream *SDL_IOFromMem(void *mem, size_t size)
 
 SDL_IOStream *SDL_IOFromConstMem(const void *mem, size_t size)
 {
-    if (!mem) {
+    CHECK_PARAM(!mem) {
         SDL_InvalidParamError("mem");
         return NULL;
-    } else if (!size) {
+    }
+    CHECK_PARAM(!size) {
         SDL_InvalidParamError("size");
         return NULL;
     }
@@ -1178,7 +1180,7 @@ SDL_IOStream *SDL_IOFromDynamicMem(void)
 
 SDL_IOStatus SDL_GetIOStatus(SDL_IOStream *context)
 {
-    if (!context) {
+    CHECK_PARAM(!context) {
         SDL_InvalidParamError("context");
         return SDL_IO_STATUS_ERROR;
     }
@@ -1187,11 +1189,11 @@ SDL_IOStatus SDL_GetIOStatus(SDL_IOStream *context)
 
 SDL_IOStream *SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata)
 {
-    if (!iface) {
+    CHECK_PARAM(!iface) {
         SDL_InvalidParamError("iface");
         return NULL;
     }
-    if (iface->version < sizeof(*iface)) {
+    CHECK_PARAM(iface->version < sizeof(*iface)) {
         // Update this to handle older versions of this interface
         SDL_SetError("Invalid interface, should be initialized with SDL_INIT_INTERFACE()");
         return NULL;
@@ -1227,7 +1229,7 @@ void *SDL_LoadFile_IO(SDL_IOStream *src, size_t *datasize, bool closeio)
     char *data = NULL, *newdata;
     bool loading_chunks = false;
 
-    if (!src) {
+    CHECK_PARAM(!src) {
         SDL_InvalidParamError("src");
         goto done;
     }
@@ -1308,12 +1310,12 @@ bool SDL_SaveFile_IO(SDL_IOStream *src, const void *data, size_t datasize, bool
     size_t size_total = 0;
     bool success = true;
 
-    if (!src) {
+    CHECK_PARAM(!src) {
         SDL_InvalidParamError("src");
         goto done;
     }
 
-    if (!data && datasize > 0) {
+    CHECK_PARAM(!data && datasize > 0) {
         SDL_InvalidParamError("data");
         goto done;
     }
@@ -1356,7 +1358,7 @@ bool SDL_SaveFile(const char *file, const void *data, size_t datasize)
 
 SDL_PropertiesID SDL_GetIOProperties(SDL_IOStream *context)
 {
-    if (!context) {
+    CHECK_PARAM(!context) {
         SDL_InvalidParamError("context");
         return 0;
     }
@@ -1369,9 +1371,10 @@ SDL_PropertiesID SDL_GetIOProperties(SDL_IOStream *context)
 
 Sint64 SDL_GetIOSize(SDL_IOStream *context)
 {
-    if (!context) {
+    CHECK_PARAM(!context) {
         return SDL_InvalidParamError("context");
     }
+
     if (!context->iface.size) {
         Sint64 pos, size;
 
@@ -1389,10 +1392,12 @@ Sint64 SDL_GetIOSize(SDL_IOStream *context)
 
 Sint64 SDL_SeekIO(SDL_IOStream *context, Sint64 offset, SDL_IOWhence whence)
 {
-    if (!context) {
+    CHECK_PARAM(!context) {
         SDL_InvalidParamError("context");
         return -1;
-    } else if (!context->iface.seek) {
+    }
+
+    if (!context->iface.seek) {
         SDL_Unsupported();
         return -1;
     }
@@ -1406,14 +1411,18 @@ Sint64 SDL_TellIO(SDL_IOStream *context)
 
 size_t SDL_ReadIO(SDL_IOStream *context, void *ptr, size_t size)
 {
-    if (!context) {
+    CHECK_PARAM(!context) {
         SDL_InvalidParamError("context");
         return 0;
-    } else if (!context->iface.read) {
+    }
+
+    if (!context->iface.read) {
         context->status = SDL_IO_STATUS_WRITEONLY;
         SDL_Unsupported();
         return 0;
-    } else if (size == 0) {
+    }
+
+    if (size == 0) {
         return 0;  // context->status doesn't change for this.
     }
 
@@ -1425,14 +1434,18 @@ size_t SDL_ReadIO(SDL_IOStream *context, void *ptr, size_t size)
 
 size_t SDL_WriteIO(SDL_IOStream *context, const void *ptr, size_t size)
 {
-    if (!context) {
+    CHECK_PARAM(!context) {
         SDL_InvalidParamError("context");
         return 0;
-    } else if (!context->iface.write) {
+    }
+
+    if (!context->iface.write) {
         context->status = SDL_IO_STATUS_READONLY;
         SDL_Unsupported();
         return 0;
-    } else if (size == 0) {
+    }
+
+    if (size == 0) {
         return 0;  // context->status doesn't change for this.
     }
 
@@ -1481,7 +1494,7 @@ bool SDL_FlushIO(SDL_IOStream *context)
 {
     bool result = true;
 
-    if (!context) {
+    CHECK_PARAM(!context) {
         return SDL_InvalidParamError("context");
     }
 

+ 8 - 8
src/joystick/SDL_gamepad.c

@@ -147,12 +147,12 @@ struct SDL_Gamepad
 
 #undef _guarded
 
-#define CHECK_GAMEPAD_MAGIC(gamepad, result)                    \
-    if (!SDL_ObjectValid(gamepad, SDL_OBJECT_TYPE_GAMEPAD) ||   \
-        !SDL_IsJoystickValid(gamepad->joystick)) {              \
-        SDL_InvalidParamError("gamepad");                       \
-        SDL_UnlockJoysticks();                                  \
-        return result;                                          \
+#define CHECK_GAMEPAD_MAGIC(gamepad, result)                            \
+    CHECK_PARAM(!SDL_ObjectValid(gamepad, SDL_OBJECT_TYPE_GAMEPAD) ||   \
+        !SDL_IsJoystickValid(gamepad->joystick)) {                      \
+        SDL_InvalidParamError("gamepad");                               \
+        SDL_UnlockJoysticks();                                          \
+        return result;                                                  \
     }
 
 static SDL_vidpid_list SDL_allowed_gamepads = {
@@ -2455,7 +2455,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa
 
     SDL_AssertJoysticksLocked();
 
-    if (!mappingString) {
+    CHECK_PARAM(!mappingString) {
         SDL_InvalidParamError("mappingString");
         return -1;
     }
@@ -2790,7 +2790,7 @@ bool SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping)
     SDL_GUID guid = SDL_GetJoystickGUIDForID(instance_id);
     bool result = false;
 
-    if (SDL_memcmp(&guid, &s_zeroGUID, sizeof(guid)) == 0) {
+    CHECK_PARAM(SDL_memcmp(&guid, &s_zeroGUID, sizeof(guid)) == 0) {
         return SDL_InvalidParamError("instance_id");
     }
 

+ 12 - 12
src/joystick/SDL_joystick.c

@@ -615,18 +615,18 @@ static SDL_vidpid_list zero_centered_devices = {
     false
 };
 
-#define CHECK_JOYSTICK_MAGIC(joystick, result)                  \
-    if (!SDL_ObjectValid(joystick, SDL_OBJECT_TYPE_JOYSTICK)) { \
-        SDL_InvalidParamError("joystick");                      \
-        SDL_UnlockJoysticks();                                  \
-        return result;                                          \
-    }
-
-#define CHECK_JOYSTICK_VIRTUAL(joystick, result)                \
-    if (!joystick->is_virtual) {                                \
-        SDL_SetError("joystick isn't virtual");                 \
-        SDL_UnlockJoysticks();                                  \
-        return result;                                          \
+#define CHECK_JOYSTICK_MAGIC(joystick, result)                          \
+    CHECK_PARAM(!SDL_ObjectValid(joystick, SDL_OBJECT_TYPE_JOYSTICK)) { \
+        SDL_InvalidParamError("joystick");                              \
+        SDL_UnlockJoysticks();                                          \
+        return result;                                                  \
+    }
+
+#define CHECK_JOYSTICK_VIRTUAL(joystick, result)                        \
+    CHECK_PARAM(!joystick->is_virtual) {                                \
+        SDL_SetError("joystick isn't virtual");                         \
+        SDL_UnlockJoysticks();                                          \
+        return result;                                                  \
     }
 
 bool SDL_JoysticksInitialized(void)

+ 2 - 2
src/joystick/virtual/SDL_virtualjoystick.c

@@ -138,11 +138,11 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des
 
     SDL_AssertJoysticksLocked();
 
-    if (!desc) {
+    CHECK_PARAM(!desc) {
         SDL_InvalidParamError("desc");
         return 0;
     }
-    if (desc->version < sizeof(*desc)) {
+    CHECK_PARAM(desc->version < sizeof(*desc)) {
         // Update this to handle older versions of this interface
         SDL_SetError("Invalid desc, should be initialized with SDL_INIT_INTERFACE()");
         return 0;

+ 1 - 1
src/loadso/windows/SDL_sysloadso.c

@@ -29,7 +29,7 @@
 
 SDL_SharedObject *SDL_LoadObject(const char *sofile)
 {
-    if (!sofile) {
+    CHECK_PARAM(!sofile) {
         SDL_InvalidParamError("sofile");
         return NULL;
     }

+ 1 - 1
src/misc/SDL_url.c

@@ -24,7 +24,7 @@
 
 bool SDL_OpenURL(const char *url)
 {
-    if (!url) {
+    CHECK_PARAM(!url) {
         return SDL_InvalidParamError("url");
     }
     return SDL_SYS_OpenURL(url);

+ 9 - 9
src/process/SDL_process.c

@@ -25,7 +25,7 @@
 
 SDL_Process *SDL_CreateProcess(const char * const *args, bool pipe_stdio)
 {
-    if (!args || !args[0] || !args[0][0]) {
+    CHECK_PARAM(!args || !args[0] || !args[0][0]) {
         SDL_InvalidParamError("args");
         return NULL;
     }
@@ -47,12 +47,12 @@ SDL_Process *SDL_CreateProcessWithProperties(SDL_PropertiesID props)
     const char * const *args = SDL_GetPointerProperty(props, SDL_PROP_PROCESS_CREATE_ARGS_POINTER, NULL);
 #if defined(SDL_PLATFORM_WINDOWS)
     const char *cmdline = SDL_GetStringProperty(props, SDL_PROP_PROCESS_CREATE_CMDLINE_STRING, NULL);
-    if ((!args || !args[0] || !args[0][0]) && (!cmdline || !cmdline[0])) {
+    CHECK_PARAM((!args || !args[0] || !args[0][0]) && (!cmdline || !cmdline[0])) {
         SDL_SetError("Either SDL_PROP_PROCESS_CREATE_ARGS_POINTER or SDL_PROP_PROCESS_CREATE_CMDLINE_STRING must be valid");
         return NULL;
     }
 #else
-    if (!args || !args[0] || !args[0][0]) {
+    CHECK_PARAM(!args || !args[0] || !args[0][0]) {
         SDL_InvalidParamError("SDL_PROP_PROCESS_CREATE_ARGS_POINTER");
         return NULL;
     }
@@ -81,7 +81,7 @@ SDL_Process *SDL_CreateProcessWithProperties(SDL_PropertiesID props)
 
 SDL_PropertiesID SDL_GetProcessProperties(SDL_Process *process)
 {
-    if (!process) {
+    CHECK_PARAM(!process) {
         return SDL_InvalidParamError("process");
     }
     return process->props;
@@ -98,7 +98,7 @@ void *SDL_ReadProcess(SDL_Process *process, size_t *datasize, int *exitcode)
         *exitcode = -1;
     }
 
-    if (!process) {
+    CHECK_PARAM(!process) {
         SDL_InvalidParamError("process");
         return NULL;
     }
@@ -118,7 +118,7 @@ void *SDL_ReadProcess(SDL_Process *process, size_t *datasize, int *exitcode)
 
 SDL_IOStream *SDL_GetProcessInput(SDL_Process *process)
 {
-    if (!process) {
+    CHECK_PARAM(!process) {
         SDL_InvalidParamError("process");
         return NULL;
     }
@@ -134,7 +134,7 @@ SDL_IOStream *SDL_GetProcessInput(SDL_Process *process)
 
 SDL_IOStream *SDL_GetProcessOutput(SDL_Process *process)
 {
-    if (!process) {
+    CHECK_PARAM(!process) {
         SDL_InvalidParamError("process");
         return NULL;
     }
@@ -150,7 +150,7 @@ SDL_IOStream *SDL_GetProcessOutput(SDL_Process *process)
 
 bool SDL_KillProcess(SDL_Process *process, bool force)
 {
-    if (!process) {
+    CHECK_PARAM(!process) {
         return SDL_InvalidParamError("process");
     }
 
@@ -163,7 +163,7 @@ bool SDL_KillProcess(SDL_Process *process, bool force)
 
 bool SDL_WaitProcess(SDL_Process *process, bool block, int *exitcode)
 {
-    if (!process) {
+    CHECK_PARAM(!process) {
         return SDL_InvalidParamError("process");
     }
 

Plik diff jest za duży
+ 236 - 348
src/render/SDL_render.c


+ 2 - 2
src/render/software/SDL_blendfillrect.c

@@ -238,7 +238,7 @@ bool SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode ble
 {
     SDL_Rect clipped;
 
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_BlendFillRect(): dst");
     }
 
@@ -306,7 +306,7 @@ bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_
     bool (*func)(SDL_Surface * dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
     bool result = true;
 
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
     }
 

+ 1 - 1
src/render/software/SDL_blendline.c

@@ -923,7 +923,7 @@ bool SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMo
 {
     BlendLineFunc func;
 
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_BlendLine(): dst");
     }
 

+ 2 - 2
src/render/software/SDL_blendpoint.c

@@ -236,7 +236,7 @@ static bool SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode bl
 
 bool SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 {
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_BlendPoint(): dst");
     }
 
@@ -302,7 +302,7 @@ bool SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_B
     bool (*func)(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
     bool result = true;
 
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_BlendPoints(): dst");
     }
 

+ 2 - 2
src/render/software/SDL_drawline.c

@@ -137,7 +137,7 @@ bool SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color
 {
     DrawLineFunc func;
 
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_DrawLine(): dst");
     }
 
@@ -164,7 +164,7 @@ bool SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32
     bool draw_end;
     DrawLineFunc func;
 
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_DrawLines(): dst");
     }
 

+ 2 - 2
src/render/software/SDL_drawpoint.c

@@ -27,7 +27,7 @@
 
 bool SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
 {
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_DrawPoint(): dst");
     }
 
@@ -66,7 +66,7 @@ bool SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32
     int i;
     int x, y;
 
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_DrawPoints(): dst");
     }
 

+ 3 - 3
src/render/software/SDL_render_sw.c

@@ -1121,12 +1121,12 @@ bool SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, S
 {
     SW_RenderData *data;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (SDL_BITSPERPIXEL(surface->format) < 8 ||
-        SDL_BITSPERPIXEL(surface->format) > 32) {
+    CHECK_PARAM(SDL_BITSPERPIXEL(surface->format) < 8 ||
+                SDL_BITSPERPIXEL(surface->format) > 32) {
         return SDL_SetError("Unsupported surface format");
     }
 

+ 2 - 2
src/render/software/SDL_triangle.c

@@ -502,10 +502,10 @@ bool SDL_SW_BlitTriangle(
 
     bool has_modulation;
 
-    if (!SDL_SurfaceValid(src)) {
+    CHECK_PARAM(!SDL_SurfaceValid(src)) {
         return SDL_InvalidParamError("src");
     }
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("dst");
     }
 

+ 5 - 5
src/sensor/SDL_sensor.c

@@ -57,11 +57,11 @@ static int SDL_sensors_locked;
 static bool SDL_sensors_initialized;
 static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL;
 
-#define CHECK_SENSOR_MAGIC(sensor, result)                  \
-    if (!SDL_ObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR)) { \
-        SDL_InvalidParamError("sensor");                    \
-        SDL_UnlockSensors();                                \
-        return result;                                      \
+#define CHECK_SENSOR_MAGIC(sensor, result)                          \
+    CHECK_PARAM(!SDL_ObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR)) { \
+        SDL_InvalidParamError("sensor");                            \
+        SDL_UnlockSensors();                                        \
+        return result;                                              \
     }
 
 bool SDL_SensorsInitialized(void)

+ 9 - 6
src/stdlib/SDL_getenv.c

@@ -222,7 +222,7 @@ char **SDL_GetEnvironmentVariables(SDL_Environment *env)
 {
     char **result = NULL;
 
-    if (!env) {
+    CHECK_PARAM(!env) {
         SDL_InvalidParamError("env");
         return NULL;
     }
@@ -253,11 +253,13 @@ bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const ch
 {
     bool result = false;
 
-    if (!env) {
+    CHECK_PARAM(!env) {
         return SDL_InvalidParamError("env");
-    } else if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL) {
+    }
+    CHECK_PARAM(!name || *name == '\0' || SDL_strchr(name, '=') != NULL) {
         return SDL_InvalidParamError("name");
-    } else if (!value) {
+    }
+    CHECK_PARAM(!value) {
         return SDL_InvalidParamError("value");
     }
 
@@ -292,9 +294,10 @@ bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name)
 {
     bool result = false;
 
-    if (!env) {
+    CHECK_PARAM(!env) {
         return SDL_InvalidParamError("env");
-    } else if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL) {
+    }
+    CHECK_PARAM(!name || *name == '\0' || SDL_strchr(name, '=') != NULL) {
         return SDL_InvalidParamError("name");
     }
 

+ 4 - 4
src/stdlib/SDL_malloc.c

@@ -6419,16 +6419,16 @@ bool SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
                                 SDL_realloc_func realloc_func,
                                 SDL_free_func free_func)
 {
-    if (!malloc_func) {
+    CHECK_PARAM(!malloc_func) {
         return SDL_InvalidParamError("malloc_func");
     }
-    if (!calloc_func) {
+    CHECK_PARAM(!calloc_func) {
         return SDL_InvalidParamError("calloc_func");
     }
-    if (!realloc_func) {
+    CHECK_PARAM(!realloc_func) {
         return SDL_InvalidParamError("realloc_func");
     }
-    if (!free_func) {
+    CHECK_PARAM(!free_func) {
         return SDL_InvalidParamError("free_func");
     }
 

+ 54 - 29
src/storage/SDL_storage.c

@@ -49,12 +49,12 @@ struct SDL_Storage
 };
 
 #define CHECK_STORAGE_MAGIC()                             \
-    if (!storage) {                                       \
+    CHECK_PARAM(!storage) {                               \
         return SDL_SetError("Invalid storage container"); \
     }
 
 #define CHECK_STORAGE_MAGIC_RET(result)            \
-    if (!storage) {                                \
+    CHECK_PARAM(!storage) {                        \
         SDL_SetError("Invalid storage container"); \
         return result;                             \
     }
@@ -183,11 +183,11 @@ SDL_Storage *SDL_OpenStorage(const SDL_StorageInterface *iface, void *userdata)
 {
     SDL_Storage *storage;
 
-    if (!iface) {
+    CHECK_PARAM(!iface) {
         SDL_InvalidParamError("iface");
         return NULL;
     }
-    if (iface->version < sizeof(*iface)) {
+    CHECK_PARAM(iface->version < sizeof(*iface)) {
         // Update this to handle older versions of this interface
         SDL_SetError("Invalid interface, should be initialized with SDL_INIT_INTERFACE()");
         return NULL;
@@ -245,11 +245,14 @@ bool SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destinati
 {
     CHECK_STORAGE_MAGIC()
 
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
-    } else if (!ValidateStoragePath(path)) {
+    }
+    CHECK_PARAM(!ValidateStoragePath(path)) {
         return false;
-    } else if (!storage->iface.read_file) {
+    }
+
+    if (!storage->iface.read_file) {
         return SDL_Unsupported();
     }
 
@@ -260,11 +263,14 @@ bool SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *so
 {
     CHECK_STORAGE_MAGIC()
 
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
-    } else if (!ValidateStoragePath(path)) {
+    }
+    CHECK_PARAM(!ValidateStoragePath(path)) {
         return false;
-    } else if (!storage->iface.write_file) {
+    }
+
+    if (!storage->iface.write_file) {
         return SDL_Unsupported();
     }
 
@@ -275,11 +281,14 @@ bool SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path)
 {
     CHECK_STORAGE_MAGIC()
 
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
-    } else if (!ValidateStoragePath(path)) {
+    }
+    CHECK_PARAM(!ValidateStoragePath(path)) {
         return false;
-    } else if (!storage->iface.mkdir) {
+    }
+
+    if (!storage->iface.mkdir) {
         return SDL_Unsupported();
     }
 
@@ -307,11 +316,14 @@ bool SDL_RemoveStoragePath(SDL_Storage *storage, const char *path)
 {
     CHECK_STORAGE_MAGIC()
 
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
-    } else if (!ValidateStoragePath(path)) {
+    }
+    CHECK_PARAM(!ValidateStoragePath(path)) {
         return false;
-    } else if (!storage->iface.remove) {
+    }
+
+    if (!storage->iface.remove) {
         return SDL_Unsupported();
     }
 
@@ -322,15 +334,20 @@ bool SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char
 {
     CHECK_STORAGE_MAGIC()
 
-    if (!oldpath) {
+    CHECK_PARAM(!oldpath) {
         return SDL_InvalidParamError("oldpath");
-    } else if (!newpath) {
+    }
+    CHECK_PARAM(!newpath) {
         return SDL_InvalidParamError("newpath");
-    } else if (!ValidateStoragePath(oldpath)) {
+    }
+
+    if (!ValidateStoragePath(oldpath)) {
         return false;
-    } else if (!ValidateStoragePath(newpath)) {
+    }
+    if (!ValidateStoragePath(newpath)) {
         return false;
-    } else if (!storage->iface.rename) {
+    }
+    if (!storage->iface.rename) {
         return SDL_Unsupported();
     }
 
@@ -341,15 +358,20 @@ bool SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *
 {
     CHECK_STORAGE_MAGIC()
 
-    if (!oldpath) {
+    CHECK_PARAM(!oldpath) {
         return SDL_InvalidParamError("oldpath");
-    } else if (!newpath) {
+    }
+    CHECK_PARAM(!newpath) {
         return SDL_InvalidParamError("newpath");
-    } else if (!ValidateStoragePath(oldpath)) {
+    }
+
+    if (!ValidateStoragePath(oldpath)) {
         return false;
-    } else if (!ValidateStoragePath(newpath)) {
+    }
+    if (!ValidateStoragePath(newpath)) {
         return false;
-    } else if (!storage->iface.copy) {
+    }
+    if (!storage->iface.copy) {
         return SDL_Unsupported();
     }
 
@@ -367,11 +389,14 @@ bool SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo
 
     CHECK_STORAGE_MAGIC()
 
-    if (!path) {
+    CHECK_PARAM(!path) {
         return SDL_InvalidParamError("path");
-    } else if (!ValidateStoragePath(path)) {
+    }
+    CHECK_PARAM(!ValidateStoragePath(path)) {
         return false;
-    } else if (!storage->iface.info) {
+    }
+
+    if (!storage->iface.info) {
         return SDL_Unsupported();
     }
 

+ 2 - 2
src/thread/SDL_thread.c

@@ -41,7 +41,7 @@ void *SDL_GetTLS(SDL_TLSID *id)
     SDL_TLSData *storage;
     int storage_index;
 
-    if (id == NULL) {
+    CHECK_PARAM(id == NULL) {
         SDL_InvalidParamError("id");
         return NULL;
     }
@@ -59,7 +59,7 @@ bool SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback dest
     SDL_TLSData *storage;
     int storage_index;
 
-    if (id == NULL) {
+    CHECK_PARAM(id == NULL) {
         return SDL_InvalidParamError("id");
     }
 

+ 3 - 3
src/time/SDL_time.c

@@ -168,13 +168,13 @@ bool SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks)
     static const Sint64 min_seconds = SDL_NS_TO_SECONDS(SDL_MIN_TIME) + 1;
     bool result = true;
 
-    if (!dt) {
+    CHECK_PARAM(!dt) {
         return SDL_InvalidParamError("dt");
     }
-    if (!ticks) {
+    CHECK_PARAM(!ticks) {
         return SDL_InvalidParamError("ticks");
     }
-    if (!SDL_DateTimeIsValid(dt)) {
+    CHECK_PARAM(!SDL_DateTimeIsValid(dt)) {
         // The validation function sets the error string.
         return false;
     }

+ 2 - 2
src/time/n3ds/SDL_systime.c

@@ -108,7 +108,7 @@ void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf)
 
 bool SDL_GetCurrentTime(SDL_Time *ticks)
 {
-    if (!ticks) {
+    CHECK_PARAM(!ticks) {
         return SDL_InvalidParamError("ticks");
     }
 
@@ -123,7 +123,7 @@ bool SDL_GetCurrentTime(SDL_Time *ticks)
 
 bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime)
 {
-    if (!dt) {
+    CHECK_PARAM(!dt) {
         return SDL_InvalidParamError("dt");
     }
 

+ 1 - 1
src/time/ngage/SDL_systime.cpp

@@ -152,7 +152,7 @@ void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf)
 
 bool SDL_GetCurrentTime(SDL_Time *ticks)
 {
-    if (!ticks) {
+    CHECK_PARAM(!ticks) {
         return SDL_InvalidParamError("ticks");
     }
 

+ 2 - 2
src/time/ps2/SDL_systime.c

@@ -34,7 +34,7 @@ void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf)
 
 bool SDL_GetCurrentTime(SDL_Time *ticks)
 {
-    if (!ticks) {
+    CHECK_PARAM(!ticks) {
         return SDL_InvalidParamError("ticks");
     }
 
@@ -45,7 +45,7 @@ bool SDL_GetCurrentTime(SDL_Time *ticks)
 
 bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime)
 {
-    if (!dt) {
+    CHECK_PARAM(!dt) {
         return SDL_InvalidParamError("dt");
     }
 

+ 2 - 2
src/time/psp/SDL_systime.c

@@ -69,7 +69,7 @@ bool SDL_GetCurrentTime(SDL_Time *ticks)
 {
     u64 sceTicks;
 
-    if (!ticks) {
+    CHECK_PARAM(!ticks) {
         return SDL_InvalidParamError("ticks");
     }
 
@@ -99,7 +99,7 @@ bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime)
     u64 local;
     int ret = 0;
 
-    if (!dt) {
+    CHECK_PARAM(!dt) {
         return SDL_InvalidParamError("dt");
     }
 

+ 2 - 2
src/time/unix/SDL_systime.c

@@ -101,7 +101,7 @@ found_date:
 
 bool SDL_GetCurrentTime(SDL_Time *ticks)
 {
-    if (!ticks) {
+    CHECK_PARAM(!ticks) {
         return SDL_InvalidParamError("ticks");
     }
 #ifdef HAVE_CLOCK_GETTIME
@@ -158,7 +158,7 @@ bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime)
 #endif
     struct tm *tm = NULL;
 
-    if (!dt) {
+    CHECK_PARAM(!dt) {
         return SDL_InvalidParamError("dt");
     }
 

+ 2 - 2
src/time/vita/SDL_systime.c

@@ -75,7 +75,7 @@ bool SDL_GetCurrentTime(SDL_Time *ticks)
 {
     SceRtcTick sceTicks;
 
-    if (!ticks) {
+    CHECK_PARAM(!ticks) {
         return SDL_InvalidParamError("ticks");
     }
 
@@ -104,7 +104,7 @@ bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime)
     SceRtcTick sceTicks, sceLocalTicks;
     int ret = 0;
 
-    if (!dt) {
+    CHECK_PARAM(!dt) {
         return SDL_InvalidParamError("dt");
     }
 

+ 2 - 2
src/time/windows/SDL_systime.c

@@ -79,7 +79,7 @@ bool SDL_GetCurrentTime(SDL_Time *ticks)
 {
     FILETIME ft;
 
-    if (!ticks) {
+    CHECK_PARAM(!ticks) {
         return SDL_InvalidParamError("ticks");
     }
 
@@ -115,7 +115,7 @@ bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime)
     SYSTEMTIME *st = NULL;
     Uint32 low, high;
 
-    if (!dt) {
+    CHECK_PARAM(!dt) {
         return SDL_InvalidParamError("dt");
     }
 

+ 4 - 4
src/timer/SDL_timer.c

@@ -301,7 +301,7 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
     SDL_Timer *timer;
     SDL_TimerMap *entry;
 
-    if (!callback_ms && !callback_ns) {
+    CHECK_PARAM(!callback_ms && !callback_ns) {
         SDL_InvalidParamError("callback");
         return 0;
     }
@@ -374,7 +374,7 @@ bool SDL_RemoveTimer(SDL_TimerID id)
     SDL_TimerMap *prev, *entry;
     bool canceled = false;
 
-    if (!id) {
+    CHECK_PARAM(!id) {
         return SDL_InvalidParamError("id");
     }
 
@@ -467,7 +467,7 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
     SDL_TimerData *data = &SDL_timer_data;
     SDL_TimerMap *entry;
 
-    if (!callback_ms && !callback_ns) {
+    CHECK_PARAM(!callback_ms && !callback_ns) {
         SDL_InvalidParamError("callback");
         return 0;
     }
@@ -507,7 +507,7 @@ bool SDL_RemoveTimer(SDL_TimerID id)
     SDL_TimerData *data = &SDL_timer_data;
     SDL_TimerMap *prev, *entry;
 
-    if (!id) {
+    CHECK_PARAM(!id) {
         return SDL_InvalidParamError("id");
     }
 

+ 11 - 11
src/tray/cocoa/SDL_tray.m

@@ -203,7 +203,7 @@ void SDL_SetTrayTooltip(SDL_Tray *tray, const char *tooltip)
 
 SDL_TrayMenu *SDL_CreateTrayMenu(SDL_Tray *tray)
 {
-    if (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
+    CHECK_PARAM(!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
         SDL_InvalidParamError("tray");
         return NULL;
     }
@@ -230,7 +230,7 @@ SDL_TrayMenu *SDL_CreateTrayMenu(SDL_Tray *tray)
 
 SDL_TrayMenu *SDL_GetTrayMenu(SDL_Tray *tray)
 {
-    if (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
+    CHECK_PARAM(!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
         SDL_InvalidParamError("tray");
         return NULL;
     }
@@ -240,7 +240,7 @@ SDL_TrayMenu *SDL_GetTrayMenu(SDL_Tray *tray)
 
 SDL_TrayMenu *SDL_CreateTraySubmenu(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -277,7 +277,7 @@ SDL_TrayMenu *SDL_CreateTraySubmenu(SDL_TrayEntry *entry)
 
 SDL_TrayMenu *SDL_GetTraySubmenu(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -287,7 +287,7 @@ SDL_TrayMenu *SDL_GetTraySubmenu(SDL_TrayEntry *entry)
 
 const SDL_TrayEntry **SDL_GetTrayEntries(SDL_TrayMenu *menu, int *count)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }
@@ -337,12 +337,12 @@ void SDL_RemoveTrayEntry(SDL_TrayEntry *entry)
 
 SDL_TrayEntry *SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *label, SDL_TrayEntryFlags flags)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }
 
-    if (pos < -1 || pos > menu->nEntries) {
+    CHECK_PARAM(pos < -1 || pos > menu->nEntries) {
         SDL_InvalidParamError("pos");
         return NULL;
     }
@@ -405,7 +405,7 @@ void SDL_SetTrayEntryLabel(SDL_TrayEntry *entry, const char *label)
 
 const char *SDL_GetTrayEntryLabel(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -476,7 +476,7 @@ void SDL_ClickTrayEntry(SDL_TrayEntry *entry)
 
 SDL_TrayMenu *SDL_GetTrayEntryParent(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -486,7 +486,7 @@ SDL_TrayMenu *SDL_GetTrayEntryParent(SDL_TrayEntry *entry)
 
 SDL_TrayEntry *SDL_GetTrayMenuParentEntry(SDL_TrayMenu *menu)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }
@@ -496,7 +496,7 @@ SDL_TrayEntry *SDL_GetTrayMenuParentEntry(SDL_TrayMenu *menu)
 
 SDL_Tray *SDL_GetTrayMenuParentTray(SDL_TrayMenu *menu)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }

+ 10 - 10
src/tray/unix/SDL_tray.c

@@ -359,7 +359,7 @@ void SDL_SetTrayTooltip(SDL_Tray *tray, const char *tooltip)
 
 SDL_TrayMenu *SDL_CreateTrayMenu(SDL_Tray *tray)
 {
-    if (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
+    CHECK_PARAM(!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
         SDL_InvalidParamError("tray");
         return NULL;
     }
@@ -388,7 +388,7 @@ SDL_TrayMenu *SDL_CreateTrayMenu(SDL_Tray *tray)
 
 SDL_TrayMenu *SDL_GetTrayMenu(SDL_Tray *tray)
 {
-    if (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
+    CHECK_PARAM(!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
         SDL_InvalidParamError("tray");
         return NULL;
     }
@@ -398,7 +398,7 @@ SDL_TrayMenu *SDL_GetTrayMenu(SDL_Tray *tray)
 
 SDL_TrayMenu *SDL_CreateTraySubmenu(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -439,7 +439,7 @@ SDL_TrayMenu *SDL_CreateTraySubmenu(SDL_TrayEntry *entry)
 
 SDL_TrayMenu *SDL_GetTraySubmenu(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -449,7 +449,7 @@ SDL_TrayMenu *SDL_GetTraySubmenu(SDL_TrayEntry *entry)
 
 const SDL_TrayEntry **SDL_GetTrayEntries(SDL_TrayMenu *menu, int *count)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }
@@ -502,12 +502,12 @@ void SDL_RemoveTrayEntry(SDL_TrayEntry *entry)
 
 SDL_TrayEntry *SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *label, SDL_TrayEntryFlags flags)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }
 
-    if (pos < -1 || pos > menu->nEntries) {
+    CHECK_PARAM(pos < -1 || pos > menu->nEntries) {
         SDL_InvalidParamError("pos");
         return NULL;
     }
@@ -600,7 +600,7 @@ void SDL_SetTrayEntryLabel(SDL_TrayEntry *entry, const char *label)
 
 const char *SDL_GetTrayEntryLabel(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -705,7 +705,7 @@ void SDL_ClickTrayEntry(SDL_TrayEntry *entry)
 
 SDL_TrayMenu *SDL_GetTrayEntryParent(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -720,7 +720,7 @@ SDL_TrayEntry *SDL_GetTrayMenuParentEntry(SDL_TrayMenu *menu)
 
 SDL_Tray *SDL_GetTrayMenuParentTray(SDL_TrayMenu *menu)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }

+ 11 - 11
src/tray/windows/SDL_tray.c

@@ -311,7 +311,7 @@ void SDL_SetTrayTooltip(SDL_Tray *tray, const char *tooltip)
 
 SDL_TrayMenu *SDL_CreateTrayMenu(SDL_Tray *tray)
 {
-    if (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
+    CHECK_PARAM(!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
         SDL_InvalidParamError("tray");
         return NULL;
     }
@@ -331,7 +331,7 @@ SDL_TrayMenu *SDL_CreateTrayMenu(SDL_Tray *tray)
 
 SDL_TrayMenu *SDL_GetTrayMenu(SDL_Tray *tray)
 {
-    if (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
+    CHECK_PARAM(!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) {
         SDL_InvalidParamError("tray");
         return NULL;
     }
@@ -341,7 +341,7 @@ SDL_TrayMenu *SDL_GetTrayMenu(SDL_Tray *tray)
 
 SDL_TrayMenu *SDL_CreateTraySubmenu(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -356,7 +356,7 @@ SDL_TrayMenu *SDL_CreateTraySubmenu(SDL_TrayEntry *entry)
 
 SDL_TrayMenu *SDL_GetTraySubmenu(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -366,7 +366,7 @@ SDL_TrayMenu *SDL_GetTraySubmenu(SDL_TrayEntry *entry)
 
 const SDL_TrayEntry **SDL_GetTrayEntries(SDL_TrayMenu *menu, int *count)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }
@@ -419,12 +419,12 @@ void SDL_RemoveTrayEntry(SDL_TrayEntry *entry)
 
 SDL_TrayEntry *SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *label, SDL_TrayEntryFlags flags)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }
 
-    if (pos < -1 || pos > menu->nEntries) {
+    CHECK_PARAM(pos < -1 || pos > menu->nEntries) {
         SDL_InvalidParamError("pos");
         return NULL;
     }
@@ -550,7 +550,7 @@ void SDL_SetTrayEntryLabel(SDL_TrayEntry *entry, const char *label)
 
 const char *SDL_GetTrayEntryLabel(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -633,7 +633,7 @@ void SDL_ClickTrayEntry(SDL_TrayEntry *entry)
 
 SDL_TrayMenu *SDL_GetTrayEntryParent(SDL_TrayEntry *entry)
 {
-    if (!entry) {
+    CHECK_PARAM(!entry) {
         SDL_InvalidParamError("entry");
         return NULL;
     }
@@ -643,7 +643,7 @@ SDL_TrayMenu *SDL_GetTrayEntryParent(SDL_TrayEntry *entry)
 
 SDL_TrayEntry *SDL_GetTrayMenuParentEntry(SDL_TrayMenu *menu)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }
@@ -653,7 +653,7 @@ SDL_TrayEntry *SDL_GetTrayMenuParentEntry(SDL_TrayMenu *menu)
 
 SDL_Tray *SDL_GetTrayMenuParentTray(SDL_TrayMenu *menu)
 {
-    if (!menu) {
+    CHECK_PARAM(!menu) {
         SDL_InvalidParamError("menu");
         return NULL;
     }

+ 3 - 3
src/video/SDL_bmp.c

@@ -216,7 +216,7 @@ SDL_Surface *SDL_LoadBMP_IO(SDL_IOStream *src, bool closeio)
 
     // Make sure we are passed a valid data source
     surface = NULL;
-    if (!src) {
+    CHECK_PARAM(!src) {
         SDL_InvalidParamError("src");
         goto done;
     }
@@ -630,11 +630,11 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
     Uint32 bV5Reserved = 0;
 
     // Make sure we have somewhere to save
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         goto done;
     }
-    if (!dst) {
+    CHECK_PARAM(!dst) {
         SDL_InvalidParamError("dst");
         goto done;
     }

+ 2 - 2
src/video/SDL_clipboard.c

@@ -196,7 +196,7 @@ void *SDL_GetClipboardData(const char *mime_type, size_t *size)
         return NULL;
     }
 
-    if (!mime_type) {
+    CHECK_PARAM(!mime_type) {
         SDL_InvalidParamError("mime_type");
         return NULL;
     }
@@ -245,7 +245,7 @@ bool SDL_HasClipboardData(const char *mime_type)
         return SDL_UninitializedVideo();
     }
 
-    if (!mime_type) {
+    CHECK_PARAM(!mime_type) {
         return SDL_InvalidParamError("mime_type");
     }
 

+ 9 - 9
src/video/SDL_fillrect.c

@@ -238,7 +238,7 @@ static void SDL_FillSurfaceRect4(Uint8 *pixels, int pitch, Uint32 color, int w,
  */
 bool SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
 {
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_FillSurfaceRect(): dst");
     }
 
@@ -262,24 +262,24 @@ bool SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Ui
     void (*fill_function)(Uint8 * pixels, int pitch, Uint32 color, int w, int h) = NULL;
     int i;
 
-    if (!SDL_SurfaceValid(dst)) {
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("SDL_FillSurfaceRects(): dst");
     }
 
-    // Nothing to do
-    if (dst->w == 0 || dst->h == 0) {
-        return true;
-    }
-
     // Perform software fill
-    if (!dst->pixels) {
+    CHECK_PARAM(!dst->pixels) {
         return SDL_SetError("SDL_FillSurfaceRects(): You must lock the surface");
     }
 
-    if (!rects) {
+    CHECK_PARAM(!rects) {
         return SDL_InvalidParamError("SDL_FillSurfaceRects(): rects");
     }
 
+    // Nothing to do
+    if (dst->w == 0 || dst->h == 0) {
+        return true;
+    }
+
     /* This function doesn't usually work on surfaces < 8 bpp
      * Except: support for 4bits, when filling full size.
      */

+ 5 - 5
src/video/SDL_pixels.c

@@ -1035,7 +1035,7 @@ SDL_Palette *SDL_CreatePalette(int ncolors)
     SDL_Palette *palette;
 
     // Input validation
-    if (ncolors < 1) {
+    CHECK_PARAM(ncolors < 1) {
         SDL_InvalidParamError("ncolors");
         return NULL;
     }
@@ -1219,13 +1219,13 @@ void SDL_DetectPalette(const SDL_Palette *pal, bool *is_opaque, bool *has_alpha_
 // Find the opaque pixel value corresponding to an RGB triple
 Uint32 SDL_MapRGB(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b)
 {
-    if (!format) {
+    CHECK_PARAM(!format) {
         SDL_InvalidParamError("format");
         return 0;
     }
 
     if (SDL_ISPIXELFORMAT_INDEXED(format->format)) {
-        if (!palette) {
+        CHECK_PARAM(!palette) {
             SDL_InvalidParamError("palette");
             return 0;
         }
@@ -1248,13 +1248,13 @@ Uint32 SDL_MapRGB(const SDL_PixelFormatDetails *format, const SDL_Palette *palet
 // Find the pixel value corresponding to an RGBA quadruple
 Uint32 SDL_MapRGBA(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 {
-    if (!format) {
+    CHECK_PARAM(!format) {
         SDL_InvalidParamError("format");
         return 0;
     }
 
     if (SDL_ISPIXELFORMAT_INDEXED(format->format)) {
-        if (!palette) {
+        CHECK_PARAM(!palette) {
             SDL_InvalidParamError("palette");
             return 0;
         }

+ 9 - 5
src/video/SDL_rect.c

@@ -31,19 +31,23 @@ bool SDL_GetSpanEnclosingRect(int width, int height,
     int span_y1, span_y2;
     int rect_y1, rect_y2;
 
-    if (width < 1) {
+    CHECK_PARAM(width < 1) {
         SDL_InvalidParamError("width");
         return false;
-    } else if (height < 1) {
+    }
+    CHECK_PARAM(height < 1) {
         SDL_InvalidParamError("height");
         return false;
-    } else if (!rects) {
+    }
+    CHECK_PARAM(!rects) {
         SDL_InvalidParamError("rects");
         return false;
-    } else if (!span) {
+    }
+    CHECK_PARAM(!span) {
         SDL_InvalidParamError("span");
         return false;
-    } else if (numrects < 1) {
+    }
+    CHECK_PARAM(numrects < 1) {
         SDL_InvalidParamError("numrects");
         return false;
     }

+ 45 - 26
src/video/SDL_rect_impl.h

@@ -38,17 +38,20 @@ bool SDL_HASINTERSECTION(const RECTTYPE *A, const RECTTYPE *B)
 {
     SCALARTYPE Amin, Amax, Bmin, Bmax;
 
-    if (!A) {
+    CHECK_PARAM(!A) {
         SDL_InvalidParamError("A");
         return false;
-    } else if (!B) {
+    }
+    CHECK_PARAM(!B) {
         SDL_InvalidParamError("B");
         return false;
-    } else if (SDL_RECT_CAN_OVERFLOW(A) ||
-               SDL_RECT_CAN_OVERFLOW(B)) {
+    }
+    CHECK_PARAM(SDL_RECT_CAN_OVERFLOW(A) || SDL_RECT_CAN_OVERFLOW(B)) {
         SDL_SetError("Potential rect math overflow");
         return false;
-    } else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) {
+    }
+
+    if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) {
         return false; // Special cases for empty rects
     }
 
@@ -87,20 +90,24 @@ bool SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
 {
     SCALARTYPE Amin, Amax, Bmin, Bmax;
 
-    if (!A) {
+    CHECK_PARAM(!A) {
         SDL_InvalidParamError("A");
         return false;
-    } else if (!B) {
+    }
+    CHECK_PARAM(!B) {
         SDL_InvalidParamError("B");
         return false;
-    } else if (SDL_RECT_CAN_OVERFLOW(A) ||
-               SDL_RECT_CAN_OVERFLOW(B)) {
+    }
+    CHECK_PARAM(SDL_RECT_CAN_OVERFLOW(A) || SDL_RECT_CAN_OVERFLOW(B)) {
         SDL_SetError("Potential rect math overflow");
         return false;
-    } else if (!result) {
+    }
+    CHECK_PARAM(!result) {
         SDL_InvalidParamError("result");
         return false;
-    } else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { // Special cases for empty rects
+    }
+
+    if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { // Special cases for empty rects
         result->w = 0;
         result->h = 0;
         return false;
@@ -141,16 +148,20 @@ bool SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
 {
     SCALARTYPE Amin, Amax, Bmin, Bmax;
 
-    if (!A) {
+    CHECK_PARAM(!A) {
         return SDL_InvalidParamError("A");
-    } else if (!B) {
+    }
+    CHECK_PARAM(!B) {
         return SDL_InvalidParamError("B");
-    } else if (SDL_RECT_CAN_OVERFLOW(A) ||
-               SDL_RECT_CAN_OVERFLOW(B)) {
+    }
+    CHECK_PARAM(SDL_RECT_CAN_OVERFLOW(A) || SDL_RECT_CAN_OVERFLOW(B)) {
         return SDL_SetError("Potential rect math overflow");
-    } else if (!result) {
+    }
+    CHECK_PARAM(!result) {
         return SDL_InvalidParamError("result");
-    } else if (SDL_RECTEMPTY(A)) { // Special cases for empty Rects
+    }
+
+    if (SDL_RECTEMPTY(A)) { // Special cases for empty Rects
         if (SDL_RECTEMPTY(B)) {    // A and B empty
             SDL_zerop(result);
         } else { // A empty, B not empty
@@ -201,10 +212,11 @@ bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *clip,
     SCALARTYPE x, y;
     int i;
 
-    if (!points) {
+    CHECK_PARAM(!points) {
         SDL_InvalidParamError("points");
         return false;
-    } else if (count < 1) {
+    }
+    CHECK_PARAM(count < 1) {
         SDL_InvalidParamError("count");
         return false;
     }
@@ -320,25 +332,32 @@ bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTYPE *
     SCALARTYPE recty2;
     int outcode1, outcode2;
 
-    if (!rect) {
+    CHECK_PARAM(!rect) {
         SDL_InvalidParamError("rect");
         return false;
-    } else if (SDL_RECT_CAN_OVERFLOW(rect)) {
+    }
+    CHECK_PARAM(SDL_RECT_CAN_OVERFLOW(rect)) {
         SDL_SetError("Potential rect math overflow");
         return false;
-    } else if (!X1) {
+    }
+    CHECK_PARAM(!X1) {
         SDL_InvalidParamError("X1");
         return false;
-    } else if (!Y1) {
+    }
+    CHECK_PARAM(!Y1) {
         SDL_InvalidParamError("Y1");
         return false;
-    } else if (!X2) {
+    }
+    CHECK_PARAM(!X2) {
         SDL_InvalidParamError("X2");
         return false;
-    } else if (!Y2) {
+    }
+    CHECK_PARAM(!Y2) {
         SDL_InvalidParamError("Y2");
         return false;
-    } else if (SDL_RECTEMPTY(rect)) {
+    }
+
+    if (SDL_RECTEMPTY(rect)) {
         return false; // Special case for empty rect
     }
 

+ 2 - 2
src/video/SDL_stb.c

@@ -140,11 +140,11 @@ bool SDL_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
     bool retval = true;
 
     // Make sure we have somewhere to save
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         retval = SDL_InvalidParamError("surface");
         goto done;
     }
-    if (!dst) {
+    CHECK_PARAM(!dst) {
         retval = SDL_InvalidParamError("dst");
         goto done;
     }

+ 2 - 2
src/video/SDL_stretch.c

@@ -33,10 +33,10 @@ bool SDL_StretchSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *
     SDL_Rect full_src;
     SDL_Rect full_dst;
 
-    if (!src) {
+    CHECK_PARAM(!src) {
         return SDL_InvalidParamError("src");
     }
-    if (!dst) {
+    CHECK_PARAM(!dst) {
         return SDL_InvalidParamError("dst");
     }
 

+ 85 - 77
src/video/SDL_surface.c

@@ -194,17 +194,17 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
     size_t pitch, size;
     SDL_Surface *surface;
 
-    if (width < 0) {
+    CHECK_PARAM(width < 0) {
         SDL_InvalidParamError("width");
         return NULL;
     }
 
-    if (height < 0) {
+    CHECK_PARAM(height < 0) {
         SDL_InvalidParamError("height");
         return NULL;
     }
 
-    if (format == SDL_PIXELFORMAT_UNKNOWN) {
+    CHECK_PARAM(format == SDL_PIXELFORMAT_UNKNOWN) {
         SDL_InvalidParamError("format");
         return NULL;
     }
@@ -245,17 +245,17 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
  */
 SDL_Surface *SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch)
 {
-    if (width < 0) {
+    CHECK_PARAM(width < 0) {
         SDL_InvalidParamError("width");
         return NULL;
     }
 
-    if (height < 0) {
+    CHECK_PARAM(height < 0) {
         SDL_InvalidParamError("height");
         return NULL;
     }
 
-    if (format == SDL_PIXELFORMAT_UNKNOWN) {
+    CHECK_PARAM(format == SDL_PIXELFORMAT_UNKNOWN) {
         SDL_InvalidParamError("format");
         return NULL;
     }
@@ -270,7 +270,7 @@ SDL_Surface *SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format
             return NULL;
         }
 
-        if (pitch < 0 || (size_t)pitch < minimalPitch) {
+        CHECK_PARAM(pitch < 0 || (size_t)pitch < minimalPitch) {
             SDL_InvalidParamError("pitch");
             return NULL;
         }
@@ -287,7 +287,7 @@ SDL_Surface *SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format
 
 SDL_PropertiesID SDL_GetSurfaceProperties(SDL_Surface *surface)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         return 0;
     }
@@ -300,7 +300,7 @@ SDL_PropertiesID SDL_GetSurfaceProperties(SDL_Surface *surface)
 
 bool SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -378,12 +378,12 @@ SDL_Palette *SDL_CreateSurfacePalette(SDL_Surface *surface)
 {
     SDL_Palette *palette;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         return NULL;
     }
 
-    if (!SDL_ISPIXELFORMAT_INDEXED(surface->format)) {
+    CHECK_PARAM(!SDL_ISPIXELFORMAT_INDEXED(surface->format)) {
         SDL_SetError("The surface is not indexed format");
         return NULL;
     }
@@ -416,11 +416,11 @@ SDL_Palette *SDL_CreateSurfacePalette(SDL_Surface *surface)
 
 bool SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (palette && palette->ncolors > (1 << SDL_BITSPERPIXEL(surface->format))) {
+    CHECK_PARAM(palette && palette->ncolors > (1 << SDL_BITSPERPIXEL(surface->format))) {
         return SDL_SetError("SDL_SetSurfacePalette() passed a palette that doesn't match the surface format");
     }
 
@@ -452,11 +452,11 @@ SDL_Palette *SDL_GetSurfacePalette(SDL_Surface *surface)
 
 bool SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (!SDL_SurfaceValid(image)) {
+    CHECK_PARAM(!SDL_SurfaceValid(image)) {
         return SDL_InvalidParamError("image");
     }
 
@@ -486,7 +486,7 @@ SDL_Surface **SDL_GetSurfaceImages(SDL_Surface *surface, int *count)
         *count = 0;
     }
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         return NULL;
     }
@@ -510,7 +510,7 @@ SDL_Surface **SDL_GetSurfaceImages(SDL_Surface *surface, int *count)
 
 SDL_Surface *SDL_GetSurfaceImage(SDL_Surface *surface, float display_scale)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         return NULL;
     }
@@ -598,7 +598,7 @@ bool SDL_SetSurfaceRLE(SDL_Surface *surface, bool enabled)
 {
     int flags;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -631,11 +631,11 @@ bool SDL_SetSurfaceColorKey(SDL_Surface *surface, bool enabled, Uint32 key)
 {
     int flags;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (surface->palette && key >= ((Uint32)surface->palette->ncolors)) {
+    CHECK_PARAM(surface->palette && key >= ((Uint32)surface->palette->ncolors)) {
         return SDL_InvalidParamError("key");
     }
 
@@ -672,11 +672,11 @@ bool SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key)
         *key = 0;
     }
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (!(surface->map.info.flags & SDL_COPY_COLORKEY)) {
+    CHECK_PARAM(!(surface->map.info.flags & SDL_COPY_COLORKEY)) {
         return SDL_SetError("Surface doesn't have a colorkey");
     }
 
@@ -781,7 +781,7 @@ bool SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
 {
     int flags;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -803,7 +803,7 @@ bool SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
 
 bool SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         if (r) {
             *r = 255;
         }
@@ -832,7 +832,7 @@ bool SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
 {
     int flags;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -852,7 +852,7 @@ bool SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
 
 bool SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         if (alpha) {
             *alpha = 255;
         }
@@ -870,11 +870,11 @@ bool SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
     int flags;
     bool result = true;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (blendMode == SDL_BLENDMODE_INVALID) {
+    CHECK_PARAM(blendMode == SDL_BLENDMODE_INVALID) {
         return SDL_InvalidParamError("blendMode");
     }
 
@@ -919,7 +919,7 @@ bool SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
         *blendMode = SDL_BLENDMODE_INVALID;
     }
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -978,13 +978,13 @@ bool SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect)
 
 bool SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         if (rect) {
             SDL_zerop(rect);
         }
         return SDL_InvalidParamError("surface");
     }
-    if (!rect) {
+    CHECK_PARAM(!rect) {
         return SDL_InvalidParamError("rect");
     }
     *rect = surface->clip_rect;
@@ -1017,11 +1017,13 @@ bool SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst
     SDL_Rect r_src, r_dst;
 
     // Make sure the surfaces aren't locked
-    if (!SDL_SurfaceValid(src)) {
+    CHECK_PARAM(!SDL_SurfaceValid(src)) {
         return SDL_InvalidParamError("src");
-    } else if (!SDL_SurfaceValid(dst)) {
+    }
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("dst");
-    } else if ((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
+    }
+    CHECK_PARAM((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
         return SDL_SetError("Surfaces must not be locked during blit");
     }
 
@@ -1127,11 +1129,13 @@ bool SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surfac
     SDL_Rect r_src, r_dst;
 
     // Make sure the surfaces aren't locked
-    if (!SDL_SurfaceValid(src) || !src->pixels) {
+    CHECK_PARAM(!SDL_SurfaceValid(src) || !src->pixels) {
         return SDL_InvalidParamError("src");
-    } else if (!SDL_SurfaceValid(dst) || !dst->pixels) {
+    }
+    CHECK_PARAM(!SDL_SurfaceValid(dst) || !dst->pixels) {
         return SDL_InvalidParamError("dst");
-    } else if ((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
+    }
+    CHECK_PARAM((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
         return SDL_SetError("Surfaces must not be locked during blit");
     }
 
@@ -1342,11 +1346,13 @@ bool SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface
     SDL_Rect r_src, r_dst;
 
     // Make sure the surfaces aren't locked
-    if (!SDL_SurfaceValid(src)) {
+    CHECK_PARAM(!SDL_SurfaceValid(src)) {
         return SDL_InvalidParamError("src");
-    } else if (!SDL_SurfaceValid(dst)) {
+    }
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("dst");
-    } else if ((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
+    }
+    CHECK_PARAM((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
         return SDL_SetError("Surfaces must not be locked during blit");
     }
 
@@ -1447,15 +1453,16 @@ bool SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, fl
     SDL_Rect r_src, r_dst;
 
     // Make sure the surfaces aren't locked
-    if (!SDL_SurfaceValid(src)) {
+    CHECK_PARAM(!SDL_SurfaceValid(src)) {
         return SDL_InvalidParamError("src");
-    } else if (!SDL_SurfaceValid(dst)) {
+    }
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("dst");
-    } else if ((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
+    }
+    CHECK_PARAM((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
         return SDL_SetError("Surfaces must not be locked during blit");
     }
-
-    if (scale <= 0.0f) {
+    CHECK_PARAM(scale <= 0.0f) {
         return SDL_InvalidParamError("scale");
     }
 
@@ -1565,9 +1572,10 @@ bool SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wi
     int dst_bottom_height;
 
     // Make sure the surfaces aren't locked
-    if (!SDL_SurfaceValid(src)) {
+    CHECK_PARAM(!SDL_SurfaceValid(src)) {
         return SDL_InvalidParamError("src");
-    } else if (!SDL_SurfaceValid(dst)) {
+    }
+    CHECK_PARAM(!SDL_SurfaceValid(dst)) {
         return SDL_InvalidParamError("dst");
     }
 
@@ -1698,7 +1706,7 @@ bool SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wi
  */
 bool SDL_LockSurface(SDL_Surface *surface)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -1816,7 +1824,7 @@ static bool SDL_FlipSurfaceVertical(SDL_Surface *surface)
 
 bool SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
     if (!surface->pixels) {
@@ -1857,12 +1865,12 @@ SDL_Surface *SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelForm
     Uint8 *palette_saved_alpha = NULL;
     int palette_saved_alpha_ncolors = 0;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         goto error;
     }
 
-    if (format == SDL_PIXELFORMAT_UNKNOWN) {
+    CHECK_PARAM(format == SDL_PIXELFORMAT_UNKNOWN) {
         SDL_InvalidParamError("format");
         goto error;
     }
@@ -2129,7 +2137,7 @@ error:
 
 SDL_Surface *SDL_DuplicateSurface(SDL_Surface *surface)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         return NULL;
     }
@@ -2144,7 +2152,7 @@ SDL_Surface *SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_S
     SDL_Color copy_color;
     bool rc;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         goto error;
     }
@@ -2221,7 +2229,7 @@ error:
 
 SDL_Surface *SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         return NULL;
     }
@@ -2258,16 +2266,16 @@ bool SDL_ConvertPixelsAndColorspace(int width, int height,
     void *nonconst_src = (void *)src;
     bool result;
 
-    if (!src) {
+    CHECK_PARAM(!src) {
         return SDL_InvalidParamError("src");
     }
-    if (!src_pitch) {
+    CHECK_PARAM(!src_pitch) {
         return SDL_InvalidParamError("src_pitch");
     }
-    if (!dst) {
+    CHECK_PARAM(!dst) {
         return SDL_InvalidParamError("dst");
     }
-    if (!dst_pitch) {
+    CHECK_PARAM(!dst_pitch) {
         return SDL_InvalidParamError("dst_pitch");
     }
 
@@ -2450,16 +2458,16 @@ static bool SDL_PremultiplyAlphaPixelsAndColorspace(int width, int height, SDL_P
     SDL_Colorspace colorspace;
     bool result = false;
 
-    if (!src) {
+    CHECK_PARAM(!src) {
         return SDL_InvalidParamError("src");
     }
-    if (!src_pitch) {
+    CHECK_PARAM(!src_pitch) {
         return SDL_InvalidParamError("src_pitch");
     }
-    if (!dst) {
+    CHECK_PARAM(!dst) {
         return SDL_InvalidParamError("dst");
     }
-    if (!dst_pitch) {
+    CHECK_PARAM(!dst_pitch) {
         return SDL_InvalidParamError("dst_pitch");
     }
 
@@ -2558,7 +2566,7 @@ bool SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, bool linear)
 {
     SDL_Colorspace colorspace;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -2572,7 +2580,7 @@ bool SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a)
     SDL_Rect clip_rect;
     bool result = false;
 
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -2632,7 +2640,7 @@ Uint32 SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
 
 Uint32 SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 {
-    if (!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
         SDL_InvalidParamError("surface");
         return true;
     }
@@ -2672,15 +2680,15 @@ bool SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g
         a = &unused;
     }
 
-    if (!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (x < 0 || x >= surface->w) {
+    CHECK_PARAM(x < 0 || x >= surface->w) {
         return SDL_InvalidParamError("x");
     }
 
-    if (y < 0 || y >= surface->h) {
+    CHECK_PARAM(y < 0 || y >= surface->h) {
         return SDL_InvalidParamError("y");
     }
 
@@ -2759,15 +2767,15 @@ bool SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, flo
         a = &unused;
     }
 
-    if (!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (x < 0 || x >= surface->w) {
+    CHECK_PARAM(x < 0 || x >= surface->w) {
         return SDL_InvalidParamError("x");
     }
 
-    if (y < 0 || y >= surface->h) {
+    CHECK_PARAM(y < 0 || y >= surface->h) {
         return SDL_InvalidParamError("y");
     }
 
@@ -2834,15 +2842,15 @@ bool SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g,
     Uint8 *p;
     bool result = false;
 
-    if (!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (x < 0 || x >= surface->w) {
+    CHECK_PARAM(x < 0 || x >= surface->w) {
         return SDL_InvalidParamError("x");
     }
 
-    if (y < 0 || y >= surface->h) {
+    CHECK_PARAM(y < 0 || y >= surface->h) {
         return SDL_InvalidParamError("y");
     }
 
@@ -2887,15 +2895,15 @@ bool SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, flo
 {
     bool result = false;
 
-    if (!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) {
         return SDL_InvalidParamError("surface");
     }
 
-    if (x < 0 || x >= surface->w) {
+    CHECK_PARAM(x < 0 || x >= surface->w) {
         return SDL_InvalidParamError("x");
     }
 
-    if (y < 0 || y >= surface->h) {
+    CHECK_PARAM(y < 0 || y >= surface->h) {
         return SDL_InvalidParamError("y");
     }
 

+ 36 - 37
src/video/SDL_video.c

@@ -157,22 +157,22 @@ static VideoBootStrap *bootstrap[] = {
 };
 
 #define CHECK_WINDOW_MAGIC(window, result)                              \
-    if (!_this) {                                                       \
+    CHECK_PARAM(!_this) {                                               \
         SDL_UninitializedVideo();                                       \
         return result;                                                  \
     }                                                                   \
-    if (!SDL_ObjectValid(window, SDL_OBJECT_TYPE_WINDOW)) {             \
+    CHECK_PARAM(!SDL_ObjectValid(window, SDL_OBJECT_TYPE_WINDOW)) {     \
         SDL_SetError("Invalid window");                                 \
         return result;                                                  \
     }
 
 #define CHECK_DISPLAY_MAGIC(display, result)                            \
-    if (!display) {                                                     \
+    CHECK_PARAM(!display) {                                             \
         return result;                                                  \
     }                                                                   \
 
 #define CHECK_WINDOW_NOT_POPUP(window, result)                          \
-    if (SDL_WINDOW_IS_POPUP(window)) {                                  \
+    CHECK_PARAM(SDL_WINDOW_IS_POPUP(window)) {                          \
         SDL_SetError("Operation invalid on popup windows");             \
         return result;                                                  \
     }
@@ -598,11 +598,11 @@ int SDL_GetNumVideoDrivers(void)
 
 const char *SDL_GetVideoDriver(int index)
 {
-    if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
-        return deduped_bootstrap[index]->name;
+    CHECK_PARAM(index < 0 || index >= SDL_GetNumVideoDrivers()) {
+        SDL_InvalidParamError("index");
+        return NULL;
     }
-    SDL_InvalidParamError("index");
-    return NULL;
+    return deduped_bootstrap[index]->name;
 }
 
 /*
@@ -1059,7 +1059,7 @@ bool SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect)
 
     CHECK_DISPLAY_MAGIC(display, false);
 
-    if (!rect) {
+    CHECK_PARAM(!rect) {
         return SDL_InvalidParamError("rect");
     }
 
@@ -1094,7 +1094,7 @@ bool SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect)
 
     CHECK_DISPLAY_MAGIC(display, false);
 
-    if (!rect) {
+    CHECK_PARAM(!rect) {
         return SDL_InvalidParamError("rect");
     }
 
@@ -1362,7 +1362,7 @@ SDL_DisplayMode **SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *co
 
 bool SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, bool include_high_density_modes, SDL_DisplayMode *result)
 {
-    if (!result) {
+    CHECK_PARAM(!result) {
         return SDL_InvalidParamError("closest"); // Parameter `result` is called `closest` in the header.
     }
 
@@ -1652,7 +1652,7 @@ void SDL_GlobalToRelativeForWindow(SDL_Window *window, int abs_x, int abs_y, int
 
 SDL_DisplayID SDL_GetDisplayForPoint(const SDL_Point *point)
 {
-    if (!point) {
+    CHECK_PARAM(!point) {
         SDL_InvalidParamError("point");
         return 0;
     }
@@ -1662,7 +1662,7 @@ SDL_DisplayID SDL_GetDisplayForPoint(const SDL_Point *point)
 
 SDL_DisplayID SDL_GetDisplayForRect(const SDL_Rect *rect)
 {
-    if (!rect) {
+    CHECK_PARAM(!rect) {
         SDL_InvalidParamError("rect");
         return 0;
     }
@@ -2924,7 +2924,7 @@ bool SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon)
 {
     CHECK_WINDOW_MAGIC(window, false);
 
-    if (!icon) {
+    CHECK_PARAM(!icon) {
         return SDL_InvalidParamError("icon");
     }
 
@@ -3118,10 +3118,10 @@ bool SDL_SetWindowSize(SDL_Window *window, int w, int h)
 {
     CHECK_WINDOW_MAGIC(window, false);
 
-    if (w <= 0) {
+    CHECK_PARAM(w <= 0) {
         return SDL_InvalidParamError("w");
     }
-    if (h <= 0) {
+    CHECK_PARAM(h <= 0) {
         return SDL_InvalidParamError("h");
     }
 
@@ -3266,15 +3266,14 @@ bool SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h)
 bool SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h)
 {
     CHECK_WINDOW_MAGIC(window, false);
-    if (min_w < 0) {
+    CHECK_PARAM(min_w < 0) {
         return SDL_InvalidParamError("min_w");
     }
-    if (min_h < 0) {
+    CHECK_PARAM(min_h < 0) {
         return SDL_InvalidParamError("min_h");
     }
 
-    if ((window->max_w && min_w > window->max_w) ||
-        (window->max_h && min_h > window->max_h)) {
+    CHECK_PARAM((window->max_w && min_w > window->max_w) || (window->max_h && min_h > window->max_h)) {
         return SDL_SetError("SDL_SetWindowMinimumSize(): Tried to set minimum size larger than maximum size");
     }
 
@@ -3308,10 +3307,10 @@ bool SDL_GetWindowMinimumSize(SDL_Window *window, int *min_w, int *min_h)
 bool SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h)
 {
     CHECK_WINDOW_MAGIC(window, false);
-    if (max_w < 0) {
+    CHECK_PARAM(max_w < 0) {
         return SDL_InvalidParamError("max_w");
     }
-    if (max_h < 0) {
+    CHECK_PARAM(max_h < 0) {
         return SDL_InvalidParamError("max_h");
     }
 
@@ -4092,7 +4091,7 @@ bool SDL_SetWindowProgressState(SDL_Window *window, SDL_ProgressState state)
     CHECK_WINDOW_MAGIC(window, false);
     CHECK_WINDOW_NOT_POPUP(window, false);
 
-    if (state < SDL_PROGRESS_STATE_NONE || state > SDL_PROGRESS_STATE_ERROR) {
+    CHECK_PARAM(state < SDL_PROGRESS_STATE_NONE || state > SDL_PROGRESS_STATE_ERROR) {
         return SDL_InvalidParamError("state");
     }
 
@@ -5048,7 +5047,7 @@ bool SDL_GL_GetAttribute(SDL_GLAttr attr, int *value)
     GLenum attachmentattrib = 0;
 #endif
 
-    if (!value) {
+    CHECK_PARAM(!value) {
         return SDL_InvalidParamError("value");
     }
 
@@ -5457,7 +5456,7 @@ bool SDL_GL_SetSwapInterval(int interval)
 
 bool SDL_GL_GetSwapInterval(int *interval)
 {
-    if (!interval) {
+    CHECK_PARAM(!interval) {
        return SDL_InvalidParamError("interval");
     }
 
@@ -5491,10 +5490,10 @@ bool SDL_GL_SwapWindow(SDL_Window *window)
 
 bool SDL_GL_DestroyContext(SDL_GLContext context)
 {
-    if (!_this) {
+    CHECK_PARAM(!_this) {
         return SDL_UninitializedVideo();
     }
-    if (!context) {
+    CHECK_PARAM(!context) {
         return SDL_InvalidParamError("context");
     }
 
@@ -5805,9 +5804,10 @@ bool SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
     SDL_Window *current_window;
     SDL_MessageBoxData mbdata;
 
-    if (!messageboxdata) {
+    CHECK_PARAM(!messageboxdata) {
         return SDL_InvalidParamError("messageboxdata");
-    } else if (messageboxdata->numbuttons < 0) {
+    }
+    CHECK_PARAM(messageboxdata->numbuttons < 0) {
         return SDL_SetError("Invalid number of buttons");
     }
 
@@ -6146,11 +6146,11 @@ bool SDL_Vulkan_CreateSurface(SDL_Window *window,
         return SDL_SetError(NOT_A_VULKAN_WINDOW);
     }
 
-    if (!instance) {
+    CHECK_PARAM(!instance) {
         return SDL_InvalidParamError("instance");
     }
 
-    if (!surface) {
+    CHECK_PARAM(!surface) {
         return SDL_InvalidParamError("surface");
     }
 
@@ -6170,17 +6170,17 @@ bool SDL_Vulkan_GetPresentationSupport(VkInstance instance,
                                            VkPhysicalDevice physicalDevice,
                                            Uint32 queueFamilyIndex)
 {
-    if (!_this) {
+    CHECK_PARAM(!_this) {
         SDL_UninitializedVideo();
         return false;
     }
 
-    if (!instance) {
+    CHECK_PARAM(!instance) {
         SDL_InvalidParamError("instance");
         return false;
     }
 
-    if (!physicalDevice) {
+    CHECK_PARAM(!physicalDevice) {
         SDL_InvalidParamError("physicalDevice");
         return false;
     }
@@ -6231,12 +6231,11 @@ void SDL_Metal_DestroyView(SDL_MetalView view)
 void *SDL_Metal_GetLayer(SDL_MetalView view)
 {
     if (_this && _this->Metal_GetLayer) {
-        if (view) {
-            return _this->Metal_GetLayer(_this, view);
-        } else {
+        CHECK_PARAM(!view) {
             SDL_InvalidParamError("view");
             return NULL;
         }
+        return _this->Metal_GetLayer(_this, view);
     } else {
         SDL_SetError("Metal is not supported.");
         return NULL;

+ 3 - 3
src/video/windows/SDL_windowsvideo.c

@@ -70,7 +70,7 @@ typedef enum THUMBBUTTONFLAGS
     THBF_HIDDEN = 0x8,
     THBF_NONINTERACTIVE = 0x10
 } THUMBBUTTONFLAGS;
- 
+
 #if defined(_MSC_VER)
 #pragma warning(disable: 4103)
 #endif
@@ -801,11 +801,11 @@ bool SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outp
     IDXGIAdapter *pDXGIAdapter;
     IDXGIOutput *pDXGIOutput;
 
-    if (!adapterIndex) {
+    CHECK_PARAM(!adapterIndex) {
         return SDL_InvalidParamError("adapterIndex");
     }
 
-    if (!outputIndex) {
+    CHECK_PARAM(!outputIndex) {
         return SDL_InvalidParamError("outputIndex");
     }
 

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików