Skip to content

Commit 25b2d2c

Browse files
committed
Use new parameter validation macro
1 parent ee1c90a commit 25b2d2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1109
-1129
lines changed

src/SDL.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static bool SDL_ValidMetadataProperty(const char *name)
148148

149149
bool SDL_SetAppMetadataProperty(const char *name, const char *value)
150150
{
151-
if (!SDL_ValidMetadataProperty(name)) {
151+
CHECK_PARAM(!SDL_ValidMetadataProperty(name)) {
152152
return SDL_InvalidParamError("name");
153153
}
154154

@@ -157,7 +157,7 @@ bool SDL_SetAppMetadataProperty(const char *name, const char *value)
157157

158158
const char *SDL_GetAppMetadataProperty(const char *name)
159159
{
160-
if (!SDL_ValidMetadataProperty(name)) {
160+
CHECK_PARAM(!SDL_ValidMetadataProperty(name)) {
161161
SDL_InvalidParamError("name");
162162
return NULL;
163163
}

src/SDL_hashtable.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static bool maybe_resize(SDL_HashTable *ht)
292292

293293
bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value, bool replace)
294294
{
295-
if (!table) {
295+
CHECK_PARAM(!table) {
296296
return SDL_InvalidParamError("table");
297297
}
298298

@@ -338,7 +338,7 @@ bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *
338338

339339
bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **value)
340340
{
341-
if (!table) {
341+
CHECK_PARAM(!table) {
342342
if (value) {
343343
*value = NULL;
344344
}
@@ -364,7 +364,7 @@ bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void
364364

365365
bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
366366
{
367-
if (!table) {
367+
CHECK_PARAM(!table) {
368368
return SDL_InvalidParamError("table");
369369
}
370370

@@ -384,9 +384,10 @@ bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
384384

385385
bool SDL_IterateHashTable(const SDL_HashTable *table, SDL_HashTableIterateCallback callback, void *userdata)
386386
{
387-
if (!table) {
387+
CHECK_PARAM(!table) {
388388
return SDL_InvalidParamError("table");
389-
} else if (!callback) {
389+
}
390+
CHECK_PARAM(!callback) {
390391
return SDL_InvalidParamError("callback");
391392
}
392393

@@ -410,7 +411,7 @@ bool SDL_IterateHashTable(const SDL_HashTable *table, SDL_HashTableIterateCallba
410411

411412
bool SDL_HashTableEmpty(SDL_HashTable *table)
412413
{
413-
if (!table) {
414+
CHECK_PARAM(!table) {
414415
return SDL_InvalidParamError("table");
415416
}
416417

src/SDL_hints.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static const char *GetHintEnvironmentVariable(const char *name)
104104

105105
bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority)
106106
{
107-
if (!name || !*name) {
107+
CHECK_PARAM(!name || !*name) {
108108
return SDL_InvalidParamError("name");
109109
}
110110

@@ -165,7 +165,7 @@ bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriori
165165

166166
bool SDL_ResetHint(const char *name)
167167
{
168-
if (!name || !*name) {
168+
CHECK_PARAM(!name || !*name) {
169169
return SDL_InvalidParamError("name");
170170
}
171171

@@ -316,9 +316,10 @@ bool SDL_GetHintBoolean(const char *name, bool default_value)
316316

317317
bool SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
318318
{
319-
if (!name || !*name) {
319+
CHECK_PARAM(!name || !*name) {
320320
return SDL_InvalidParamError("name");
321-
} else if (!callback) {
321+
}
322+
CHECK_PARAM(!callback) {
322323
return SDL_InvalidParamError("callback");
323324
}
324325

src/SDL_log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ bool SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix)
461461
{
462462
char *prefix_copy;
463463

464-
if (priority <= SDL_LOG_PRIORITY_INVALID || priority >= SDL_LOG_PRIORITY_COUNT) {
464+
CHECK_PARAM(priority <= SDL_LOG_PRIORITY_INVALID || priority >= SDL_LOG_PRIORITY_COUNT) {
465465
return SDL_InvalidParamError("priority");
466466
}
467467

src/SDL_properties.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,22 @@ static bool SDLCALL CopyOneProperty(void *userdata, const SDL_HashTable *table,
250250

251251
bool SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst)
252252
{
253-
if (!src) {
253+
CHECK_PARAM(!src) {
254254
return SDL_InvalidParamError("src");
255255
}
256-
if (!dst) {
256+
CHECK_PARAM(!dst) {
257257
return SDL_InvalidParamError("dst");
258258
}
259259

260260
SDL_Properties *src_properties = NULL;
261261
SDL_Properties *dst_properties = NULL;
262262

263263
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)src, (const void **)&src_properties);
264-
if (!src_properties) {
264+
CHECK_PARAM(!src_properties) {
265265
return SDL_InvalidParamError("src");
266266
}
267267
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)dst, (const void **)&dst_properties);
268-
if (!dst_properties) {
268+
CHECK_PARAM(!dst_properties) {
269269
return SDL_InvalidParamError("dst");
270270
}
271271

@@ -287,12 +287,12 @@ bool SDL_LockProperties(SDL_PropertiesID props)
287287
{
288288
SDL_Properties *properties = NULL;
289289

290-
if (!props) {
290+
CHECK_PARAM(!props) {
291291
return SDL_InvalidParamError("props");
292292
}
293293

294294
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
295-
if (!properties) {
295+
CHECK_PARAM(!properties) {
296296
return SDL_InvalidParamError("props");
297297
}
298298

@@ -321,17 +321,17 @@ static bool SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL
321321
SDL_Properties *properties = NULL;
322322
bool result = true;
323323

324-
if (!props) {
324+
CHECK_PARAM(!props) {
325325
SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
326326
return SDL_InvalidParamError("props");
327327
}
328-
if (!name || !*name) {
328+
CHECK_PARAM(!name || !*name) {
329329
SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
330330
return SDL_InvalidParamError("name");
331331
}
332332

333333
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
334-
if (!properties) {
334+
CHECK_PARAM(!properties) {
335335
SDL_FreePropertyWithCleanup(NULL, property, NULL, true);
336336
return SDL_InvalidParamError("props");
337337
}
@@ -755,15 +755,15 @@ bool SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCall
755755
{
756756
SDL_Properties *properties = NULL;
757757

758-
if (!props) {
758+
CHECK_PARAM(!props) {
759759
return SDL_InvalidParamError("props");
760760
}
761-
if (!callback) {
761+
CHECK_PARAM(!callback) {
762762
return SDL_InvalidParamError("callback");
763763
}
764764

765765
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
766-
if (!properties) {
766+
CHECK_PARAM(!properties) {
767767
return SDL_InvalidParamError("props");
768768
}
769769

src/audio/SDL_audio.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ int SDL_GetNumAudioDrivers(void)
136136

137137
const char *SDL_GetAudioDriver(int index)
138138
{
139-
if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
140-
return deduped_bootstrap[index]->name;
139+
CHECK_PARAM(index < 0 || index >= SDL_GetNumAudioDrivers()) {
140+
SDL_InvalidParamError("index");
141+
return NULL;
141142
}
142-
SDL_InvalidParamError("index");
143-
return NULL;
143+
return deduped_bootstrap[index]->name;
144144
}
145145

146146
const char *SDL_GetCurrentAudioDriver(void)
@@ -1576,7 +1576,7 @@ const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
15761576

15771577
bool SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames)
15781578
{
1579-
if (!spec) {
1579+
CHECK_PARAM(!spec) {
15801580
return SDL_InvalidParamError("spec");
15811581
}
15821582

@@ -1937,7 +1937,7 @@ float SDL_GetAudioDeviceGain(SDL_AudioDeviceID devid)
19371937

19381938
bool SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain)
19391939
{
1940-
if (gain < 0.0f) {
1940+
CHECK_PARAM(gain < 0.0f) {
19411941
return SDL_InvalidParamError("gain");
19421942
}
19431943

@@ -1986,11 +1986,15 @@ bool SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream * const *stre
19861986

19871987
if (num_streams == 0) {
19881988
return true; // nothing to do
1989-
} else if (num_streams < 0) {
1989+
}
1990+
1991+
CHECK_PARAM(num_streams < 0) {
19901992
return SDL_InvalidParamError("num_streams");
1991-
} else if (!streams) {
1993+
}
1994+
CHECK_PARAM(!streams) {
19921995
return SDL_InvalidParamError("streams");
1993-
} else if (SDL_IsAudioDevicePhysical(devid)) {
1996+
}
1997+
CHECK_PARAM(SDL_IsAudioDevicePhysical(devid)) {
19941998
return SDL_SetError("Audio streams are bound to device ids from SDL_OpenAudioDevice, not raw physical devices");
19951999
}
19962000

@@ -2150,7 +2154,7 @@ SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream *stream)
21502154
{
21512155
SDL_AudioDeviceID result = 0;
21522156

2153-
if (!stream) {
2157+
CHECK_PARAM(!stream) {
21542158
SDL_InvalidParamError("stream");
21552159
return 0;
21562160
}

0 commit comments

Comments
 (0)