diff --git a/VisualC-GDK/tests/testgdk/src/testgdk.cpp b/VisualC-GDK/tests/testgdk/src/testgdk.cpp index ed69ecbeab..8395c8bb1c 100644 --- a/VisualC-GDK/tests/testgdk/src/testgdk.cpp +++ b/VisualC-GDK/tests/testgdk/src/testgdk.cpp @@ -239,17 +239,17 @@ LoadSprite(const char *file) /* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */ sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h); if (!sprites[i]) { - return (-1); + return -1; } if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError()); SDL_DestroyTexture(sprites[i]); - return (-1); + return -1; } } /* We're ready to roll. :) */ - return (0); + return 0; } void @@ -364,8 +364,9 @@ loop() #endif } for (i = 0; i < state->num_windows; ++i) { - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } DrawSprites(state->renderers[i], sprites[i]); } } @@ -382,7 +383,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO); - if (!state) { + if (state == NULL) { return 1; } @@ -445,7 +446,7 @@ main(int argc, char *argv[]) /* Create the windows, initialize the renderers, and load the textures */ sprites = (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites)); - if (!sprites) { + if (sprites == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } diff --git a/Xcode-iOS/Demos/src/accelerometer.c b/Xcode-iOS/Demos/src/accelerometer.c index 0af153676b..3ce8125134 100644 --- a/Xcode-iOS/Demos/src/accelerometer.c +++ b/Xcode-iOS/Demos/src/accelerometer.c @@ -127,7 +127,7 @@ initializeTextures(SDL_Renderer *renderer) /* create ship texture from surface */ ship = SDL_CreateTextureFromSurface(renderer, bmp_surface); - if (!ship) { + if (ship == NULL) { fatalError("could not create ship texture"); } SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND); @@ -145,7 +145,7 @@ initializeTextures(SDL_Renderer *renderer) } /* create space texture from surface */ space = SDL_CreateTextureFromSurface(renderer, bmp_surface); - if (!space) { + if (space == NULL) { fatalError("could not create space texture"); } SDL_FreeSurface(bmp_surface); diff --git a/Xcode-iOS/Demos/src/fireworks.c b/Xcode-iOS/Demos/src/fireworks.c index 600d20bbb4..eb3bb4cdee 100644 --- a/Xcode-iOS/Demos/src/fireworks.c +++ b/Xcode-iOS/Demos/src/fireworks.c @@ -84,14 +84,16 @@ stepParticles(double deltaTime) /* is the particle actually active, or is it marked for deletion? */ if (curr->isActive) { /* is the particle off the screen? */ - if (curr->y > screen_h) + if (curr->y > screen_h) { curr->isActive = 0; - else if (curr->y < 0) + } else if (curr->y < 0) { curr->isActive = 0; - if (curr->x > screen_w) + } + if (curr->x > screen_w) { curr->isActive = 0; - else if (curr->x < 0) + } else if (curr->x < 0) { curr->isActive = 0; + } /* step velocity, then step position */ curr->yvel += ACCEL * deltaMilliseconds; @@ -133,15 +135,17 @@ stepParticles(double deltaTime) } /* if we're a dust particle, shrink our size */ - if (curr->type == dust) + if (curr->type == dust) { curr->size -= deltaMilliseconds * 0.010f; + } } /* if we're still active, pack ourselves in the array next to the last active guy (pack the array tightly) */ - if (curr->isActive) + if (curr->isActive) { *(slot++) = *curr; + } } /* endif (curr->isActive) */ curr++; } @@ -188,8 +192,9 @@ explodeEmitter(struct particle *emitter) int i; for (i = 0; i < 200; i++) { - if (num_active_particles >= MAX_PARTICLES) + if (num_active_particles >= MAX_PARTICLES) { return; + } /* come up with a random angle and speed for new particle */ float theta = randomFloat(0, 2.0f * 3.141592); @@ -226,8 +231,9 @@ void spawnTrailFromEmitter(struct particle *emitter) { - if (num_active_particles >= MAX_PARTICLES) + if (num_active_particles >= MAX_PARTICLES) { return; + } /* select the particle at the slot at the end of our array */ struct particle *p = &particles[num_active_particles]; @@ -262,8 +268,9 @@ void spawnEmitterParticle(GLfloat x, GLfloat y) { - if (num_active_particles >= MAX_PARTICLES) + if (num_active_particles >= MAX_PARTICLES) { return; + } /* find particle at endpoint of array */ struct particle *p = &particles[num_active_particles]; diff --git a/Xcode-iOS/Demos/src/happy.c b/Xcode-iOS/Demos/src/happy.c index 73d4d4feb3..42562007e1 100644 --- a/Xcode-iOS/Demos/src/happy.c +++ b/Xcode-iOS/Demos/src/happy.c @@ -117,7 +117,7 @@ initializeTexture(SDL_Renderer *renderer) /* convert RGBA surface to texture */ texture = SDL_CreateTextureFromSurface(renderer, bmp_surface); - if (!texture) { + if (texture == NULL) { fatalError("could not create texture"); } SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); diff --git a/Xcode-iOS/Demos/src/keyboard.c b/Xcode-iOS/Demos/src/keyboard.c index 4d630bae5f..6ab1db213a 100644 --- a/Xcode-iOS/Demos/src/keyboard.c +++ b/Xcode-iOS/Demos/src/keyboard.c @@ -165,7 +165,7 @@ loadFont(void) { SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp"); - if (!surface) { + if (surface == NULL) { printf("Error loading bitmap: %s\n", SDL_GetError()); return 0; } else { @@ -183,7 +183,7 @@ loadFont(void) SDL_BlitSurface(surface, NULL, converted, NULL); /* create our texture */ texture = SDL_CreateTextureFromSurface(renderer, converted); - if (!texture) { + if (texture == NULL) { printf("texture creation failed: %s\n", SDL_GetError()); } else { /* set blend mode for our texture */ diff --git a/Xcode-iOS/Demos/src/mixer.c b/Xcode-iOS/Demos/src/mixer.c index 18e33f134c..4c4ffbad08 100644 --- a/Xcode-iOS/Demos/src/mixer.c +++ b/Xcode-iOS/Demos/src/mixer.c @@ -207,9 +207,9 @@ playSound(struct sound *s) break; } /* if this channel's sound is older than the oldest so far, set it to oldest */ - if (mixer.channels[i].timestamp < - mixer.channels[oldest_channel].timestamp) + if (mixer.channels[i].timestamp < mixer.channels[oldest_channel].timestamp) { oldest_channel = i; + } } /* no empty channels, take the oldest one */ diff --git a/Xcode-iOS/Demos/src/rectangles.c b/Xcode-iOS/Demos/src/rectangles.c index a08f997906..9102cf2795 100644 --- a/Xcode-iOS/Demos/src/rectangles.c +++ b/Xcode-iOS/Demos/src/rectangles.c @@ -58,11 +58,11 @@ main(int argc, char *argv[]) /* create window and renderer */ window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI); - if (!window) { + if (window == NULL) { fatalError("Could not initialize Window"); } renderer = SDL_CreateRenderer(window, -1, 0); - if (!renderer) { + if (renderer == NULL) { fatalError("Could not create renderer"); } diff --git a/Xcode-iOS/Demos/src/touch.c b/Xcode-iOS/Demos/src/touch.c index 6c184630da..22a251be14 100644 --- a/Xcode-iOS/Demos/src/touch.c +++ b/Xcode-iOS/Demos/src/touch.c @@ -63,7 +63,7 @@ initializeTexture(SDL_Renderer *renderer) brush = SDL_CreateTextureFromSurface(renderer, bmp_surface); SDL_FreeSurface(bmp_surface); - if (!brush) { + if (brush == NULL) { fatalError("could not create brush texture"); } /* additive blending -- laying strokes on top of eachother makes them brighter */ diff --git a/src/SDL.c b/src/SDL.c index de01776eca..1a6800a472 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -216,7 +216,7 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the timer subsystem */ - if ((flags & SDL_INIT_TIMER)){ + if ((flags & SDL_INIT_TIMER)) { #if !SDL_TIMERS_DISABLED && !SDL_TIMER_DUMMY if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) { if (SDL_TimerInit() < 0) { @@ -232,7 +232,7 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the video subsystem */ - if ((flags & SDL_INIT_VIDEO)){ + if ((flags & SDL_INIT_VIDEO)) { #if !SDL_VIDEO_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) { if (SDL_VideoInit(NULL) < 0) { @@ -248,7 +248,7 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the audio subsystem */ - if ((flags & SDL_INIT_AUDIO)){ + if ((flags & SDL_INIT_AUDIO)) { #if !SDL_AUDIO_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) { if (SDL_AudioInit(NULL) < 0) { @@ -264,7 +264,7 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the joystick subsystem */ - if ((flags & SDL_INIT_JOYSTICK)){ + if ((flags & SDL_INIT_JOYSTICK)) { #if !SDL_JOYSTICK_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) { if (SDL_JoystickInit() < 0) { @@ -279,7 +279,7 @@ SDL_InitSubSystem(Uint32 flags) #endif } - if ((flags & SDL_INIT_GAMECONTROLLER)){ + if ((flags & SDL_INIT_GAMECONTROLLER)) { #if !SDL_JOYSTICK_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) { if (SDL_GameControllerInit() < 0) { @@ -295,7 +295,7 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the haptic subsystem */ - if ((flags & SDL_INIT_HAPTIC)){ + if ((flags & SDL_INIT_HAPTIC)) { #if !SDL_HAPTIC_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) { if (SDL_HapticInit() < 0) { @@ -311,7 +311,7 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the sensor subsystem */ - if ((flags & SDL_INIT_SENSOR)){ + if ((flags & SDL_INIT_SENSOR)) { #if !SDL_SENSOR_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) { if (SDL_SensorInit() < 0) { @@ -328,11 +328,11 @@ SDL_InitSubSystem(Uint32 flags) (void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */ - return (0); + return 0; quit_and_error: SDL_QuitSubSystem(flags_initialized); - return (-1); + return -1; } int @@ -500,8 +500,7 @@ SDL_GetVersion(SDL_version * ver) static SDL_bool check_hint = SDL_TRUE; static SDL_bool legacy_version = SDL_FALSE; - if (!ver) { - return; + if (ver == NULL) { return; } SDL_VERSION(ver); diff --git a/src/SDL_assert.c b/src/SDL_assert.c index 4bde1d8dce..07642ba896 100644 --- a/src/SDL_assert.c +++ b/src/SDL_assert.c @@ -244,10 +244,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata) } else { state = (SDL_assert_state)selected; } - } - - else - { + } else { #if defined(__EMSCRIPTEN__) /* This is nasty, but we can't block on a custom UI. */ for ( ; ; ) { diff --git a/src/SDL_dataqueue.c b/src/SDL_dataqueue.c index 46301c188b..08e2b3e388 100644 --- a/src/SDL_dataqueue.c +++ b/src/SDL_dataqueue.c @@ -57,7 +57,7 @@ SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack) { SDL_DataQueue *queue = (SDL_DataQueue *) SDL_malloc(sizeof (SDL_DataQueue)); - if (!queue) { + if (queue == NULL) { SDL_OutOfMemory(); return NULL; } else { @@ -101,7 +101,7 @@ SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack) SDL_DataQueuePacket *prev = NULL; size_t i; - if (!queue) { + if (queue == NULL) { return; } @@ -180,7 +180,7 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len) size_t origlen; size_t datalen; - if (!queue) { + if (queue == NULL) { return SDL_InvalidParamError("queue"); } @@ -190,13 +190,13 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len) while (len > 0) { SDL_DataQueuePacket *packet = queue->tail; - SDL_assert(!packet || (packet->datalen <= packet_size)); - if (!packet || (packet->datalen >= packet_size)) { + SDL_assert(packet == NULL || (packet->datalen <= packet_size)); + if (packet == NULL || (packet->datalen >= packet_size)) { /* tail packet missing or completely full; we need a new packet. */ packet = AllocateDataQueuePacket(queue); - if (!packet) { + if (packet == NULL) { /* uhoh, reset so we've queued nothing new, free what we can. */ - if (!origtail) { + if (origtail == NULL) { packet = queue->head; /* whole queue. */ } else { packet = origtail->next; /* what we added to existing queue. */ @@ -231,7 +231,7 @@ SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len) Uint8 *ptr = buf; SDL_DataQueuePacket *packet; - if (!queue) { + if (queue == NULL) { return 0; } @@ -256,7 +256,7 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len) Uint8 *ptr = buf; SDL_DataQueuePacket *packet; - if (!queue) { + if (queue == NULL) { return 0; } @@ -299,7 +299,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len) { SDL_DataQueuePacket *packet; - if (!queue) { + if (queue == NULL) { SDL_InvalidParamError("queue"); return NULL; } else if (len == 0) { @@ -323,7 +323,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len) /* Need a fresh packet. */ packet = AllocateDataQueuePacket(queue); - if (!packet) { + if (packet == NULL) { SDL_OutOfMemory(); return NULL; } diff --git a/src/SDL_guid.c b/src/SDL_guid.c index 6bb892d11e..bcd75ebf22 100644 --- a/src/SDL_guid.c +++ b/src/SDL_guid.c @@ -51,15 +51,15 @@ void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID) static unsigned char nibble(unsigned char c) { if ((c >= '0') && (c <= '9')) { - return (c - '0'); + return c - '0'; } if ((c >= 'A') && (c <= 'F')) { - return (c - 'A' + 0x0a); + return c - 'A' + 0x0a; } if ((c >= 'a') && (c <= 'f')) { - return (c - 'a' + 0x0a); + return c - 'a' + 0x0a; } /* received an invalid character, and no real way to return an error */ diff --git a/src/SDL_hints.c b/src/SDL_hints.c index 9e2073f74e..1e800cef7b 100644 --- a/src/SDL_hints.c +++ b/src/SDL_hints.c @@ -50,7 +50,7 @@ SDL_SetHintWithPriority(const char *name, const char *value, SDL_Hint *hint; SDL_HintWatch *entry; - if (!name) { + if (name == NULL) { return SDL_FALSE; } @@ -65,7 +65,7 @@ SDL_SetHintWithPriority(const char *name, const char *value, return SDL_FALSE; } if (hint->value != value && - (!value || !hint->value || SDL_strcmp(hint->value, value) != 0)) { + (value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) { for (entry = hint->callbacks; entry; ) { /* Save the next entry in case this one is deleted */ SDL_HintWatch *next = entry->next; @@ -82,7 +82,7 @@ SDL_SetHintWithPriority(const char *name, const char *value, /* Couldn't find the hint, add a new one */ hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); - if (!hint) { + if (hint == NULL) { return SDL_FALSE; } hint->name = SDL_strdup(name); @@ -101,7 +101,7 @@ SDL_ResetHint(const char *name) SDL_Hint *hint; SDL_HintWatch *entry; - if (!name) { + if (name == NULL) { return SDL_FALSE; } @@ -179,7 +179,7 @@ SDL_GetHint(const char *name) SDL_bool SDL_GetStringBoolean(const char *value, SDL_bool default_value) { - if (!value || !*value) { + if (value == NULL || !*value) { return default_value; } if (*value == '0' || SDL_strcasecmp(value, "false") == 0) { @@ -202,7 +202,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata) SDL_HintWatch *entry; const char *value; - if (!name || !*name) { + if (name == NULL || !*name) { SDL_InvalidParamError("name"); return; } @@ -214,7 +214,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata) SDL_DelHintCallback(name, callback, userdata); entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry)); - if (!entry) { + if (entry == NULL) { SDL_OutOfMemory(); return; } @@ -226,10 +226,10 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata) break; } } - if (!hint) { + if (hint == NULL) { /* Need to add a hint entry for this watcher */ hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); - if (!hint) { + if (hint == NULL) { SDL_OutOfMemory(); SDL_free(entry); return; diff --git a/src/SDL_log.c b/src/SDL_log.c index 80ac7666d4..f49f863bb0 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -105,7 +105,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = { void SDL_LogInit(void) { - if (!log_function_mutex) { + if (log_function_mutex == NULL) { /* if this fails we'll try to continue without it. */ log_function_mutex = SDL_CreateMutex(); } @@ -313,7 +313,7 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list return; } - if (!log_function_mutex) { + if (log_function_mutex == NULL) { /* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */ log_function_mutex = SDL_CreateMutex(); } @@ -323,15 +323,17 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list len = SDL_vsnprintf(stack_buf, sizeof(stack_buf), fmt, aq); va_end(aq); - if (len < 0) + if (len < 0) { return; + } /* If message truncated, allocate and re-render */ if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) { /* Allocate exactly what we need, including the zero-terminator */ message = (char *)SDL_malloc(len_plus_term); - if (!message) + if (message == NULL) { return; + } va_copy(aq, ap); len = SDL_vsnprintf(message, len_plus_term, fmt, aq); va_end(aq); diff --git a/src/atomic/SDL_atomic.c b/src/atomic/SDL_atomic.c index 70c6709e3d..4106d29caa 100644 --- a/src/atomic/SDL_atomic.c +++ b/src/atomic/SDL_atomic.c @@ -128,15 +128,15 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval) { #ifdef HAVE_MSC_ATOMICS SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(long) == sizeof(a->value)); - return (_InterlockedCompareExchange((long*)&a->value, (long)newval, (long)oldval) == (long)oldval); + return _InterlockedCompareExchange((long *)&a->value, (long)newval, (long)oldval) == (long)oldval; #elif defined(HAVE_WATCOM_ATOMICS) - return (SDL_bool) _SDL_cmpxchg_watcom(&a->value, newval, oldval); + return (SDL_bool)_SDL_cmpxchg_watcom(&a->value, newval, oldval); #elif defined(HAVE_GCC_ATOMICS) return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval); -#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ +#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value); #elif defined(__SOLARIS__) - return (SDL_bool) ((int) atomic_cas_uint((volatile uint_t*)&a->value, (uint_t)oldval, (uint_t)newval) == oldval); + return (SDL_bool)((int)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval); #elif EMULATE_CAS SDL_bool retval = SDL_FALSE; @@ -157,17 +157,17 @@ SDL_bool SDL_AtomicCASPtr(void **a, void *oldval, void *newval) { #if defined(HAVE_MSC_ATOMICS) - return (_InterlockedCompareExchangePointer(a, newval, oldval) == oldval); + return _InterlockedCompareExchangePointer(a, newval, oldval) == oldval; #elif defined(HAVE_WATCOM_ATOMICS) - return (SDL_bool) _SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval); + return (SDL_bool)_SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval); #elif defined(HAVE_GCC_ATOMICS) return __sync_bool_compare_and_swap(a, oldval, newval); -#elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ +#elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ return (SDL_bool) OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t*) a); -#elif defined(__MACOS__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ +#elif defined(__MACOS__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a); #elif defined(__SOLARIS__) - return (SDL_bool) (atomic_cas_ptr(a, oldval, newval) == oldval); + return (SDL_bool)(atomic_cas_ptr(a, oldval, newval) == oldval); #elif EMULATE_CAS SDL_bool retval = SDL_FALSE; @@ -189,13 +189,13 @@ SDL_AtomicSet(SDL_atomic_t *a, int v) { #ifdef HAVE_MSC_ATOMICS SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value)); - return _InterlockedExchange((long*)&a->value, v); + return _InterlockedExchange((long *)&a->value, v); #elif defined(HAVE_WATCOM_ATOMICS) return _SDL_xchg_watcom(&a->value, v); #elif defined(HAVE_GCC_ATOMICS) return __sync_lock_test_and_set(&a->value, v); #elif defined(__SOLARIS__) - return (int) atomic_swap_uint((volatile uint_t*)&a->value, v); + return (int)atomic_swap_uint((volatile uint_t *)&a->value, v); #else int value; do { @@ -211,7 +211,7 @@ SDL_AtomicSetPtr(void **a, void *v) #if defined(HAVE_MSC_ATOMICS) return _InterlockedExchangePointer(a, v); #elif defined(HAVE_WATCOM_ATOMICS) - return (void *) _SDL_xchg_watcom((int *)a, (long)v); + return (void *)_SDL_xchg_watcom((int *)a, (long)v); #elif defined(HAVE_GCC_ATOMICS) return __sync_lock_test_and_set(a, v); #elif defined(__SOLARIS__) @@ -230,7 +230,7 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v) { #ifdef HAVE_MSC_ATOMICS SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value)); - return _InterlockedExchangeAdd((long*)&a->value, v); + return _InterlockedExchangeAdd((long *)&a->value, v); #elif defined(HAVE_WATCOM_ATOMICS) return _SDL_xadd_watcom(&a->value, v); #elif defined(HAVE_GCC_ATOMICS) @@ -261,7 +261,7 @@ SDL_AtomicGet(SDL_atomic_t *a) return _SDL_xadd_watcom(&a->value, 0); #elif defined(HAVE_GCC_ATOMICS) return __sync_or_and_fetch(&a->value, 0); -#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ +#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ return sizeof(a->value) == sizeof(uint32_t) ? OSAtomicOr32Barrier(0, (volatile uint32_t *)&a->value) : OSAtomicAdd64Barrier(0, (volatile int64_t *)&a->value); #elif defined(__SOLARIS__) return atomic_or_uint((volatile uint_t *)&a->value, 0); diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index 4ea699486c..3c273bf9ba 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -63,7 +63,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) /* Terrible terrible damage */ static SDL_mutex *_spinlock_mutex; - if (!_spinlock_mutex) { + if (_spinlock_mutex == NULL) { /* Race condition on first lock... */ _spinlock_mutex = SDL_CreateMutex(); } @@ -78,14 +78,14 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) } #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET - return (__sync_lock_test_and_set(lock, 1) == 0); + return __sync_lock_test_and_set(lock, 1) == 0; #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)) - return (_InterlockedExchange_acq(lock, 1) == 0); + return _InterlockedExchange_acq(lock, 1) == 0; #elif defined(_MSC_VER) SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); - return (InterlockedExchange((long*)lock, 1) == 0); + return InterlockedExchange((long *)lock, 1) == 0; #elif defined(__WATCOMC__) && defined(__386__) return _SDL_xchg_watcom(lock, 1) == 0; @@ -102,28 +102,28 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) __asm__ __volatile__ ( "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); - return (result == 0); + return result == 0; } #endif __asm__ __volatile__ ( "swp %0, %1, [%2]\n" : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory"); - return (result == 0); + return result == 0; #elif defined(__GNUC__) && defined(__arm__) int result; __asm__ __volatile__ ( "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); - return (result == 0); + return result == 0; #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) int result; __asm__ __volatile__( "lock ; xchgl %0, (%1)\n" : "=r" (result) : "r" (lock), "0" (1) : "cc", "memory"); - return (result == 0); + return result == 0; #elif defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__) /* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */ @@ -131,11 +131,11 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) #elif defined(__SOLARIS__) && defined(_LP64) /* Used for Solaris with non-gcc compilers. */ - return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)lock, 0, 1) == 0); + return (SDL_bool)((int)atomic_cas_64((volatile uint64_t *)lock, 0, 1) == 0); #elif defined(__SOLARIS__) && !defined(_LP64) /* Used for Solaris with non-gcc compilers. */ - return (SDL_bool) ((int) atomic_cas_32((volatile uint32_t*)lock, 0, 1) == 0); + return (SDL_bool)((int)atomic_cas_32((volatile uint32_t *)lock, 0, 1) == 0); #elif defined(PS2) uint32_t oldintr; SDL_bool res = SDL_FALSE; @@ -147,7 +147,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) res = SDL_TRUE; } // enable interuption - if(oldintr) { EIntr(); } + if (oldintr) { EIntr(); } return res; #else #error Please implement for your platform. diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 3054ac0905..9eec4e55ed 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -509,11 +509,9 @@ SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle) } else { mark_device_removed(handle, current_audio.outputDevices, ¤t_audio.outputDevicesRemoved); } - for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++) - { + for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++) { device = open_devices[device_index]; - if (device != NULL && device->handle == handle) - { + if (device != NULL && device->handle == handle) { device_was_opened = SDL_TRUE; SDL_OpenedAudioDeviceDisconnected(device); break; @@ -977,7 +975,7 @@ SDL_AudioInit(const char *driver_name) } } else { for (i = 0; (!initialized) && (bootstrap[i]); ++i) { - if(bootstrap[i]->demand_only) { + if (bootstrap[i]->demand_only) { continue; } diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index 73df288c39..8ca5fa99f2 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -180,7 +180,7 @@ ResamplerPadding(const int inrate, const int outrate) return 0; } if (inrate > outrate) { - return (int) SDL_ceilf(((float) (RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float) outrate))); + return (int)SDL_ceilf(((float)(RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float)outrate))); } return RESAMPLER_SAMPLES_PER_ZERO_CROSSING; } @@ -246,7 +246,7 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate, outtime = outtimeincr * i; } - return outframes * chans * sizeof (float); + return outframes * chans * sizeof(float); } int @@ -485,7 +485,7 @@ SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format /* we keep no streaming state here, so pad with silence on both ends. */ padding = (float *) SDL_calloc(paddingsamples ? paddingsamples : 1, sizeof (float)); - if (!padding) { + if (padding == NULL) { SDL_OutOfMemory(); return; } @@ -583,7 +583,7 @@ SDL_BuildAudioResampleCVT(SDL_AudioCVT * cvt, const int dst_channels, !!! FIXME in 2.1: We need to store data for this resampler, because the cvt structure doesn't store the original sample rates, !!! FIXME in 2.1: so we steal the ninth and tenth slot. :( */ if (cvt->filter_index >= (SDL_AUDIOCVT_MAX_FILTERS-2)) { - return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS-2); + return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS - 2); } cvt->filters[SDL_AUDIOCVT_MAX_FILTERS-1] = (SDL_AudioFilter) (uintptr_t) src_rate; cvt->filters[SDL_AUDIOCVT_MAX_FILTERS] = (SDL_AudioFilter) (uintptr_t) dst_rate; @@ -785,7 +785,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt, } cvt->needed = (cvt->filter_index != 0); - return (cvt->needed); + return cvt->needed; } typedef int (*SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen); @@ -832,7 +832,7 @@ EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen) ptr = stream->work_buffer_base; } else { ptr = (Uint8 *) SDL_realloc(stream->work_buffer_base, newlen + 32); - if (!ptr) { + if (ptr == NULL) { SDL_OutOfMemory(); return NULL; } @@ -908,12 +908,12 @@ SetupLibSampleRateResampling(SDL_AudioStream *stream) if (SRC_available) { state = SRC_src_new(SRC_converter, stream->pre_resample_channels, &result); - if (!state) { + if (state == NULL) { SDL_SetError("src_new() failed: %s", SRC_src_strerror(result)); } } - if (!state) { + if (state == NULL) { SDL_CleanupAudioStreamResampler_SRC(stream); return SDL_FALSE; } @@ -980,7 +980,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format, SDL_AudioStream *retval; retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream)); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } @@ -1123,7 +1123,7 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in #endif workbuf = EnsureStreamBufferSize(stream, workbuflen); - if (!workbuf) { + if (workbuf == NULL) { return -1; /* probably out of memory. */ } @@ -1190,8 +1190,9 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in if (maxputbytes) { const int maxbytes = *maxputbytes; - if (buflen > maxbytes) + if (buflen > maxbytes) { buflen = maxbytes; + } *maxputbytes -= buflen; } @@ -1214,10 +1215,10 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len) SDL_Log("AUDIOSTREAM: wants to put %d preconverted bytes\n", buflen); #endif - if (!stream) { + if (stream == NULL) { return SDL_InvalidParamError("stream"); } - if (!buf) { + if (buf == NULL) { return SDL_InvalidParamError("buf"); } if (len == 0) { @@ -1269,7 +1270,7 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len) int SDL_AudioStreamFlush(SDL_AudioStream *stream) { - if (!stream) { + if (stream == NULL) { return SDL_InvalidParamError("stream"); } @@ -1287,8 +1288,9 @@ int SDL_AudioStreamFlush(SDL_AudioStream *stream) const SDL_bool first_run = stream->first_run; const int filled = stream->staging_buffer_filled; int actual_input_frames = filled / stream->src_sample_frame_size; - if (!first_run) + if (!first_run) { actual_input_frames += stream->resampler_padding_samples / stream->pre_resample_channels; + } if (actual_input_frames > 0) { /* don't bother if nothing to flush. */ /* This is how many bytes we're expecting without silence appended. */ @@ -1327,10 +1329,10 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len) SDL_Log("AUDIOSTREAM: want to get %d converted bytes\n", len); #endif - if (!stream) { + if (stream == NULL) { return SDL_InvalidParamError("stream"); } - if (!buf) { + if (buf == NULL) { return SDL_InvalidParamError("buf"); } if (len <= 0) { @@ -1340,20 +1342,20 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len) return SDL_SetError("Can't request partial sample frames"); } - return (int) SDL_ReadFromDataQueue(stream->queue, buf, len); + return (int)SDL_ReadFromDataQueue(stream->queue, buf, len); } /* number of converted/resampled bytes available */ int SDL_AudioStreamAvailable(SDL_AudioStream *stream) { - return stream ? (int) SDL_CountDataQueue(stream->queue) : 0; + return stream ? (int)SDL_CountDataQueue(stream->queue) : 0; } void SDL_AudioStreamClear(SDL_AudioStream *stream) { - if (!stream) { + if (stream == NULL) { SDL_InvalidParamError("stream"); } else { SDL_ClearDataQueue(stream->queue, stream->packetlen * 2); diff --git a/src/audio/SDL_audiodev.c b/src/audio/SDL_audiodev.c index c3de61afab..fc96e58a2c 100644 --- a/src/audio/SDL_audiodev.c +++ b/src/audio/SDL_audiodev.c @@ -83,8 +83,9 @@ SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (* const char *audiodev; char audiopath[1024]; - if (test == NULL) + if (test == NULL) { test = test_stub; + } /* Figure out what our audio device is */ if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) && diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c index bd521dec38..824ddee5dc 100644 --- a/src/audio/SDL_wave.c +++ b/src/audio/SDL_wave.c @@ -818,7 +818,7 @@ IMA_ADPCM_Init(WaveFile *file, size_t datalength) /* There's no specification for this, but it's basically the same * format because the extensible header has wSampePerBlocks too. */ - } else { + } else { /* The Standards Update says there 'should' be 2 bytes for wSamplesPerBlock. */ if (chunk->size >= 20 && format->extsize >= 2) { format->samplesperblock = chunk->data[18] | ((Uint16)chunk->data[19] << 8); @@ -899,14 +899,18 @@ IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble) * (nybble & 0x8 ? -1 : 1) * ((nybble & 0x7) * step / 4 + step / 8) */ delta = step >> 3; - if (nybble & 0x04) + if (nybble & 0x04) { delta += step; - if (nybble & 0x02) + } + if (nybble & 0x02) { delta += step >> 1; - if (nybble & 0x01) + } + if (nybble & 0x01) { delta += step >> 2; - if (nybble & 0x08) + } + if (nybble & 0x08) { delta = -delta; + } sample = lastsample + delta; diff --git a/src/audio/aaudio/SDL_aaudio.c b/src/audio/aaudio/SDL_aaudio.c index fd9c76bd80..ee3f8a1015 100644 --- a/src/audio/aaudio/SDL_aaudio.c +++ b/src/audio/aaudio/SDL_aaudio.c @@ -439,7 +439,7 @@ SDL_bool aaudio_DetectBrokenPlayState( void ) int64_t framePosition, timeNanoseconds; aaudio_result_t res; - if ( !audioDevice || !audioDevice->hidden ) { + if (audioDevice == NULL || !audioDevice->hidden ) { return SDL_FALSE; } diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index d8424ae4ac..3de6402ef2 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -230,7 +230,7 @@ get_audio_device(void *handle, const int channels) const char *device; if (handle != NULL) { - return (const char *) handle; + return (const char *)handle; } /* !!! FIXME: we also check "SDL_AUDIO_DEVICE_NAME" at the higher level. */ @@ -398,8 +398,7 @@ ALSA_PlayDevice(_THIS) return; } continue; - } - else if (status == 0) { + } else if (status == 0) { /* No frames were written (no available space in pcm device). Allow other threads to catch up. */ Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq; @@ -414,7 +413,7 @@ ALSA_PlayDevice(_THIS) static Uint8 * ALSA_GetDeviceBuf(_THIS) { - return (this->hidden->mixbuf); + return this->hidden->mixbuf; } static int @@ -438,8 +437,7 @@ ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen) if (status == -EAGAIN) { ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time); status = 0; - } - else if (status < 0) { + } else if (status < 0) { /*printf("ALSA: capture error %d\n", status);*/ status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0); if (status < 0) { @@ -500,7 +498,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params) status = ALSA_snd_pcm_hw_params_set_period_size_near( this->hidden->pcm_handle, hwparams, &persize, NULL); if ( status < 0 ) { - return(-1); + return -1; } /* Need to at least double buffer */ @@ -508,19 +506,19 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params) status = ALSA_snd_pcm_hw_params_set_periods_min( this->hidden->pcm_handle, hwparams, &periods, NULL); if ( status < 0 ) { - return(-1); + return -1; } status = ALSA_snd_pcm_hw_params_set_periods_first( this->hidden->pcm_handle, hwparams, &periods, NULL); if ( status < 0 ) { - return(-1); + return -1; } /* "set" the hardware with the desired parameters */ status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams); if ( status < 0 ) { - return(-1); + return -1; } this->spec.samples = persize; @@ -536,7 +534,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params) persize, periods, bufsize); } - return(0); + return 0; } static int @@ -572,8 +570,7 @@ ALSA_OpenDevice(_THIS, const char *devname) SND_PCM_NONBLOCK); if (status < 0) { - return SDL_SetError("ALSA: Couldn't open audio device: %s", - ALSA_snd_strerror(status)); + return SDL_SetError("ALSA: Couldn't open audio device: %s", ALSA_snd_strerror(status)); } this->hidden->pcm_handle = pcm_handle; @@ -582,16 +579,14 @@ ALSA_OpenDevice(_THIS, const char *devname) snd_pcm_hw_params_alloca(&hwparams); status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams); if (status < 0) { - return SDL_SetError("ALSA: Couldn't get hardware config: %s", - ALSA_snd_strerror(status)); + return SDL_SetError("ALSA: Couldn't get hardware config: %s", ALSA_snd_strerror(status)); } /* SDL only uses interleaved sample output */ status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); if (status < 0) { - return SDL_SetError("ALSA: Couldn't set interleaved access: %s", - ALSA_snd_strerror(status)); + return SDL_SetError("ALSA: Couldn't set interleaved access: %s", ALSA_snd_strerror(status)); } /* Try for a closest match on audio format */ @@ -673,8 +668,7 @@ ALSA_OpenDevice(_THIS, const char *devname) status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &rate, NULL); if (status < 0) { - return SDL_SetError("ALSA: Couldn't set audio frequency: %s", - ALSA_snd_strerror(status)); + return SDL_SetError("ALSA: Couldn't set audio frequency: %s", ALSA_snd_strerror(status)); } this->spec.freq = rate; @@ -688,24 +682,20 @@ ALSA_OpenDevice(_THIS, const char *devname) snd_pcm_sw_params_alloca(&swparams); status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams); if (status < 0) { - return SDL_SetError("ALSA: Couldn't get software config: %s", - ALSA_snd_strerror(status)); + return SDL_SetError("ALSA: Couldn't get software config: %s", ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples); if (status < 0) { - return SDL_SetError("Couldn't set minimum available samples: %s", - ALSA_snd_strerror(status)); + return SDL_SetError("Couldn't set minimum available samples: %s", ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1); if (status < 0) { - return SDL_SetError("ALSA: Couldn't set start threshold: %s", - ALSA_snd_strerror(status)); + return SDL_SetError("ALSA: Couldn't set start threshold: %s", ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params(pcm_handle, swparams); if (status < 0) { - return SDL_SetError("Couldn't set software audio parameters: %s", - ALSA_snd_strerror(status)); + return SDL_SetError("Couldn't set software audio parameters: %s", ALSA_snd_strerror(status)); } /* Calculate the final parameters for this audio specification */ @@ -746,7 +736,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee char *handle = NULL; char *ptr; - if (!dev) { + if (dev == NULL) { return; } @@ -756,7 +746,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee Make sure not to free the storage associated with desc in this case */ if (hint) { desc = ALSA_snd_device_name_get_hint(hint, "DESC"); - if (!desc) { + if (desc == NULL) { SDL_free(dev); return; } @@ -776,7 +766,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee /*printf("ALSA: adding %s device '%s' (%s)\n", iscapture ? "capture" : "output", name, desc);*/ handle = SDL_strdup(name); - if (!handle) { + if (handle == NULL) { if (hint) { free(desc); } @@ -789,8 +779,9 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee * enumeration time */ SDL_AddAudioDevice(iscapture, desc, NULL, handle); - if (hint) + if (hint) { free(desc); + } dev->name = handle; dev->iscapture = iscapture; dev->next = *pSeen; @@ -829,7 +820,7 @@ ALSA_HotplugIteration(void) if we can find a preferred prefix for the system. */ for (i = 0; hints[i]; i++) { char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME"); - if (!name) { + if (name == NULL) { continue; } @@ -858,17 +849,17 @@ ALSA_HotplugIteration(void) char *name; /* if we didn't find a device name prefix we like at all... */ - if ((!match) && (defaultdev != i)) { + if ((match == NULL) && (defaultdev != i)) { continue; /* ...skip anything that isn't the default device. */ } name = ALSA_snd_device_name_get_hint(hints[i], "NAME"); - if (!name) { + if (name == NULL) { continue; } /* only want physical hardware interfaces */ - if (!match || (SDL_strncmp(name, match, match_len) == 0)) { + if (match == NULL || (SDL_strncmp(name, match, match_len) == 0)) { char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID"); const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0); const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0); @@ -893,8 +884,12 @@ ALSA_HotplugIteration(void) } dev->next = seen; seen = dev; - if (isinput) have_input = SDL_TRUE; - if (isoutput) have_output = SDL_TRUE; + if (isinput) { + have_input = SDL_TRUE; + } + if (isoutput) { + have_output = SDL_TRUE; + } } else { prev = dev; } diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c index 2d60ee030c..f379b307bf 100644 --- a/src/audio/android/SDL_androidaudio.c +++ b/src/audio/android/SDL_androidaudio.c @@ -146,26 +146,24 @@ void ANDROIDAUDIO_PauseDevices(void) { /* TODO: Handle multiple devices? */ struct SDL_PrivateAudioData *private; - if(audioDevice != NULL && audioDevice->hidden != NULL) { + if (audioDevice != NULL && audioDevice->hidden != NULL) { private = (struct SDL_PrivateAudioData *) audioDevice->hidden; if (SDL_AtomicGet(&audioDevice->paused)) { /* The device is already paused, leave it alone */ private->resume = SDL_FALSE; - } - else { + } else { SDL_LockMutex(audioDevice->mixer_lock); SDL_AtomicSet(&audioDevice->paused, 1); private->resume = SDL_TRUE; } } - if(captureDevice != NULL && captureDevice->hidden != NULL) { + if (captureDevice != NULL && captureDevice->hidden != NULL) { private = (struct SDL_PrivateAudioData *) captureDevice->hidden; if (SDL_AtomicGet(&captureDevice->paused)) { /* The device is already paused, leave it alone */ private->resume = SDL_FALSE; - } - else { + } else { SDL_LockMutex(captureDevice->mixer_lock); SDL_AtomicSet(&captureDevice->paused, 1); private->resume = SDL_TRUE; @@ -178,7 +176,7 @@ void ANDROIDAUDIO_ResumeDevices(void) { /* TODO: Handle multiple devices? */ struct SDL_PrivateAudioData *private; - if(audioDevice != NULL && audioDevice->hidden != NULL) { + if (audioDevice != NULL && audioDevice->hidden != NULL) { private = (struct SDL_PrivateAudioData *) audioDevice->hidden; if (private->resume) { SDL_AtomicSet(&audioDevice->paused, 0); @@ -187,7 +185,7 @@ void ANDROIDAUDIO_ResumeDevices(void) } } - if(captureDevice != NULL && captureDevice->hidden != NULL) { + if (captureDevice != NULL && captureDevice->hidden != NULL) { private = (struct SDL_PrivateAudioData *) captureDevice->hidden; if (private->resume) { SDL_AtomicSet(&captureDevice->paused, 0); diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c index 979ef69536..e7631a63e3 100644 --- a/src/audio/directsound/SDL_directsound.c +++ b/src/audio/directsound/SDL_directsound.c @@ -293,7 +293,7 @@ DSOUND_GetDeviceBuf(_THIS) } if (result != DS_OK) { SetDSerror("DirectSound GetCurrentPosition", result); - return (NULL); + return NULL; } cursor /= this->spec.size; #ifdef DEBUG_SOUND @@ -328,9 +328,9 @@ DSOUND_GetDeviceBuf(_THIS) } if (result != DS_OK) { SetDSerror("DirectSound Lock", result); - return (NULL); + return NULL; } - return (this->hidden->locked_buf); + return this->hidden->locked_buf; } static int diff --git a/src/audio/disk/SDL_diskaudio.c b/src/audio/disk/SDL_diskaudio.c index 0dc7e4f178..a972145055 100644 --- a/src/audio/disk/SDL_diskaudio.c +++ b/src/audio/disk/SDL_diskaudio.c @@ -65,7 +65,7 @@ DISKAUDIO_PlayDevice(_THIS) static Uint8 * DISKAUDIO_GetDeviceBuf(_THIS) { - return (_this->hidden->mixbuf); + return _this->hidden->mixbuf; } static int diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c index 84836b22cb..401838a841 100644 --- a/src/audio/dsp/SDL_dspaudio.c +++ b/src/audio/dsp/SDL_dspaudio.c @@ -80,12 +80,13 @@ DSP_OpenDevice(_THIS, const char *devname) /* Make sure fragment size stays a power of 2, or OSS fails. */ /* I don't know which of these are actually legal values, though... */ - if (this->spec.channels > 8) + if (this->spec.channels > 8) { this->spec.channels = 8; - else if (this->spec.channels > 4) + } else if (this->spec.channels > 4) { this->spec.channels = 4; - else if (this->spec.channels > 2) + } else if (this->spec.channels > 2) { this->spec.channels = 2; + } /* Initialize all variables that we clean on shutdown */ this->hidden = (struct SDL_PrivateAudioData *) @@ -258,13 +259,13 @@ DSP_PlayDevice(_THIS) static Uint8 * DSP_GetDeviceBuf(_THIS) { - return (this->hidden->mixbuf); + return this->hidden->mixbuf; } static int DSP_CaptureFromDevice(_THIS, void *buffer, int buflen) { - return (int) read(this->hidden->audio_fd, buffer, buflen); + return (int)read(this->hidden->audio_fd, buffer, buflen); } static void diff --git a/src/audio/emscripten/SDL_emscriptenaudio.c b/src/audio/emscripten/SDL_emscriptenaudio.c index 510a38904b..5dc4625f51 100644 --- a/src/audio/emscripten/SDL_emscriptenaudio.c +++ b/src/audio/emscripten/SDL_emscriptenaudio.c @@ -206,7 +206,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname) /* create context */ result = MAIN_THREAD_EM_ASM_INT({ - if(typeof(Module['SDL3']) === 'undefined') { + if (typeof(Module['SDL3']) === 'undefined') { Module['SDL3'] = {}; } var SDL3 = Module['SDL3']; diff --git a/src/audio/jack/SDL_jackaudio.c b/src/audio/jack/SDL_jackaudio.c index 54f1a9b52e..e9495c0a3f 100644 --- a/src/audio/jack/SDL_jackaudio.c +++ b/src/audio/jack/SDL_jackaudio.c @@ -310,7 +310,7 @@ JACK_OpenDevice(_THIS, const char *devname) } devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags); - if (!devports || !devports[0]) { + if (devports == NULL || !devports[0]) { return SDL_SetError("No physical JACK ports available"); } diff --git a/src/audio/netbsd/SDL_netbsdaudio.c b/src/audio/netbsd/SDL_netbsdaudio.c index e83b2f8b75..7813b01bfb 100644 --- a/src/audio/netbsd/SDL_netbsdaudio.c +++ b/src/audio/netbsd/SDL_netbsdaudio.c @@ -144,7 +144,7 @@ NETBSDAUDIO_PlayDevice(_THIS) static Uint8 * NETBSDAUDIO_GetDeviceBuf(_THIS) { - return (this->hidden->mixbuf); + return this->hidden->mixbuf; } diff --git a/src/audio/openslES/SDL_openslES.c b/src/audio/openslES/SDL_openslES.c index fd3fc7bf8d..21131e707a 100644 --- a/src/audio/openslES/SDL_openslES.c +++ b/src/audio/openslES/SDL_openslES.c @@ -423,7 +423,7 @@ openslES_CreatePCMPlayer(_THIS) it can be done as described here: https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point */ - if(SDL_GetAndroidSDKVersion() >= 21) { + if (SDL_GetAndroidSDKVersion() >= 21) { SDL_AudioFormat test_format; for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) { if (SDL_AUDIO_ISSIGNED(test_format)) { @@ -498,7 +498,7 @@ openslES_CreatePCMPlayer(_THIS) break; } - if(SDL_AUDIO_ISFLOAT(this->spec.format)) { + if (SDL_AUDIO_ISFLOAT(this->spec.format)) { /* Copy all setup into PCM EX structure */ format_pcm_ex.formatType = SL_ANDROID_DATAFORMAT_PCM_EX; format_pcm_ex.endianness = format_pcm.endianness; diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c index c8ce986435..bd501f7546 100644 --- a/src/audio/pipewire/SDL_pipewire.c +++ b/src/audio/pipewire/SDL_pipewire.c @@ -1062,7 +1062,7 @@ input_callback(void *data) } pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream); - if (!pw_buf) { + if (pw_buf == NULL) { return; } @@ -1186,15 +1186,15 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname) /* Get the hints for the application name, stream name and role */ app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME); - if (!app_name || *app_name == '\0') { + if (app_name == NULL || *app_name == '\0') { app_name = SDL_GetHint(SDL_HINT_APP_NAME); - if (!app_name || *app_name == '\0') { + if (app_name == NULL || *app_name == '\0') { app_name = "SDL Application"; } } stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME); - if (!stream_name || *stream_name == '\0') { + if (stream_name == NULL || *stream_name == '\0') { stream_name = "Audio Stream"; } @@ -1203,7 +1203,7 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname) * but 'Game' seems more appropriate for the majority of SDL applications. */ stream_role = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_ROLE); - if (!stream_role || *stream_role == '\0') { + if (stream_role == NULL || *stream_role == '\0') { stream_role = "Game"; } diff --git a/src/audio/ps2/SDL_ps2audio.c b/src/audio/ps2/SDL_ps2audio.c index c3df809be7..0afbc66698 100644 --- a/src/audio/ps2/SDL_ps2audio.c +++ b/src/audio/ps2/SDL_ps2audio.c @@ -154,8 +154,9 @@ static void PS2AUDIO_Deinitialize(void) static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl * impl) { - if(init_audio_driver() < 0) + if (init_audio_driver() < 0) { return SDL_FALSE; + } /* Set the function pointers */ impl->OpenDevice = PS2AUDIO_OpenDevice; diff --git a/src/audio/psp/SDL_pspaudio.c b/src/audio/psp/SDL_pspaudio.c index c68df84f14..b81eaf6901 100644 --- a/src/audio/psp/SDL_pspaudio.c +++ b/src/audio/psp/SDL_pspaudio.c @@ -102,7 +102,7 @@ PSPAUDIO_OpenDevice(_THIS, const char *devname) static void PSPAUDIO_PlayDevice(_THIS) { - if (this->spec.freq != 44100){ + if (this->spec.freq != 44100) { Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer]; SDL_assert(this->spec.channels == 2); sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, mixbuf); @@ -128,7 +128,7 @@ static Uint8 *PSPAUDIO_GetDeviceBuf(_THIS) static void PSPAUDIO_CloseDevice(_THIS) { if (this->hidden->channel >= 0) { - if (this->spec.freq != 44100){ + if (this->spec.freq != 44100) { sceAudioSRCChRelease(); } else { sceAudioChRelease(this->hidden->channel); diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index 6009004fde..7dc4b726d6 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -49,17 +49,11 @@ static SDL_bool include_monitors = SDL_FALSE; #if (PA_API_VERSION < 12) /** Return non-zero if the passed state is one of the connected states */ static SDL_INLINE int PA_CONTEXT_IS_GOOD(pa_context_state_t x) { - return - x == PA_CONTEXT_CONNECTING || - x == PA_CONTEXT_AUTHORIZING || - x == PA_CONTEXT_SETTING_NAME || - x == PA_CONTEXT_READY; + return x == PA_CONTEXT_CONNECTING || x == PA_CONTEXT_AUTHORIZING || x == PA_CONTEXT_SETTING_NAME || x == PA_CONTEXT_READY; } /** Return non-zero if the passed state is one of the connected states */ static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x) { - return - x == PA_STREAM_CREATING || - x == PA_STREAM_READY; + return x == PA_STREAM_CREATING || x == PA_STREAM_READY; } #endif /* pulseaudio <= 0.9.10 */ @@ -308,7 +302,7 @@ ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context) SDL_assert(mainloop_api); /* this never fails, right? */ context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName()); - if (!context) { + if (context == NULL) { PULSEAUDIO_pa_mainloop_free(mainloop); return SDL_SetError("pa_context_new() failed"); } @@ -541,7 +535,7 @@ FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *h SinkDeviceNameCallback, &h->device_name)); } - return (h->device_name != NULL); + return h->device_name != NULL; } static int diff --git a/src/audio/vita/SDL_vitaaudio.c b/src/audio/vita/SDL_vitaaudio.c index 9095c52a53..5fb04792c9 100644 --- a/src/audio/vita/SDL_vitaaudio.c +++ b/src/audio/vita/SDL_vitaaudio.c @@ -78,7 +78,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname) } } - if(!test_format) { + if (!test_format) { return SDL_SetError("Unsupported audio format"); } @@ -108,7 +108,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname) format = SCE_AUDIO_OUT_MODE_STEREO; } - if(this->spec.freq < 48000) { + if (this->spec.freq < 48000) { port = SCE_AUDIO_OUT_PORT_TYPE_BGM; } diff --git a/src/audio/wasapi/SDL_wasapi_winrt.cpp b/src/audio/wasapi/SDL_wasapi_winrt.cpp index 2ce4ecc8ed..a5f6ca6d39 100644 --- a/src/audio/wasapi/SDL_wasapi_winrt.cpp +++ b/src/audio/wasapi/SDL_wasapi_winrt.cpp @@ -387,8 +387,7 @@ WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid) if (SDL_wcscmp(i->str, devid) == 0) { if (prev) { prev->next = next; - } - else { + } else { deviceid_list = next; } SDL_RemoveAudioDevice(iscapture, i->str); @@ -419,7 +418,7 @@ WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTENS } devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist)); - if (!devidlist) { + if (devidlist == NULL) { return; /* oh well. */ } diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 900af2956b..f15d4d016c 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -727,7 +727,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls, library_file = (*env)->GetStringUTFChars(env, library, NULL); library_handle = dlopen(library_file, RTLD_GLOBAL); - if (!library_handle) { + if (library_handle == NULL) { /* When deploying android app bundle format uncompressed native libs may not extract from apk to filesystem. In this case we should use lib name without path. https://bugzilla.libsdl.org/show_bug.cgi?id=4739 */ const char *library_name = SDL_strrchr(library_file, '/'); @@ -770,7 +770,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls, } (*env)->DeleteLocalRef(env, string); } - if (!arg) { + if (arg == NULL) { arg = SDL_strdup(""); } argv[argc++] = arg; @@ -867,8 +867,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)( { SDL_LockMutex(Android_ActivityMutex); - if (Android_Window) - { + if (Android_Window) { Android_SendResize(Android_Window); } @@ -883,8 +882,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)( displayOrientation = (SDL_DisplayOrientation)orientation; - if (Android_Window) - { + if (Android_Window) { SDL_VideoDisplay *display = SDL_GetDisplay(0); SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation); } @@ -993,8 +991,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, j { SDL_LockMutex(Android_ActivityMutex); - if (Android_Window) - { + if (Android_Window) { SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata; data->native_window = Android_JNI_GetNativeWindow(); @@ -1012,8 +1009,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j SDL_LockMutex(Android_ActivityMutex); #if SDL_VIDEO_OPENGL_EGL - if (Android_Window) - { + if (Android_Window) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata; @@ -1038,8 +1034,7 @@ retry: SDL_LockMutex(Android_ActivityMutex); - if (Android_Window) - { + if (Android_Window) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata; @@ -1873,7 +1868,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer, if (result > 0) { /* Number of chuncks */ - return (result / size); + return result / size; } else { /* Error or EOF */ return result; @@ -2258,7 +2253,7 @@ void *SDL_AndroidGetActivity(void) /* See SDL_system.h for caveats on using this function. */ JNIEnv *env = Android_JNI_GetEnv(); - if (!env) { + if (env == NULL) { return NULL; } @@ -2312,7 +2307,7 @@ const char * SDL_AndroidGetInternalStoragePath(void) { static char *s_AndroidInternalFilesPath = NULL; - if (!s_AndroidInternalFilesPath) { + if (s_AndroidInternalFilesPath == NULL) { struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); jmethodID mid; jobject context; @@ -2405,7 +2400,7 @@ const char * SDL_AndroidGetExternalStoragePath(void) { static char *s_AndroidExternalFilesPath = NULL; - if (!s_AndroidExternalFilesPath) { + if (s_AndroidExternalFilesPath == NULL) { struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); jmethodID mid; jobject context; diff --git a/src/core/freebsd/SDL_evdev_kbd_freebsd.c b/src/core/freebsd/SDL_evdev_kbd_freebsd.c index 93f1332074..670c5c8849 100644 --- a/src/core/freebsd/SDL_evdev_kbd_freebsd.c +++ b/src/core/freebsd/SDL_evdev_kbd_freebsd.c @@ -67,7 +67,7 @@ struct SDL_EVDEV_keyboard_state static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd) { - return (ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0); + return ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0; } static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL; @@ -95,7 +95,9 @@ static void kbd_cleanup(void) SDL_zero(mData); mData.operation = MOUSE_SHOW; ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode); - if (kbd->keyboard_fd != kbd->console_fd) close(kbd->keyboard_fd); + if (kbd->keyboard_fd != kbd->console_fd) { + close(kbd->keyboard_fd); + } ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index)); ioctl(kbd->console_fd, CONS_MOUSECTL, &mData); } @@ -151,13 +153,14 @@ static void kbd_unregister_emerg_cleanup() old_action_p = &(old_sigaction[signum]); /* Examine current signal action */ - if (sigaction(signum, NULL, &cur_action)) + if (sigaction(signum, NULL, &cur_action)) { continue; + } /* Check if action installed and not modifed */ - if (!(cur_action.sa_flags & SA_SIGINFO) - || cur_action.sa_sigaction != &kbd_cleanup_signal_action) + if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) { continue; + } /* Restore original action */ sigaction(signum, old_action_p, NULL); @@ -201,16 +204,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) struct sigaction new_action; signum = fatal_signals[tabidx]; old_action_p = &(old_sigaction[signum]); - if (sigaction(signum, NULL, old_action_p)) + if (sigaction(signum, NULL, old_action_p)) { continue; + } /* Skip SIGHUP and SIGPIPE if handler is already installed * - assume the handler will do the cleanup */ - if ((signum == SIGHUP || signum == SIGPIPE) - && (old_action_p->sa_handler != SIG_DFL - || (void (*)(int))old_action_p->sa_sigaction != SIG_DFL)) + if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) { continue; + } new_action = *old_action_p; new_action.sa_flags |= SA_SIGINFO; @@ -230,7 +233,7 @@ SDL_EVDEV_kbd_init(void) SDL_zero(mData); mData.operation = MOUSE_HIDE; kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state)); - if (!kbd) { + if (kbd == NULL) { return NULL; } @@ -252,8 +255,7 @@ SDL_EVDEV_kbd_init(void) kbd->ledflagstate = flag_state; } - if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0) - { + if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0) { SDL_free(kbd->accents); kbd->accents = &accentmap_default_us_acc; } @@ -261,8 +263,7 @@ SDL_EVDEV_kbd_init(void) if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) { /* Set the keyboard in XLATE mode and load the keymaps */ ioctl(kbd->console_fd, KDSKBMODE, (unsigned long)(K_XLATE)); - if(!SDL_EVDEV_kbd_load_keymaps(kbd)) - { + if (!SDL_EVDEV_kbd_load_keymaps(kbd)) { SDL_free(kbd->key_map); kbd->key_map = &keymap_default_us_acc; } @@ -274,8 +275,7 @@ SDL_EVDEV_kbd_init(void) ioctl(kbd->console_fd, CONS_RELKBD, 1ul); SDL_asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index); kbd->keyboard_fd = open(devicePath, O_WRONLY | O_CLOEXEC); - if (kbd->keyboard_fd == -1) - { + if (kbd->keyboard_fd == -1) { // Give keyboard back. ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index)); kbd->keyboard_fd = kbd->console_fd; @@ -288,8 +288,7 @@ SDL_EVDEV_kbd_init(void) kbd_register_emerg_cleanup(kbd); } SDL_free(devicePath); - } - else kbd->keyboard_fd = kbd->console_fd; + } else kbd->keyboard_fd = kbd->console_fd; } return kbd; @@ -300,7 +299,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) { struct mouse_info mData; - if (!kbd) { + if (kbd == NULL) { return; } SDL_zero(mData); @@ -314,8 +313,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode); close(kbd->keyboard_fd); - if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0) - { + if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0) { // Give back keyboard. ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index)); } @@ -346,10 +344,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c) put_queue(kbd, 0xc0 | (c >> 6)); put_queue(kbd, 0x80 | (c & 0x3f)); } else if (c < 0x10000) { - if (c >= 0xD800 && c < 0xE000) + if (c >= 0xD800 && c < 0xE000) { return; - if (c == 0xFFFF) + } + if (c == 0xFFFF) { return; + } /* 1110**** 10****** 10****** */ put_queue(kbd, 0xe0 | (c >> 12)); put_queue(kbd, 0x80 | ((c >> 6) & 0x3f)); @@ -378,13 +378,14 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch) kbd->diacr = 0; for (i = 0; i < kbd->accents->n_accs; i++) { - if (kbd->accents->acc[i].accchar == d) - { + if (kbd->accents->acc[i].accchar == d) { for (j = 0; j < NUM_ACCENTCHARS; ++j) { - if (kbd->accents->acc[i].map[j][0] == 0) /* end of table */ + if (kbd->accents->acc[i].map[j][0] == 0) { /* end of table */ break; - if (kbd->accents->acc[i].map[j][0] == ch) + } + if (kbd->accents->acc[i].map[j][0] == ch) { return kbd->accents->acc[i].map[j][1]; + } } } } @@ -415,11 +416,13 @@ static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag) { - if (up_flag) - return; /* no action, if this is a key release */ + if (up_flag) { + return; /* no action, if this is a key release */ + } - if (kbd->diacr) + if (kbd->diacr) { value = handle_diacr(kbd, value); + } if (kbd->dead_key_next) { kbd->dead_key_next = SDL_FALSE; @@ -449,8 +452,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ * handle the case that two shift or control * keys are depressed simultaneously */ - if (kbd->shift_down[value]) + if (kbd->shift_down[value]) { kbd->shift_down[value]--; + } } else kbd->shift_down[value]++; @@ -476,7 +480,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d key_map = *kbd->key_map; - if (!kbd) { + if (kbd == NULL) { return; } @@ -487,10 +491,10 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d /* These constitute unprintable language-related keys, so ignore them. */ return; } - if (keycode > 95) + if (keycode > 95) { keycode -= 7; - if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8)) - { + } + if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8)) { keycode += ALTGR_OFFSET; } keysym = key_map.key[keycode]; @@ -499,18 +503,21 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d } final_key_state = kbd->shift_state & 0x7; - if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP)) + if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP)) { final_key_state ^= 0x1; - if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM)) + } + if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM)) { final_key_state ^= 0x1; + } map_from_key_sym = keysym.map[final_key_state]; if ((keysym.spcl & (0x80 >> final_key_state)) || (map_from_key_sym & SPCLKEY)) { /* Special function.*/ if (map_from_key_sym == 0) return; /* Nothing to do. */ - if (map_from_key_sym & SPCLKEY) + if (map_from_key_sym & SPCLKEY) { map_from_key_sym &= ~SPCLKEY; + } if (map_from_key_sym >= F_ACC && map_from_key_sym <= L_ACC) { /* Accent function.*/ unsigned int accent_index = map_from_key_sym - F_ACC; @@ -524,36 +531,50 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d break; case LSHA: /* left shift + alt lock */ case RSHA: /* right shift + alt lock */ - if (down == 0) chg_vc_kbd_led(kbd, ALKED); + if (down == 0) { + chg_vc_kbd_led(kbd, ALKED); + } case LSH: /* left shift */ case RSH: /* right shift */ k_shift(kbd, 0, down == 0); break; case LCTRA: /* left ctrl + alt lock */ case RCTRA: /* right ctrl + alt lock */ - if (down == 0) chg_vc_kbd_led(kbd, ALKED); + if (down == 0) { + chg_vc_kbd_led(kbd, ALKED); + } case LCTR: /* left ctrl */ case RCTR: /* right ctrl */ k_shift(kbd, 1, down == 0); break; case LALTA: /* left alt + alt lock */ case RALTA: /* right alt + alt lock */ - if (down == 0) chg_vc_kbd_led(kbd, ALKED); + if (down == 0) { + chg_vc_kbd_led(kbd, ALKED); + } case LALT: /* left alt */ case RALT: /* right alt */ k_shift(kbd, 2, down == 0); break; case ALK: /* alt lock */ - if (down == 1) chg_vc_kbd_led(kbd, ALKED); + if (down == 1) { + chg_vc_kbd_led(kbd, ALKED); + } break; case CLK: /* caps lock*/ - if (down == 1) chg_vc_kbd_led(kbd, CLKED); + if (down == 1) { + chg_vc_kbd_led(kbd, CLKED); + } break; case NLK: /* num lock */ - if (down == 1) chg_vc_kbd_led(kbd, NLKED); + if (down == 1) { + chg_vc_kbd_led(kbd, NLKED); + } break; case SLK: /* scroll lock */ - if (down == 1) chg_vc_kbd_led(kbd, SLKED); + if (down == 1) { + chg_vc_kbd_led(kbd, SLKED); + } break; default: return; diff --git a/src/core/gdk/SDL_gdk.cpp b/src/core/gdk/SDL_gdk.cpp index bb3a625acf..426721c1c8 100644 --- a/src/core/gdk/SDL_gdk.cpp +++ b/src/core/gdk/SDL_gdk.cpp @@ -105,13 +105,13 @@ SDL_GDKRunApp(SDL_main_func mainFunction, void *reserved) /* Parse it into argv and argc */ argv = (char **) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv)); - if (!argv) { + if (argv == NULL) { return OutOfMemory(); } for (i = 0; i < argc; ++i) { DWORD len; char *arg = WIN_StringToUTF8W(argvw[i]); - if (!arg) { + if (arg == NULL) { return OutOfMemory(); } len = (DWORD) SDL_strlen(arg); diff --git a/src/core/linux/SDL_dbus.c b/src/core/linux/SDL_dbus.c index ac3eef8a2e..efe6b5a4e9 100644 --- a/src/core/linux/SDL_dbus.c +++ b/src/core/linux/SDL_dbus.c @@ -198,7 +198,7 @@ SDL_DBus_Quit(void) SDL_DBusContext * SDL_DBus_GetContext(void) { - if (!dbus_handle || !dbus.session_conn) { + if (dbus_handle == NULL || !dbus.session_conn) { SDL_DBus_Init(); } @@ -376,20 +376,25 @@ SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, cons { DBusMessageIter iterDict, iterEntry, iterValue; - if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict)) + if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict)) { goto failed; + } - if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry)) + if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry)) { goto failed; + } - if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) + if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) { goto failed; + } - if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue)) + if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue)) { goto failed; + } - if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) + if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) { goto failed; + } if (!dbus.message_iter_close_container(&iterEntry, &iterValue) || !dbus.message_iter_close_container(&iterDict, &iterEntry) @@ -436,12 +441,12 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit) const char *key = "reason"; const char *reply = NULL; const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME); - if (!reason || !reason[0]) { + if (reason == NULL || !reason[0]) { reason = default_inhibit_reason; } msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit"); - if (!msg) { + if (msg == NULL) { return SDL_FALSE; } @@ -478,10 +483,10 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit) if (inhibit) { const char *app = SDL_GetHint(SDL_HINT_APP_NAME); const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME); - if (!app || !app[0]) { + if (app == NULL || !app[0]) { app = "My SDL application"; } - if (!reason || !reason[0]) { + if (reason == NULL || !reason[0]) { reason = default_inhibit_reason; } diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c index 6e26b458b5..6d8362a9e6 100644 --- a/src/core/linux/SDL_evdev.c +++ b/src/core/linux/SDL_evdev.c @@ -188,11 +188,11 @@ SDL_EVDEV_Init(void) while ((spec = SDL_strtokr(rest, ",", &rest))) { char* endofcls = 0; long cls = SDL_strtol(spec, &endofcls, 0); - if (endofcls) + if (endofcls) { SDL_EVDEV_device_added(endofcls + 1, cls); + } } - } - else { + } else { /* TODO: Scan the devices manually, like a caveman */ } } @@ -226,7 +226,7 @@ SDL_EVDEV_Quit(void) SDL_EVDEV_kbd_quit(_this->kbd); /* Remove existing devices */ - while(_this->first != NULL) { + while (_this->first != NULL) { SDL_EVDEV_device_removed(_this->first->path); } @@ -249,11 +249,13 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl switch(udev_event) { case SDL_UDEV_DEVICEADDED: - if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD))) + if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD))) { return; + } - if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK)) + if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK)) { return; + } SDL_EVDEV_device_added(dev_path, udev_class); break; @@ -338,13 +340,15 @@ SDL_EVDEV_Poll(void) case EV_ABS: switch(events[i].code) { case ABS_MT_SLOT: - if (!item->is_touchscreen) /* FIXME: temp hack */ + if (!item->is_touchscreen) { /* FIXME: temp hack */ break; + } item->touchscreen_data->current_slot = events[i].value; break; case ABS_MT_TRACKING_ID: - if (!item->is_touchscreen) /* FIXME: temp hack */ + if (!item->is_touchscreen) { /* FIXME: temp hack */ break; + } if (events[i].value >= 0) { item->touchscreen_data->slots[item->touchscreen_data->current_slot].tracking_id = events[i].value; item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_DOWN; @@ -353,24 +357,27 @@ SDL_EVDEV_Poll(void) } break; case ABS_MT_POSITION_X: - if (!item->is_touchscreen) /* FIXME: temp hack */ + if (!item->is_touchscreen) { /* FIXME: temp hack */ break; + } item->touchscreen_data->slots[item->touchscreen_data->current_slot].x = events[i].value; if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) { item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE; } break; case ABS_MT_POSITION_Y: - if (!item->is_touchscreen) /* FIXME: temp hack */ + if (!item->is_touchscreen) { /* FIXME: temp hack */ break; + } item->touchscreen_data->slots[item->touchscreen_data->current_slot].y = events[i].value; if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) { item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE; } break; case ABS_MT_PRESSURE: - if (!item->is_touchscreen) /* FIXME: temp hack */ + if (!item->is_touchscreen) { /* FIXME: temp hack */ break; + } item->touchscreen_data->slots[item->touchscreen_data->current_slot].pressure = events[i].value; if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) { item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE; @@ -378,8 +385,9 @@ SDL_EVDEV_Poll(void) break; case ABS_X: if (item->is_touchscreen) { - if (item->touchscreen_data->max_slots != 1) + if (item->touchscreen_data->max_slots != 1) { break; + } item->touchscreen_data->slots[0].x = events[i].value; } else if (!item->relative_mouse) { /* FIXME: Normalize to input device's reported input range (EVIOCGABS) */ @@ -388,8 +396,9 @@ SDL_EVDEV_Poll(void) break; case ABS_Y: if (item->is_touchscreen) { - if (item->touchscreen_data->max_slots != 1) + if (item->touchscreen_data->max_slots != 1) { break; + } item->touchscreen_data->slots[0].y = events[i].value; } else if (!item->relative_mouse) { /* FIXME: Normalize to input device's reported input range (EVIOCGABS) */ @@ -403,24 +412,28 @@ SDL_EVDEV_Poll(void) case EV_REL: switch(events[i].code) { case REL_X: - if (item->relative_mouse) + if (item->relative_mouse) { item->mouse_x += events[i].value; + } break; case REL_Y: - if (item->relative_mouse) + if (item->relative_mouse) { item->mouse_y += events[i].value; + } break; case REL_WHEEL: - if (!item->high_res_wheel) + if (!item->high_res_wheel) { item->mouse_wheel += events[i].value; + } break; case REL_WHEEL_HI_RES: SDL_assert(item->high_res_wheel); item->mouse_wheel += events[i].value; break; case REL_HWHEEL: - if (!item->high_res_hwheel) + if (!item->high_res_hwheel) { item->mouse_hwheel += events[i].value; + } break; case REL_HWHEEL_HI_RES: SDL_assert(item->high_res_hwheel); @@ -446,10 +459,11 @@ SDL_EVDEV_Poll(void) item->mouse_wheel = item->mouse_hwheel = 0; } - if (!item->is_touchscreen) /* FIXME: temp hack */ + if (!item->is_touchscreen) { /* FIXME: temp hack */ break; + } - for(j = 0; j < item->touchscreen_data->max_slots; j++) { + for (j = 0; j < item->touchscreen_data->max_slots; j++) { norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) / (float)item->touchscreen_data->range_x; norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) / @@ -485,12 +499,14 @@ SDL_EVDEV_Poll(void) } } - if (item->out_of_sync) + if (item->out_of_sync) { item->out_of_sync = SDL_FALSE; + } break; case SYN_DROPPED: - if (item->is_touchscreen) + if (item->is_touchscreen) { item->out_of_sync = SDL_TRUE; + } SDL_EVDEV_sync_device(item); break; default: @@ -533,12 +549,14 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class) char name[64]; struct input_absinfo abs_info; - if (!item->is_touchscreen) + if (!item->is_touchscreen) { return 0; + } item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data)); - if (item->touchscreen_data == NULL) + if (item->touchscreen_data == NULL) { return SDL_OutOfMemory(); + } ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name); if (ret < 0) { @@ -608,7 +626,7 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class) return SDL_OutOfMemory(); } - for(i = 0; i < item->touchscreen_data->max_slots; i++) { + for (i = 0; i < item->touchscreen_data->max_slots; i++) { item->touchscreen_data->slots[i].tracking_id = -1; } @@ -627,8 +645,9 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class) static void SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) { - if (!item->is_touchscreen) + if (!item->is_touchscreen) { return; + } SDL_DelTouch(item->fd); SDL_free(item->touchscreen_data->slots); @@ -655,8 +674,9 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item) size_t mt_req_size; /* TODO: sync devices other than touchscreen */ - if (!item->is_touchscreen) + if (!item->is_touchscreen) { return; + } mt_req_size = sizeof(*mt_req_code) + sizeof(*mt_req_values) * item->touchscreen_data->max_slots; @@ -674,7 +694,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item) SDL_free(mt_req_code); return; } - for(i = 0; i < item->touchscreen_data->max_slots; i++) { + for (i = 0; i < item->touchscreen_data->max_slots; i++) { /* * This doesn't account for the very edge case of the user removing their * finger and replacing it on the screen during the time we're out of sync, @@ -701,7 +721,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item) SDL_free(mt_req_code); return; } - for(i = 0; i < item->touchscreen_data->max_slots; i++) { + for (i = 0; i < item->touchscreen_data->max_slots; i++) { if (item->touchscreen_data->slots[i].tracking_id >= 0 && item->touchscreen_data->slots[i].x != mt_req_values[i]) { item->touchscreen_data->slots[i].x = mt_req_values[i]; @@ -719,7 +739,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item) SDL_free(mt_req_code); return; } - for(i = 0; i < item->touchscreen_data->max_slots; i++) { + for (i = 0; i < item->touchscreen_data->max_slots; i++) { if (item->touchscreen_data->slots[i].tracking_id >= 0 && item->touchscreen_data->slots[i].y != mt_req_values[i]) { item->touchscreen_data->slots[i].y = mt_req_values[i]; @@ -737,7 +757,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item) SDL_free(mt_req_code); return; } - for(i = 0; i < item->touchscreen_data->max_slots; i++) { + for (i = 0; i < item->touchscreen_data->max_slots; i++) { if (item->touchscreen_data->slots[i].tracking_id >= 0 && item->touchscreen_data->slots[i].pressure != mt_req_values[i]) { item->touchscreen_data->slots[i].pressure = mt_req_values[i]; diff --git a/src/core/linux/SDL_evdev_capabilities.c b/src/core/linux/SDL_evdev_capabilities.c index e23d499736..cf5530f846 100644 --- a/src/core/linux/SDL_evdev_capabilities.c +++ b/src/core/linux/SDL_evdev_capabilities.c @@ -138,8 +138,9 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)], /* the first 32 bits are ESC, numbers, and Q to D; if we have any of * those, consider it a keyboard device; do not test KEY_RESERVED, though */ keyboard_mask = 0xFFFFFFFE; - if ((bitmask_key[0] & keyboard_mask) != 0) + if ((bitmask_key[0] & keyboard_mask) != 0) { devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */ + } return devclass; } diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c index 06bdf27fef..b11e9fc5e9 100644 --- a/src/core/linux/SDL_evdev_kbd.c +++ b/src/core/linux/SDL_evdev_kbd.c @@ -269,13 +269,14 @@ static void kbd_unregister_emerg_cleanup() old_action_p = &(old_sigaction[signum]); /* Examine current signal action */ - if (sigaction(signum, NULL, &cur_action)) + if (sigaction(signum, NULL, &cur_action)) { continue; + } /* Check if action installed and not modifed */ - if (!(cur_action.sa_flags & SA_SIGINFO) - || cur_action.sa_sigaction != &kbd_cleanup_signal_action) + if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) { continue; + } /* Restore original action */ sigaction(signum, old_action_p, NULL); @@ -319,16 +320,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) struct sigaction new_action; signum = fatal_signals[tabidx]; old_action_p = &(old_sigaction[signum]); - if (sigaction(signum, NULL, old_action_p)) + if (sigaction(signum, NULL, old_action_p)) { continue; + } /* Skip SIGHUP and SIGPIPE if handler is already installed * - assume the handler will do the cleanup */ - if ((signum == SIGHUP || signum == SIGPIPE) - && (old_action_p->sa_handler != SIG_DFL - || (void (*)(int))old_action_p->sa_sigaction != SIG_DFL)) + if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) { continue; + } new_action = *old_action_p; new_action.sa_flags |= SA_SIGINFO; @@ -346,7 +347,7 @@ SDL_EVDEV_kbd_init(void) char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0}; kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd)); - if (!kbd) { + if (kbd == NULL) { return NULL; } @@ -412,7 +413,7 @@ SDL_EVDEV_kbd_init(void) void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) { - if (!kbd) { + if (kbd == NULL) { return; } @@ -460,10 +461,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c) put_queue(kbd, 0xc0 | (c >> 6)); put_queue(kbd, 0x80 | (c & 0x3f)); } else if (c < 0x10000) { - if (c >= 0xD800 && c < 0xE000) + if (c >= 0xD800 && c < 0xE000) { return; - if (c == 0xFFFF) + } + if (c == 0xFFFF) { return; + } /* 1110**** 10****** 10****** */ put_queue(kbd, 0xe0 | (c >> 12)); put_queue(kbd, 0x80 | ((c >> 6) & 0x3f)); @@ -498,8 +501,9 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch) } } - if (ch == ' ' || ch == d) + if (ch == ' ' || ch == d) { return d; + } put_utf8(kbd, d); @@ -553,24 +557,27 @@ static void fn_enter(SDL_EVDEV_keyboard_state *kbd) static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd) { - if (kbd->rep) + if (kbd->rep) { return; + } chg_vc_kbd_led(kbd, K_CAPSLOCK); } static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd) { - if (kbd->rep) + if (kbd->rep) { return; + } set_vc_kbd_led(kbd, K_CAPSLOCK); } static void fn_num(SDL_EVDEV_keyboard_state *kbd) { - if (!kbd->rep) + if (!kbd->rep) { chg_vc_kbd_led(kbd, K_NUMLOCK); + } } static void fn_compose(SDL_EVDEV_keyboard_state *kbd) @@ -588,12 +595,15 @@ static void k_ignore(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up static void k_spec(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) { - if (up_flag) + if (up_flag) { return; - if (value >= SDL_arraysize(fn_handler)) + } + if (value >= SDL_arraysize(fn_handler)) { return; - if (fn_handler[value]) + } + if (fn_handler[value]) { fn_handler[value](kbd); + } } static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) @@ -602,11 +612,13 @@ static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) { - if (up_flag) - return; /* no action, if this is a key release */ + if (up_flag) { + return; /* no action, if this is a key release */ + } - if (kbd->diacr) + if (kbd->diacr) { value = handle_diacr(kbd, value); + } if (kbd->dead_key_next) { kbd->dead_key_next = SDL_FALSE; @@ -675,8 +687,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ */ if (value == KVAL(K_CAPSSHIFT)) { value = KVAL(K_SHIFT); - if (!up_flag) + if (!up_flag) { clr_vc_kbd_led(kbd, K_CAPSLOCK); + } } if (up_flag) { @@ -684,8 +697,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ * handle the case that two shift or control * keys are depressed simultaneously */ - if (kbd->shift_down[value]) + if (kbd->shift_down[value]) { kbd->shift_down[value]--; + } } else kbd->shift_down[value]++; @@ -761,7 +775,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d unsigned short *key_map; unsigned short keysym; - if (!kbd) { + if (kbd == NULL) { return; } @@ -769,7 +783,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate; key_map = kbd->key_maps[shift_final]; - if (!key_map) { + if (key_map == NULL) { /* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */ kbd->shift_state = 0; kbd->slockstate = 0; diff --git a/src/core/linux/SDL_fcitx.c b/src/core/linux/SDL_fcitx.c index 1cab0ae501..5e85af9b93 100644 --- a/src/core/linux/SDL_fcitx.c +++ b/src/core/linux/SDL_fcitx.c @@ -347,14 +347,30 @@ Fcitx_ModState(void) Uint32 fcitx_mods = 0; SDL_Keymod sdl_mods = SDL_GetModState(); - if (sdl_mods & KMOD_SHIFT) fcitx_mods |= (1 << 0); - if (sdl_mods & KMOD_CAPS) fcitx_mods |= (1 << 1); - if (sdl_mods & KMOD_CTRL) fcitx_mods |= (1 << 2); - if (sdl_mods & KMOD_ALT) fcitx_mods |= (1 << 3); - if (sdl_mods & KMOD_NUM) fcitx_mods |= (1 << 4); - if (sdl_mods & KMOD_MODE) fcitx_mods |= (1 << 7); - if (sdl_mods & KMOD_LGUI) fcitx_mods |= (1 << 6); - if (sdl_mods & KMOD_RGUI) fcitx_mods |= (1 << 28); + if (sdl_mods & KMOD_SHIFT) { + fcitx_mods |= (1 << 0); + } + if (sdl_mods & KMOD_CAPS) { + fcitx_mods |= (1 << 1); + } + if (sdl_mods & KMOD_CTRL) { + fcitx_mods |= (1 << 2); + } + if (sdl_mods & KMOD_ALT) { + fcitx_mods |= (1 << 3); + } + if (sdl_mods & KMOD_NUM) { + fcitx_mods |= (1 << 4); + } + if (sdl_mods & KMOD_MODE) { + fcitx_mods |= (1 << 7); + } + if (sdl_mods & KMOD_LGUI) { + fcitx_mods |= (1 << 6); + } + if (sdl_mods & KMOD_RGUI) { + fcitx_mods |= (1 << 28); + } return fcitx_mods; } @@ -436,7 +452,7 @@ SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect) } focused_win = SDL_GetKeyboardFocus(); - if (!focused_win) { + if (focused_win == NULL) { return ; } diff --git a/src/core/linux/SDL_ibus.c b/src/core/linux/SDL_ibus.c index e0de9a0893..5f0eed6076 100644 --- a/src/core/linux/SDL_ibus.c +++ b/src/core/linux/SDL_ibus.c @@ -64,14 +64,30 @@ IBus_ModState(void) SDL_Keymod sdl_mods = SDL_GetModState(); /* Not sure about MOD3, MOD4 and HYPER mappings */ - if (sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK; - if (sdl_mods & KMOD_CAPS) ibus_mods |= IBUS_LOCK_MASK; - if (sdl_mods & KMOD_LCTRL) ibus_mods |= IBUS_CONTROL_MASK; - if (sdl_mods & KMOD_LALT) ibus_mods |= IBUS_MOD1_MASK; - if (sdl_mods & KMOD_NUM) ibus_mods |= IBUS_MOD2_MASK; - if (sdl_mods & KMOD_MODE) ibus_mods |= IBUS_MOD5_MASK; - if (sdl_mods & KMOD_LGUI) ibus_mods |= IBUS_SUPER_MASK; - if (sdl_mods & KMOD_RGUI) ibus_mods |= IBUS_META_MASK; + if (sdl_mods & KMOD_LSHIFT) { + ibus_mods |= IBUS_SHIFT_MASK; + } + if (sdl_mods & KMOD_CAPS) { + ibus_mods |= IBUS_LOCK_MASK; + } + if (sdl_mods & KMOD_LCTRL) { + ibus_mods |= IBUS_CONTROL_MASK; + } + if (sdl_mods & KMOD_LALT) { + ibus_mods |= IBUS_MOD1_MASK; + } + if (sdl_mods & KMOD_NUM) { + ibus_mods |= IBUS_MOD2_MASK; + } + if (sdl_mods & KMOD_MODE) { + ibus_mods |= IBUS_MOD5_MASK; + } + if (sdl_mods & KMOD_LGUI) { + ibus_mods |= IBUS_SUPER_MASK; + } + if (sdl_mods & KMOD_RGUI) { + ibus_mods |= IBUS_META_MASK; + } return ibus_mods; } @@ -98,7 +114,7 @@ IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext * } dbus->message_iter_get_basic(inside, &struct_id); - if (!struct_id || SDL_strncmp(struct_id, struct_id, id_size) != 0) { + if (struct_id == NULL || SDL_strncmp(struct_id, struct_id, id_size) != 0) { return SDL_FALSE; } return SDL_TRUE; @@ -248,13 +264,12 @@ IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data) dbus->message_iter_init(msg, &iter); has_dec_pos = IBus_GetDecorationPosition(conn, &iter, dbus, &start_pos, &end_pos); - if (!has_dec_pos) - { + if (!has_dec_pos) { dbus->message_iter_init(msg, &iter); has_pos = IBus_GetVariantCursorPos(conn, &iter, dbus, &pos); } - if(has_dec_pos) { + if (has_dec_pos) { SDL_SendEditingText(text, start_pos, end_pos - start_pos); } else if (has_pos) { SDL_SendEditingText(text, pos, -1); @@ -298,15 +313,19 @@ IBus_ReadAddressFromFile(const char *file_path) FILE *addr_file; addr_file = fopen(file_path, "r"); - if (!addr_file) { + if (addr_file == NULL) { return NULL; } while (fgets(addr_buf, sizeof(addr_buf), addr_file)) { if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) { size_t sz = SDL_strlen(addr_buf); - if (addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0; - if (addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0; + if (addr_buf[sz - 1] == '\n') { + addr_buf[sz - 1] = 0; + } + if (addr_buf[sz - 2] == '\r') { + addr_buf[sz - 2] = 0; + } success = SDL_TRUE; break; } @@ -340,7 +359,7 @@ IBus_GetDBusAddressFilename(void) } dbus = SDL_DBus_GetContext(); - if (!dbus) { + if (dbus == NULL) { return NULL; } @@ -354,7 +373,7 @@ IBus_GetDBusAddressFilename(void) and look up the address from a filepath using all those bits, eek. */ disp_env = SDL_getenv("DISPLAY"); - if (!disp_env || !*disp_env) { + if (disp_env == NULL || !*disp_env) { display = SDL_strdup(":0.0"); } else { display = SDL_strdup(disp_env); @@ -364,7 +383,7 @@ IBus_GetDBusAddressFilename(void) disp_num = SDL_strrchr(display, ':'); screen_num = SDL_strrchr(display, '.'); - if (!disp_num) { + if (disp_num == NULL) { SDL_free(display); return NULL; } @@ -392,7 +411,7 @@ IBus_GetDBusAddressFilename(void) SDL_strlcpy(config_dir, conf_env, sizeof(config_dir)); } else { const char *home_env = SDL_getenv("HOME"); - if (!home_env || !*home_env) { + if (home_env == NULL || !*home_env) { SDL_free(display); return NULL; } @@ -460,7 +479,7 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr) ibus_input_interface = IBUS_INPUT_INTERFACE; ibus_conn = dbus->connection_open_private(addr, NULL); - if (!ibus_conn) { + if (ibus_conn == NULL) { return SDL_FALSE; /* oh well. */ } @@ -498,7 +517,9 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr) static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus) { - if (!dbus) return SDL_FALSE; + if (dbus == NULL) { + return SDL_FALSE; + } if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) { return SDL_TRUE; @@ -516,7 +537,9 @@ IBus_CheckConnection(SDL_DBusContext *dbus) struct inotify_event *event = (struct inotify_event*) p; if (event->len > 0) { char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/'); - if (!addr_file_no_path) return SDL_FALSE; + if (addr_file_no_path == NULL) { + return SDL_FALSE; + } if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) { file_updated = SDL_TRUE; @@ -552,7 +575,7 @@ SDL_IBus_Init(void) char *addr; char *addr_file_dir; - if (!addr_file) { + if (addr_file == NULL) { return SDL_FALSE; } @@ -560,7 +583,7 @@ SDL_IBus_Init(void) ibus_addr_file = SDL_strdup(addr_file); addr = IBus_ReadAddressFromFile(addr_file); - if (!addr) { + if (addr == NULL) { SDL_free(addr_file); return SDL_FALSE; } @@ -699,7 +722,7 @@ SDL_IBus_UpdateTextRect(const SDL_Rect *rect) } focused_win = SDL_GetKeyboardFocus(); - if (!focused_win) { + if (focused_win == NULL) { return; } diff --git a/src/core/linux/SDL_ime.c b/src/core/linux/SDL_ime.c index 3ad4dbf434..e43fe86912 100644 --- a/src/core/linux/SDL_ime.c +++ b/src/core/linux/SDL_ime.c @@ -49,16 +49,17 @@ InitIME() const char *xmodifiers = SDL_getenv("XMODIFIERS"); #endif - if (inited == SDL_TRUE) + if (inited == SDL_TRUE) { return; + } inited = SDL_TRUE; /* See if fcitx IME support is being requested */ #ifdef HAVE_FCITX - if (!SDL_IME_Init_Real && + if (SDL_IME_Init_Real == NULL && ((im_module && SDL_strcmp(im_module, "fcitx") == 0) || - (!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) { + (im_module == NULL && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) { SDL_IME_Init_Real = SDL_Fcitx_Init; SDL_IME_Quit_Real = SDL_Fcitx_Quit; SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus; @@ -71,7 +72,7 @@ InitIME() /* default to IBus */ #ifdef HAVE_IBUS_IBUS_H - if (!SDL_IME_Init_Real) { + if (SDL_IME_Init_Real == NULL) { SDL_IME_Init_Real = SDL_IBus_Init; SDL_IME_Quit_Real = SDL_IBus_Quit; SDL_IME_SetFocus_Real = SDL_IBus_SetFocus; @@ -109,29 +110,33 @@ SDL_IME_Init(void) void SDL_IME_Quit(void) { - if (SDL_IME_Quit_Real) + if (SDL_IME_Quit_Real) { SDL_IME_Quit_Real(); + } } void SDL_IME_SetFocus(SDL_bool focused) { - if (SDL_IME_SetFocus_Real) + if (SDL_IME_SetFocus_Real) { SDL_IME_SetFocus_Real(focused); + } } void SDL_IME_Reset(void) { - if (SDL_IME_Reset_Real) + if (SDL_IME_Reset_Real) { SDL_IME_Reset_Real(); + } } SDL_bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state) { - if (SDL_IME_ProcessKeyEvent_Real) + if (SDL_IME_ProcessKeyEvent_Real) { return SDL_IME_ProcessKeyEvent_Real(keysym, keycode, state); + } return SDL_FALSE; } @@ -139,15 +144,17 @@ SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state) void SDL_IME_UpdateTextRect(const SDL_Rect *rect) { - if (SDL_IME_UpdateTextRect_Real) + if (SDL_IME_UpdateTextRect_Real) { SDL_IME_UpdateTextRect_Real(rect); + } } void SDL_IME_PumpEvents() { - if (SDL_IME_PumpEvents_Real) + if (SDL_IME_PumpEvents_Real) { SDL_IME_PumpEvents_Real(); + } } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/core/linux/SDL_threadprio.c b/src/core/linux/SDL_threadprio.c index 5be4694f72..297ded7e51 100644 --- a/src/core/linux/SDL_threadprio.c +++ b/src/core/linux/SDL_threadprio.c @@ -116,20 +116,20 @@ rtkit_initialize() dbus_conn = get_rtkit_dbus_connection(); /* Try getting minimum nice level: this is often greater than PRIO_MIN (-20). */ - if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel", - DBUS_TYPE_INT32, &rtkit_min_nice_level)) { + if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel", + DBUS_TYPE_INT32, &rtkit_min_nice_level)) { rtkit_min_nice_level = -20; } /* Try getting maximum realtime priority: this can be less than the POSIX default (99). */ - if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority", - DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) { + if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority", + DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) { rtkit_max_realtime_priority = 99; } /* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */ - if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax", - DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) { + if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax", + DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) { rtkit_max_rttime_usec = 200000; } } @@ -168,8 +168,7 @@ rtkit_initialize_realtime_thread() // Requirement #1: Set RLIMIT_RTTIME err = getrlimit(nLimit, &rlimit); - if (err) - { + if (err) { return SDL_FALSE; } @@ -177,21 +176,18 @@ rtkit_initialize_realtime_thread() rlimit.rlim_max = rtkit_max_rttime_usec; rlimit.rlim_cur = rlimit.rlim_max / 2; err = setrlimit(nLimit, &rlimit); - if (err) - { + if (err) { return SDL_FALSE; } // Requirement #2: Add SCHED_RESET_ON_FORK to the scheduler policy err = sched_getparam(nPid, &schedParam); - if (err) - { + if (err) { return SDL_FALSE; } err = sched_setscheduler(nPid, nSchedPolicy, &schedParam); - if (err) - { + if (err) { return SDL_FALSE; } @@ -209,13 +205,14 @@ rtkit_setpriority_nice(pid_t thread, int nice_level) pthread_once(&rtkit_initialize_once, rtkit_initialize); dbus_conn = get_rtkit_dbus_connection(); - if (nice < rtkit_min_nice_level) + if (nice < rtkit_min_nice_level) { nice = rtkit_min_nice_level; + } - if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn, - rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID", - DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID, - DBUS_TYPE_INVALID)) { + if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn, + rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID", + DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID, + DBUS_TYPE_INVALID)) { return SDL_FALSE; } return SDL_TRUE; @@ -232,8 +229,9 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority) pthread_once(&rtkit_initialize_once, rtkit_initialize); dbus_conn = get_rtkit_dbus_connection(); - if (priority > rtkit_max_realtime_priority) + if (priority > rtkit_max_realtime_priority) { priority = rtkit_max_realtime_priority; + } // We always perform the thread state changes necessary for rtkit. // This wastes some system calls if the state is already set but @@ -243,10 +241,10 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority) // go through to determine whether it really needs to fail or not. rtkit_initialize_realtime_thread(); - if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn, - rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID", - DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID, - DBUS_TYPE_INVALID)) { + if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn, + rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID", + DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID, + DBUS_TYPE_INVALID)) { return SDL_FALSE; } return SDL_TRUE; diff --git a/src/core/linux/SDL_udev.c b/src/core/linux/SDL_udev.c index f609ff5683..7f30dbfeb7 100644 --- a/src/core/linux/SDL_udev.c +++ b/src/core/linux/SDL_udev.c @@ -115,7 +115,7 @@ SDL_UDEV_Init(void) if (_this == NULL) { _this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this)); - if(_this == NULL) { + if (_this == NULL) { return SDL_OutOfMemory(); } @@ -323,14 +323,13 @@ SDL_UDEV_LoadLibrary(void) #endif if (_this->udev_handle == NULL) { - for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) { + for ( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) { _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]); if (_this->udev_handle != NULL) { retval = SDL_UDEV_load_syms(); if (retval < 0) { SDL_UDEV_UnloadLibrary(); - } - else { + } else { break; } } @@ -355,7 +354,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask)); value = _this->syms.udev_device_get_sysattr_value(pdev, attr); - if (!value) { + if (value == NULL) { return; } @@ -390,7 +389,7 @@ guess_device_class(struct udev_device *dev) while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) { pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL); } - if (!pdev) { + if (pdev == NULL) { return 0; } diff --git a/src/core/openbsd/SDL_wscons_kbd.c b/src/core/openbsd/SDL_wscons_kbd.c index d35162b6ad..f9eefe109a 100644 --- a/src/core/openbsd/SDL_wscons_kbd.c +++ b/src/core/openbsd/SDL_wscons_kbd.c @@ -229,14 +229,15 @@ static struct SDL_wscons_compose_tab_s { static keysym_t ksym_upcase(keysym_t ksym) { - if (ksym >= KS_f1 && ksym <= KS_f20) - return(KS_F1 - KS_f1 + ksym); + if (ksym >= KS_f1 && ksym <= KS_f20) { + return KS_F1 - KS_f1 + ksym; + } - if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff && - latin1_to_upper[ksym] != 0x00) - return(latin1_to_upper[ksym]); + if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff && latin1_to_upper[ksym] != 0x00) { + return latin1_to_upper[ksym]; + } - return(ksym); + return ksym; } static struct wscons_keycode_to_SDL { keysym_t sourcekey; @@ -410,7 +411,7 @@ static SDL_WSCONS_input_data* SDL_WSCONS_Init_Keyboard(const char* dev) #endif SDL_WSCONS_input_data* input = (SDL_WSCONS_input_data*)SDL_calloc(1, sizeof(SDL_WSCONS_input_data)); - if (!input) { + if (input == NULL) { return input; } input->fd = open(dev,O_RDWR | O_NONBLOCK | O_CLOEXEC); @@ -487,10 +488,12 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c) put_queue(input, 0xc0 | (c >> 6)); put_queue(input, 0x80 | (c & 0x3f)); } else if (c < 0x10000) { - if (c >= 0xD800 && c <= 0xF500) + if (c >= 0xD800 && c <= 0xF500) { return; - if (c == 0xFFFF) + } + if (c == 0xFFFF) { return; + } /* 1110**** 10****** 10****** */ put_queue(input, 0xe0 | (c >> 12)); put_queue(input, 0x80 | ((c >> 6) & 0x3f)); @@ -507,7 +510,9 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c) static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym) { if (KS_GROUP(ksym) == KS_GROUP_Keypad) { - if (SDL_isprint(ksym & 0xFF)) ksym &= 0xFF; + if (SDL_isprint(ksym & 0xFF)) { + ksym &= 0xFF; + } } switch(ksym) { case KS_Escape: @@ -565,7 +570,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) keysym_t *group; keysym_t ksym, result; - if (!input) return; + if (input == NULL) { + return; + } if ((n = read(input->fd, events, sizeof(events))) > 0) { n /= sizeof(struct wscons_event); for (i = 0; i < n; i++) { @@ -574,21 +581,27 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) case WSCONS_EVENT_KEY_DOWN: { switch (input->keymap.map[events[i].value].group1[0]) { case KS_Hold_Screen: { - if (input->lockheldstate[0] >= 1) break; + if (input->lockheldstate[0] >= 1) { + break; + } input->ledstate ^= LED_SCR; ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); input->lockheldstate[0] = 1; break; } case KS_Num_Lock: { - if (input->lockheldstate[1] >= 1) break; + if (input->lockheldstate[1] >= 1) { + break; + } input->ledstate ^= LED_NUM; ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); input->lockheldstate[1] = 1; break; } case KS_Caps_Lock: { - if (input->lockheldstate[2] >= 1) break; + if (input->lockheldstate[2] >= 1) { + break; + } input->ledstate ^= LED_CAP; ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); input->lockheldstate[2] = 1; @@ -596,7 +609,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) } #ifndef __NetBSD__ case KS_Mode_Lock: { - if (input->lockheldstate[3] >= 1) break; + if (input->lockheldstate[3] >= 1) { + break; + } input->ledstate ^= 1 << 4; ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); input->lockheldstate[3] = 1; @@ -604,50 +619,66 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) } #endif case KS_Shift_Lock: { - if (input->lockheldstate[4] >= 1) break; + if (input->lockheldstate[4] >= 1) { + break; + } input->ledstate ^= 1 << 5; ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); input->lockheldstate[4] = 1; break; } case KS_Shift_L: { - if (input->shiftheldstate[0]) break; + if (input->shiftheldstate[0]) { + break; + } input->shiftstate[0]++; input->shiftheldstate[0] = 1; break; } case KS_Shift_R: { - if (input->shiftheldstate[1]) break; + if (input->shiftheldstate[1]) { + break; + } input->shiftstate[0]++; input->shiftheldstate[1] = 1; break; } case KS_Alt_L: { - if (input->shiftheldstate[2]) break; + if (input->shiftheldstate[2]) { + break; + } input->shiftstate[1]++; input->shiftheldstate[2] = 1; break; } case KS_Alt_R: { - if (input->shiftheldstate[3]) break; + if (input->shiftheldstate[3]) { + break; + } input->shiftstate[1]++; input->shiftheldstate[3] = 1; break; } case KS_Control_L: { - if (input->shiftheldstate[4]) break; + if (input->shiftheldstate[4]) { + break; + } input->shiftstate[2]++; input->shiftheldstate[4] = 1; break; } case KS_Control_R: { - if (input->shiftheldstate[5]) break; + if (input->shiftheldstate[5]) { + break; + } input->shiftstate[2]++; input->shiftheldstate[5] = 1; break; } case KS_Mode_switch: { - if (input->shiftheldstate[6]) break; + if (input->shiftheldstate[6]) { + break; + } input->shiftstate[3]++; input->shiftheldstate[6] = 1; break; @@ -658,60 +689,84 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) case WSCONS_EVENT_KEY_UP: { switch(input->keymap.map[events[i].value].group1[0]) { case KS_Hold_Screen: { - if (input->lockheldstate[0]) input->lockheldstate[0] = 0; + if (input->lockheldstate[0]) { + input->lockheldstate[0] = 0; + } } break; case KS_Num_Lock: { - if (input->lockheldstate[1]) input->lockheldstate[1] = 0; + if (input->lockheldstate[1]) { + input->lockheldstate[1] = 0; + } } break; case KS_Caps_Lock: { - if (input->lockheldstate[2]) input->lockheldstate[2] = 0; + if (input->lockheldstate[2]) { + input->lockheldstate[2] = 0; + } } break; #ifndef __NetBSD__ case KS_Mode_Lock: { - if (input->lockheldstate[3]) input->lockheldstate[3] = 0; + if (input->lockheldstate[3]) { + input->lockheldstate[3] = 0; + } } break; #endif case KS_Shift_Lock: { - if (input->lockheldstate[4]) input->lockheldstate[4] = 0; + if (input->lockheldstate[4]) { + input->lockheldstate[4] = 0; + } } break; case KS_Shift_L: { input->shiftheldstate[0] = 0; - if (input->shiftstate[0]) input->shiftstate[0]--; + if (input->shiftstate[0]) { + input->shiftstate[0]--; + } break; } case KS_Shift_R: { input->shiftheldstate[1] = 0; - if (input->shiftstate[0]) input->shiftstate[0]--; + if (input->shiftstate[0]) { + input->shiftstate[0]--; + } break; } case KS_Alt_L: { input->shiftheldstate[2] = 0; - if (input->shiftstate[1]) input->shiftstate[1]--; + if (input->shiftstate[1]) { + input->shiftstate[1]--; + } break; } case KS_Alt_R: { input->shiftheldstate[3] = 0; - if (input->shiftstate[1]) input->shiftstate[1]--; + if (input->shiftstate[1]) { + input->shiftstate[1]--; + } break; } case KS_Control_L: { input->shiftheldstate[4] = 0; - if (input->shiftstate[2]) input->shiftstate[2]--; + if (input->shiftstate[2]) { + input->shiftstate[2]--; + } break; } case KS_Control_R: { input->shiftheldstate[5] = 0; - if (input->shiftstate[2]) input->shiftstate[2]--; + if (input->shiftstate[2]) { + input->shiftstate[2]--; + } break; } case KS_Mode_switch: { input->shiftheldstate[6] = 0; - if (input->shiftstate[3]) input->shiftstate[3]--; + if (input->shiftstate[3]) { + input->shiftstate[3]--; + } break; } } @@ -729,7 +784,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) else Translate_to_keycode(input, type, events[i].value); - if (type == WSCONS_EVENT_KEY_UP) continue; + if (type == WSCONS_EVENT_KEY_UP) { + continue; + } if (IS_ALTGR_MODE && !IS_CONTROL_HELD) group = &input->keymap.map[events[i].value].group2[0]; @@ -774,7 +831,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) } else result = ksym; break; } - if (result == KS_voidSymbol) continue; + if (result == KS_voidSymbol) { + continue; + } if (input->composelen > 0) { if (input->composelen == 2 && group == &input->keymap.map[events[i].value].group2[0]) { @@ -805,21 +864,24 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) if (KS_GROUP(result) == KS_GROUP_Ascii) { if (IS_CONTROL_HELD) { - if ((result >= KS_at && result <= KS_z) || result == KS_space) + if ((result >= KS_at && result <= KS_z) || result == KS_space) { result = result & 0x1f; - else if (result == KS_2) + } else if (result == KS_2) { result = 0x00; - else if (result >= KS_3 && result <= KS_7) + } else if (result >= KS_3 && result <= KS_7) { result = KS_Escape + (result - KS_3); - else if (result == KS_8) - result = KS_Delete; + } else if (result == KS_8) { + result = KS_Delete; + } } if (IS_ALT_HELD) { if (input->encoding & KB_METAESC) { Translate_to_keycode(input, WSCONS_EVENT_KEY_DOWN, KS_Escape); Translate_to_text(input, result); continue; - } else result |= 0x80; + } else { + result |= 0x80; + } } } Translate_to_text(input,result); @@ -831,7 +893,10 @@ static void updateKeyboard(SDL_WSCONS_input_data* input) void SDL_WSCONS_PumpEvents() { int i = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { updateKeyboard(inputs[i]); - if (mouseInputData != NULL) updateMouse(mouseInputData); + } + if (mouseInputData != NULL) { + updateMouse(mouseInputData); + } } diff --git a/src/core/openbsd/SDL_wscons_mouse.c b/src/core/openbsd/SDL_wscons_mouse.c index 0d6be9bd3a..0c1e6c59b0 100644 --- a/src/core/openbsd/SDL_wscons_mouse.c +++ b/src/core/openbsd/SDL_wscons_mouse.c @@ -41,7 +41,9 @@ SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse() #endif SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data)); - if (!mouseInputData) return NULL; + if (mouseInputData == NULL) { + return NULL; + } mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK | O_CLOEXEC); if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; } #ifdef WSMOUSEIO_SETMODE @@ -60,11 +62,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData) int n,i; SDL_Mouse* mouse = SDL_GetMouse(); - if ((n = read(inputData->fd, events, sizeof(events))) > 0) - { + if ((n = read(inputData->fd, events, sizeof(events))) > 0) { n /= sizeof(struct wscons_event); - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { type = events[i].type; switch(type) { @@ -127,7 +127,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData) void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data* inputData) { - if (!inputData) return; + if (inputData == NULL) { + return; + } close(inputData->fd); free(inputData); } diff --git a/src/core/windows/SDL_hid.c b/src/core/windows/SDL_hid.c index d9dd04fbef..225fe703ba 100644 --- a/src/core/windows/SDL_hid.c +++ b/src/core/windows/SDL_hid.c @@ -61,9 +61,9 @@ WIN_LoadHIDDLL(void) SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps"); SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength"); SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData"); - if (!SDL_HidD_GetManufacturerString || !SDL_HidD_GetProductString || - !SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps || - !SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) { + if (SDL_HidD_GetManufacturerString == NULL || SDL_HidD_GetProductString == NULL || + SDL_HidP_GetCaps == NULL || SDL_HidP_GetButtonCaps == NULL || + SDL_HidP_GetValueCaps == NULL || SDL_HidP_MaxDataListLength == NULL || SDL_HidP_GetData == NULL) { WIN_UnloadHIDDLL(); return -1; } diff --git a/src/core/windows/SDL_immdevice.c b/src/core/windows/SDL_immdevice.c index 335596d95d..f55a31b874 100644 --- a/src/core/windows/SDL_immdevice.c +++ b/src/core/windows/SDL_immdevice.c @@ -136,7 +136,7 @@ SDL_IMMDevice_Add(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTEN } devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist)); - if (!devidlist) { + if (devidlist == NULL) { return; /* oh well. */ } @@ -442,7 +442,7 @@ EnumerateEndpointsForFlow(const SDL_bool iscapture) } items = (EndpointItem *)SDL_calloc(total, sizeof(EndpointItem)); - if (!items) { + if (items == NULL) { return; /* oh well. */ } diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index 5626258e8f..9cc0c2b02a 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -290,7 +290,7 @@ WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid) } strw = (WCHAR *) SDL_malloc(len + sizeof (WCHAR)); - if (!strw) { + if (strw == NULL) { RegCloseKey(hkey); return WIN_StringToUTF8(name); /* oh well. */ } @@ -313,13 +313,13 @@ WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid) BOOL WIN_IsEqualGUID(const GUID * a, const GUID * b) { - return (SDL_memcmp(a, b, sizeof (*a)) == 0); + return SDL_memcmp(a, b, sizeof(*a)) == 0; } BOOL WIN_IsEqualIID(REFIID a, REFIID b) { - return (SDL_memcmp(a, b, sizeof (*a)) == 0); + return SDL_memcmp(a, b, sizeof(*a)) == 0; } void diff --git a/src/core/windows/SDL_xinput.c b/src/core/windows/SDL_xinput.c index 8b9c26ef92..675ed608cc 100644 --- a/src/core/windows/SDL_xinput.c +++ b/src/core/windows/SDL_xinput.c @@ -110,13 +110,13 @@ WIN_LoadXInputDLL(void) /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, (LPCSTR)100); - if (!SDL_XInputGetState) { + if (SDL_XInputGetState == NULL) { SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetState"); } SDL_XInputSetState = (XInputSetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputSetState"); SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetCapabilities"); SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetBatteryInformation" ); - if (!SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities) { + if (SDL_XInputGetState == NULL || SDL_XInputSetState == NULL || SDL_XInputGetCapabilities == NULL) { WIN_UnloadXInputDLL(); return -1; } diff --git a/src/core/winrt/SDL_winrtapp_common.cpp b/src/core/winrt/SDL_winrtapp_common.cpp index 610aba91cf..f29f815c04 100644 --- a/src/core/winrt/SDL_winrtapp_common.cpp +++ b/src/core/winrt/SDL_winrtapp_common.cpp @@ -47,16 +47,11 @@ SDL_WinRTGetDeviceFamily() #if NTDDI_VERSION >= NTDDI_WIN10 /* !!! FIXME: I have no idea if this is the right test. This is a UWP API, I think. Older windows should...just return "mobile"? I don't know. --ryan. */ Platform::String^ deviceFamily = Windows::System::Profile::AnalyticsInfo::VersionInfo->DeviceFamily; - if (deviceFamily->Equals("Windows.Desktop")) - { + if (deviceFamily->Equals("Windows.Desktop")) { return SDL_WINRT_DEVICEFAMILY_DESKTOP; - } - else if (deviceFamily->Equals("Windows.Mobile")) - { + } else if (deviceFamily->Equals("Windows.Mobile")) { return SDL_WINRT_DEVICEFAMILY_MOBILE; - } - else if (deviceFamily->Equals("Windows.Xbox")) - { + } else if (deviceFamily->Equals("Windows.Xbox")) { return SDL_WINRT_DEVICEFAMILY_XBOX; } #endif diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp index db7ccfdf61..6b2cf2ac69 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp @@ -99,8 +99,7 @@ IFrameworkView^ SDLApplicationSource::CreateView() // SDL_WinRTGlobalApp more than once. SDL_assert(!SDL_WinRTGlobalApp); SDL_WinRTApp ^ app = ref new SDL_WinRTApp(); - if (!SDL_WinRTGlobalApp) - { + if (!SDL_WinRTGlobalApp) { SDL_WinRTGlobalApp = app; } return app; @@ -348,13 +347,12 @@ void SDL_WinRTApp::Load(Platform::String^ entryPoint) void SDL_WinRTApp::Run() { SDL_SetMainReady(); - if (WINRT_SDLAppEntryPoint) - { + if (WINRT_SDLAppEntryPoint) { // TODO, WinRT: pass the C-style main() a reasonably realistic // representation of command line arguments. int argc = 1; char **argv = (char **)SDL_malloc(2 * sizeof(*argv)); - if (!argv) { + if (argv == NULL) { return; } argv[0] = SDL_strdup("WinRTApp"); diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index 7047be49d3..05a30f3c59 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -320,8 +320,9 @@ CPU_haveAltiVec(void) int hasVectorUnit = 0; size_t length = sizeof(hasVectorUnit); int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); - if (0 == error) + if (0 == error) { altivec = (hasVectorUnit != 0); + } #elif defined(__FreeBSD__) && defined(__powerpc__) unsigned long cpufeatures = 0; elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures)); @@ -362,13 +363,10 @@ CPU_haveARMSIMD(void) int fd; fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC); - if (fd >= 0) - { + if (fd >= 0) { Elf32_auxv_t aux; - while (read(fd, &aux, sizeof aux) == sizeof aux) - { - if (aux.a_type == AT_PLATFORM) - { + while (read(fd, &aux, sizeof aux) == sizeof aux) { + if (aux.a_type == AT_PLATFORM) { const char *plat = (const char *) aux.a_un.a_val; if (plat) { arm_simd = SDL_strncmp(plat, "v6l", 3) == 0 || @@ -387,16 +385,19 @@ CPU_haveARMSIMD(void) { _kernel_swi_regs regs; regs.r[0] = 0; - if (_kernel_swi(OS_PlatformFeatures, ®s, ®s) != NULL) + if (_kernel_swi(OS_PlatformFeatures, ®s, ®s) != NULL) { return 0; + } - if (!(regs.r[0] & (1<<31))) + if (!(regs.r[0] & (1 << 31))) { return 0; + } regs.r[0] = 34; regs.r[1] = 29; - if (_kernel_swi(OS_PlatformFeatures, ®s, ®s) != NULL) + if (_kernel_swi(OS_PlatformFeatures, ®s, ®s) != NULL) { return 0; + } return regs.r[0]; } @@ -418,8 +419,7 @@ readProcAuxvForNeon(void) int fd; fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC); - if (fd >= 0) - { + if (fd >= 0) { Elf32_auxv_t aux; while (read(fd, &aux, sizeof (aux)) == sizeof (aux)) { if (aux.a_type == AT_HWCAP) { @@ -465,11 +465,12 @@ CPU_haveNEON(void) return 1; /* OpenBSD only supports ARMv7 CPUs that have NEON. */ #elif defined(HAVE_ELF_AUX_INFO) unsigned long hasneon = 0; - if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0) + if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0) { return 0; - return ((hasneon & HWCAP_NEON) == HWCAP_NEON); + } + return (hasneon & HWCAP_NEON) == HWCAP_NEON; #elif (defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_GETAUXVAL) - return ((getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON); + return (getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON; #elif defined(__LINUX__) return readProcAuxvForNeon(); #elif defined(__ANDROID__) @@ -538,7 +539,7 @@ CPU_have3DNow(void) cpuid(0x80000000, a, b, c, d); if (a >= 0x80000001) { cpuid(0x80000001, a, b, c, d); - return (d & 0x80000000); + return d & 0x80000000; } } return 0; @@ -611,7 +612,7 @@ CPU_haveAVX2(void) int a, b, c, d; (void) a; (void) b; (void) c; (void) d; /* compiler warnings... */ cpuid(7, a, b, c, d); - return (b & 0x00000020); + return b & 0x00000020; } return 0; } @@ -631,7 +632,7 @@ CPU_haveAVX512F(void) int a, b, c, d; (void) a; (void) b; (void) c; (void) d; /* compiler warnings... */ cpuid(7, a, b, c, d); - return (b & 0x00010000); + return b & 0x00010000; } return 0; } @@ -815,10 +816,10 @@ SDL_GetCPUCacheLineSize(void) (void) a; (void) b; (void) c; (void) d; if (SDL_strcmp(cpuType, "GenuineIntel") == 0 || SDL_strcmp(cpuType, "CentaurHauls") == 0 || SDL_strcmp(cpuType, " Shanghai ") == 0) { cpuid(0x00000001, a, b, c, d); - return (((b >> 8) & 0xff) * 8); + return ((b >> 8) & 0xff) * 8; } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0 || SDL_strcmp(cpuType, "HygonGenuine") == 0) { cpuid(0x80000005, a, b, c, d); - return (c & 0xff); + return c & 0xff; } else { /* Just make a guess here... */ return SDL_CACHELINE_SIZE; diff --git a/src/events/SDL_clipboardevents.c b/src/events/SDL_clipboardevents.c index d19d7fb257..c32f2aa7c8 100644 --- a/src/events/SDL_clipboardevents.c +++ b/src/events/SDL_clipboardevents.c @@ -39,7 +39,7 @@ SDL_SendClipboardUpdate(void) posted = (SDL_PushEvent(&event) > 0); } - return (posted); + return posted; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_displayevents.c b/src/events/SDL_displayevents.c index b6e14699a9..c977dea19c 100644 --- a/src/events/SDL_displayevents.c +++ b/src/events/SDL_displayevents.c @@ -30,7 +30,7 @@ SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1) { int posted; - if (!display) { + if (display == NULL) { return 0; } switch (displayevent) { @@ -53,7 +53,7 @@ SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1) posted = (SDL_PushEvent(&event) > 0); } - return (posted); + return posted; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 0b3a6823bd..ef1940aa36 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -553,7 +553,7 @@ SDL_StartEventLoop(void) } SDL_LockMutex(SDL_EventQ.lock); - if (!SDL_event_watchers_lock) { + if (SDL_event_watchers_lock == NULL) { SDL_event_watchers_lock = SDL_CreateMutex(); if (SDL_event_watchers_lock == NULL) { SDL_UnlockMutex(SDL_EventQ.lock); @@ -594,7 +594,7 @@ SDL_AddEvent(SDL_Event * event) if (SDL_EventQ.free == NULL) { entry = (SDL_EventEntry *)SDL_malloc(sizeof(*entry)); - if (!entry) { + if (entry == NULL) { return 0; } } else { @@ -669,7 +669,7 @@ static int SDL_SendWakeupEvent() { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this || !_this->SendWakeupEvent) { + if (_this == NULL || !_this->SendWakeupEvent) { return 0; } if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) { @@ -705,7 +705,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action if (action == SDL_GETEVENT) { SDL_SetError("The event system has been shut down"); } - return (-1); + return -1; } if (action == SDL_ADDEVENT) { for (i = 0; i < numevents; ++i) { @@ -728,7 +728,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action SDL_EventQ.wmmsg_used = NULL; } - for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) { + for (entry = SDL_EventQ.head; entry && (events == NULL || used < numevents); entry = next) { next = entry->next; type = entry->event.type; if (minType <= type && type <= maxType) { @@ -761,7 +761,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action /* Skip it, we don't want to include it */ continue; } - if (!events || action != SDL_GETEVENT) { + if (events == NULL || action != SDL_GETEVENT) { ++sentinels_expected; } if (SDL_AtomicGet(&SDL_sentinel_pending) > sentinels_expected) { @@ -784,7 +784,7 @@ SDL_PeepEventsInternal(SDL_Event * events, int numevents, SDL_eventaction action SDL_SendWakeupEvent(); } - return (used); + return used; } int SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action, @@ -796,13 +796,13 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action, SDL_bool SDL_HasEvent(Uint32 type) { - return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0); + return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0; } SDL_bool SDL_HasEvents(Uint32 minType, Uint32 maxType) { - return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0); + return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0; } void @@ -1125,7 +1125,7 @@ SDL_PushEvent(SDL_Event * event) event->common.timestamp = SDL_GetTicks(); if (SDL_EventOK.callback || SDL_event_watchers_count > 0) { - if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) { + if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) { if (SDL_EventOK.callback && !SDL_EventOK.callback(SDL_EventOK.userdata, event)) { if (SDL_event_watchers_lock) { SDL_UnlockMutex(SDL_event_watchers_lock); @@ -1176,7 +1176,7 @@ SDL_PushEvent(SDL_Event * event) void SDL_SetEventFilter(SDL_EventFilter filter, void *userdata) { - if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) { + if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) { /* Set filter and discard pending events */ SDL_EventOK.callback = filter; SDL_EventOK.userdata = userdata; @@ -1193,7 +1193,7 @@ SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata) { SDL_EventWatcher event_ok; - if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) { + if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) { event_ok = SDL_EventOK; if (SDL_event_watchers_lock) { @@ -1215,7 +1215,7 @@ SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata) void SDL_AddEventWatch(SDL_EventFilter filter, void *userdata) { - if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) { + if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) { SDL_EventWatcher *event_watchers; event_watchers = SDL_realloc(SDL_event_watchers, (SDL_event_watchers_count + 1) * sizeof(*event_watchers)); @@ -1239,7 +1239,7 @@ SDL_AddEventWatch(SDL_EventFilter filter, void *userdata) void SDL_DelEventWatch(SDL_EventFilter filter, void *userdata) { - if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) { + if (SDL_event_watchers_lock == NULL || SDL_LockMutex(SDL_event_watchers_lock) == 0) { int i; for (i = 0; i < SDL_event_watchers_count; ++i) { @@ -1352,7 +1352,7 @@ SDL_SendAppEvent(SDL_EventType eventType) event.type = eventType; posted = (SDL_PushEvent(&event) > 0); } - return (posted); + return posted; } int @@ -1369,7 +1369,7 @@ SDL_SendSysWMEvent(SDL_SysWMmsg * message) posted = (SDL_PushEvent(&event) > 0); } /* Update internal event state */ - return (posted); + return posted; } int diff --git a/src/events/SDL_gesture.c b/src/events/SDL_gesture.c index 3561156458..43ff2ddd7f 100644 --- a/src/events/SDL_gesture.c +++ b/src/events/SDL_gesture.c @@ -90,15 +90,18 @@ static void PrintPath(SDL_FloatPoint *path) int SDL_RecordGesture(SDL_TouchID touchId) { int i; - if (touchId < 0) recordAll = SDL_TRUE; + if (touchId < 0) { + recordAll = SDL_TRUE; + } for (i = 0; i < SDL_numGestureTouches; i++) { if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) { SDL_gestureTouch[i].recording = SDL_TRUE; - if (touchId >= 0) + if (touchId >= 0) { return 1; + } } } - return (touchId < 0); + return touchId < 0; } void SDL_GestureQuit() @@ -193,7 +196,7 @@ static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* p (SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate, (index + 1) * sizeof(SDL_DollarTemplate)); - if (!dollarTemplate) { + if (dollarTemplate == NULL) { return SDL_OutOfMemory(); } inTouch->dollarTemplate = dollarTemplate; @@ -211,12 +214,15 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path) int index = -1; int i = 0; if (inTouch == NULL) { - if (SDL_numGestureTouches == 0) return SDL_SetError("no gesture touch devices registered"); + if (SDL_numGestureTouches == 0) { + return SDL_SetError("no gesture touch devices registered"); + } for (i = 0; i < SDL_numGestureTouches; i++) { inTouch = &SDL_gestureTouch[i]; index = SDL_AddDollarGesture_one(inTouch, path); - if (index < 0) + if (index < 0) { return -1; + } } /* Use the index of the last one added. */ return index; @@ -228,7 +234,9 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) { int i,loaded = 0; SDL_GestureTouch *touch = NULL; - if (src == NULL) return 0; + if (src == NULL) { + return 0; + } if (touchId >= 0) { for (i = 0; i < SDL_numGestureTouches; i++) { if (SDL_gestureTouch[i].id == touchId) { @@ -260,10 +268,10 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) if (touchId >= 0) { /* printf("Adding loaded gesture to 1 touch\n"); */ - if (SDL_AddDollarGesture(touch, templ.path) >= 0) + if (SDL_AddDollarGesture(touch, templ.path) >= 0) { loaded++; - } - else { + } + } else { /* printf("Adding to: %i touches\n",SDL_numGestureTouches); */ for (i = 0; i < SDL_numGestureTouches; i++) { touch = &SDL_gestureTouch[i]; @@ -292,7 +300,7 @@ static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+ (p.y-templ[i].y)*(p.y-templ[i].y))); } - return dist/DOLLARNPOINTS; + return dist / DOLLARNPOINTS; } @@ -316,8 +324,7 @@ static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) f2 = f1; x1 = (float)(PHI*ta + (1-PHI)*tb); f1 = dollarDifference(points,templ,x1); - } - else { + } else { ta = x1; x1 = x2; f1 = f2; @@ -331,7 +338,7 @@ static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) else if (f1 > f2) printf("Min angle (x2): %f\n",x2); */ - return SDL_min(f1,f2); + return SDL_min(f1, f2); } /* DollarPath contains raw points, plus (possibly) the calculated length */ @@ -412,10 +419,18 @@ static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points, SD (py - centroid.y)*SDL_cos(ang) + centroid.y); - if (points[i].x < xmin) xmin = points[i].x; - if (points[i].x > xmax) xmax = points[i].x; - if (points[i].y < ymin) ymin = points[i].y; - if (points[i].y > ymax) ymax = points[i].y; + if (points[i].x < xmin) { + xmin = points[i].x; + } + if (points[i].x > xmax) { + xmax = points[i].x; + } + if (points[i].y < ymin) { + ymin = points[i].y; + } + if (points[i].y > ymax) { + ymax = points[i].y; + } } /* Scale points to DOLLARSIZE, and translate to the origin */ @@ -455,7 +470,7 @@ int SDL_GestureAddTouch(SDL_TouchID touchId) (SDL_numGestureTouches + 1) * sizeof(SDL_GestureTouch)); - if (!gestureTouch) { + if (gestureTouch == NULL) { return SDL_OutOfMemory(); } @@ -496,8 +511,9 @@ static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id) int i; for (i = 0; i < SDL_numGestureTouches; i++) { /* printf("%i ?= %i\n",SDL_gestureTouch[i].id,id); */ - if (SDL_gestureTouch[i].id == id) + if (SDL_gestureTouch[i].id == id) { return &SDL_gestureTouch[i]; + } } return NULL; } @@ -569,7 +585,9 @@ void SDL_GestureProcessEvent(SDL_Event* event) SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId); /* Shouldn't be possible */ - if (inTouch == NULL) return; + if (inTouch == NULL) { + return; + } x = event->tfinger.x; y = event->tfinger.y; @@ -589,26 +607,24 @@ void SDL_GestureProcessEvent(SDL_Event* event) /* PrintPath(path); */ if (recordAll) { index = SDL_AddDollarGesture(NULL,path); - for (i = 0; i < SDL_numGestureTouches; i++) + for (i = 0; i < SDL_numGestureTouches; i++) { SDL_gestureTouch[i].recording = SDL_FALSE; - } - else { + } + } else { index = SDL_AddDollarGesture(inTouch,path); } if (index >= 0) { SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash); - } - else { + } else { SDL_SendDollarRecord(inTouch,-1); } - } - else { + } else { int bestTempl; float error; error = dollarRecognize(&inTouch->dollarPath, &bestTempl,inTouch); - if (bestTempl >= 0){ + if (bestTempl >= 0) { /* Send Event */ unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash; SDL_SendGestureDollar(inTouch,gestureId,error); @@ -623,8 +639,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)- y)/inTouch->numDownFingers; } - } - else if (event->type == SDL_FINGERMOTION) { + } else if (event->type == SDL_FINGERMOTION) { float dx = event->tfinger.dx; float dy = event->tfinger.dy; #if defined(ENABLE_DOLLAR) @@ -669,7 +684,12 @@ void SDL_GestureProcessEvent(SDL_Event* event) dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y); dDist = (Dist - lDist); - if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */ + if (lDist == 0) { + /* To avoid impossible values */ + dDist = 0; + dtheta = 0; + } + /* inTouch->gestureLast[j].dDist = dDist; inTouch->gestureLast[j].dtheta = dtheta; @@ -682,8 +702,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist); printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */ SDL_SendGestureMulti(inTouch,dtheta,dDist); - } - else { + } else { /* inTouch->gestureLast[j].dDist = 0; inTouch->gestureLast[j].dtheta = 0; inTouch->gestureLast[j].cv.x = 0; @@ -693,8 +712,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) inTouch->gestureLast[j].f.p.y = y; break; pressure? */ - } - else if (event->type == SDL_FINGERDOWN) { + } else if (event->type == SDL_FINGERDOWN) { inTouch->numDownFingers++; inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+ diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index 9614e0c222..5723787cbc 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -751,7 +751,7 @@ SDL_SetKeyboardFocus(SDL_Window * window) { SDL_Keyboard *keyboard = &SDL_keyboard; - if (keyboard->focus && !window) { + if (keyboard->focus && window == NULL) { /* We won't get anymore keyboard messages, so reset keyboard state */ SDL_ResetKeyboard(); } @@ -760,7 +760,7 @@ SDL_SetKeyboardFocus(SDL_Window * window) if (keyboard->focus && keyboard->focus != window) { /* new window shouldn't think it has mouse captured. */ - SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE)); + SDL_assert(window == NULL || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE)); /* old window must lose an existing mouse capture. */ if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) { @@ -936,7 +936,7 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode, SD SDL_MinimizeWindow(keyboard->focus); } - return (posted); + return posted; } int @@ -1042,7 +1042,7 @@ SDL_SendKeyboardText(const char *text) posted |= (SDL_PushEvent(&event) > 0); } } - return (posted); + return posted; } int @@ -1073,7 +1073,7 @@ SDL_SendEditingText(const char *text, int start, int length) posted = (SDL_PushEvent(&event) > 0); } - return (posted); + return posted; } void @@ -1097,7 +1097,7 @@ SDL_GetModState(void) { SDL_Keyboard *keyboard = &SDL_keyboard; - return (SDL_Keymod) keyboard->modstate; + return (SDL_Keymod)keyboard->modstate; } void @@ -1180,7 +1180,7 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name) { int i; - if (!name || !*name) { + if (name == NULL || !*name) { SDL_InvalidParamError("name"); return SDL_SCANCODE_UNKNOWN; } @@ -1205,8 +1205,7 @@ SDL_GetKeyName(SDL_Keycode key) char *end; if (key & SDLK_SCANCODE_MASK) { - return - SDL_GetScancodeName((SDL_Scancode) (key & ~SDLK_SCANCODE_MASK)); + return SDL_GetScancodeName((SDL_Scancode)(key & ~SDLK_SCANCODE_MASK)); } switch (key) { diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 0e169d769a..bfb62e13b4 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -216,7 +216,7 @@ SDL_MouseInit(void) mouse->cursor_shown = SDL_TRUE; - return (0); + return 0; } void @@ -453,7 +453,7 @@ SDL_SetMouseSystemScale(int num_values, const float *values) } v = (float *)SDL_realloc(mouse->system_scale_values, num_values * sizeof(*values)); - if (!v) { + if (v == NULL) { return SDL_OutOfMemory(); } SDL_memcpy(v, values, num_values * sizeof(*values)); @@ -676,7 +676,7 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button) if (button >= mouse->num_clickstates) { int i, count = button + 1; SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate)); - if (!clickstate) { + if (clickstate == NULL) { return NULL; } mouse->clickstate = clickstate; @@ -699,7 +699,7 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state SDL_MouseInputSource *source; source = GetMouseInputSource(mouse, mouseID); - if (!source) { + if (source == NULL) { return 0; } buttonstate = source->buttonstate; @@ -996,10 +996,10 @@ SDL_GetGlobalMouseState(int *x, int *y) int tmpx, tmpy; /* make sure these are never NULL for the backend implementations... */ - if (!x) { + if (x == NULL) { x = &tmpx; } - if (!y) { + if (y == NULL) { y = &tmpy; } @@ -1259,7 +1259,7 @@ SDL_CreateCursor(const Uint8 * data, const Uint8 * mask, 0x0000FF00, 0x000000FF, 0xFF000000); - if (!surface) { + if (surface == NULL) { return NULL; } for (y = 0; y < h; ++y) { @@ -1293,7 +1293,7 @@ SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y) SDL_Surface *temp = NULL; SDL_Cursor *cursor; - if (!surface) { + if (surface == NULL) { SDL_InvalidParamError("surface"); return NULL; } @@ -1312,7 +1312,7 @@ SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y) if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) { temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0); - if (!temp) { + if (temp == NULL) { return NULL; } surface = temp; @@ -1368,7 +1368,7 @@ SDL_SetCursor(SDL_Cursor * cursor) break; } } - if (!found) { + if (found == NULL) { SDL_SetError("Cursor not associated with the current mouse"); return; } @@ -1398,7 +1398,7 @@ SDL_GetCursor(void) { SDL_Mouse *mouse = SDL_GetMouse(); - if (!mouse) { + if (mouse == NULL) { return NULL; } return mouse->cur_cursor; @@ -1409,7 +1409,7 @@ SDL_GetDefaultCursor(void) { SDL_Mouse *mouse = SDL_GetMouse(); - if (!mouse) { + if (mouse == NULL) { return NULL; } return mouse->def_cursor; @@ -1421,7 +1421,7 @@ SDL_FreeCursor(SDL_Cursor * cursor) SDL_Mouse *mouse = SDL_GetMouse(); SDL_Cursor *curr, *prev; - if (!cursor) { + if (cursor == NULL) { return; } @@ -1455,7 +1455,7 @@ SDL_ShowCursor(int toggle) SDL_Mouse *mouse = SDL_GetMouse(); SDL_bool shown; - if (!mouse) { + if (mouse == NULL) { return 0; } diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 0a429fc7c7..56fabb0285 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -43,7 +43,7 @@ static SDL_TouchID track_touchid; int SDL_TouchInit(void) { - return (0); + return 0; } int @@ -149,7 +149,7 @@ SDL_Finger * SDL_GetTouchFinger(SDL_TouchID touchID, int index) { SDL_Touch *touch = SDL_GetTouch(touchID); - if (!touch) { + if (touch == NULL) { return NULL; } if (index < 0 || index >= touch->num_fingers) { @@ -173,7 +173,7 @@ SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name) /* Add the touch to the list of touch */ touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices, (SDL_num_touch + 1) * sizeof(*touchDevices)); - if (!touchDevices) { + if (touchDevices == NULL) { return SDL_OutOfMemory(); } @@ -211,7 +211,7 @@ SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float p if (touch->num_fingers == touch->max_fingers) { SDL_Finger **new_fingers; new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers)); - if (!new_fingers) { + if (new_fingers == NULL) { return SDL_OutOfMemory(); } touch->fingers = new_fingers; @@ -256,7 +256,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window, SDL_Mouse *mouse; SDL_Touch* touch = SDL_GetTouch(id); - if (!touch) { + if (touch == NULL) { return -1; } @@ -278,10 +278,18 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window, if (finger_touching == SDL_FALSE) { int pos_x = (int)(x * (float)window->w); int pos_y = (int)(y * (float)window->h); - if (pos_x < 0) pos_x = 0; - if (pos_x > window->w - 1) pos_x = window->w - 1; - if (pos_y < 0) pos_y = 0; - if (pos_y > window->h - 1) pos_y = window->h - 1; + if (pos_x < 0) { + pos_x = 0; + } + if (pos_x > window->w - 1) { + pos_x = window->w - 1; + } + if (pos_y < 0) { + pos_y = 0; + } + if (pos_y > window->h - 1) { + pos_y = window->h - 1; + } SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); } @@ -341,7 +349,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window, posted = (SDL_PushEvent(&event) > 0); } } else { - if (!finger) { + if (finger == NULL) { /* This finger is already up */ return 0; } @@ -378,7 +386,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window, float xrel, yrel, prel; touch = SDL_GetTouch(id); - if (!touch) { + if (touch == NULL) { return -1; } @@ -393,10 +401,18 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window, if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) { int pos_x = (int)(x * (float)window->w); int pos_y = (int)(y * (float)window->h); - if (pos_x < 0) pos_x = 0; - if (pos_x > window->w - 1) pos_x = window->w - 1; - if (pos_y < 0) pos_y = 0; - if (pos_y > window->h - 1) pos_y = window->h - 1; + if (pos_x < 0) { + pos_x = 0; + } + if (pos_x > window->w - 1) { + pos_x = window->w - 1; + } + if (pos_y < 0) { + pos_y = 0; + } + if (pos_y > window->h - 1) { + pos_y = window->h - 1; + } SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); } } @@ -413,7 +429,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window, } finger = SDL_GetFinger(touch,fingerid); - if (!finger) { + if (finger == NULL) { return SDL_SendTouch(id, fingerid, window, SDL_TRUE, x, y, pressure); } @@ -465,7 +481,7 @@ SDL_DelTouch(SDL_TouchID id) index = SDL_GetTouchIndex(id); touch = SDL_GetTouch(id); - if (!touch) { + if (touch == NULL) { return; } diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index 1d4de3e3d5..87f12a59ec 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -86,7 +86,7 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1, { int posted; - if (!window) { + if (window == NULL) { return 0; } switch (windowevent) { diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index f9965aa5f7..8573b74752 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -75,8 +75,9 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode) DWORD must_exist, truncate; int a_mode; - if (!context) - return -1; /* failed (invalid call) */ + if (context == NULL) { + return -1; /* failed (invalid call) */ + } context->hidden.windowsio.h = INVALID_HANDLE_VALUE; /* mark this as unusable */ context->hidden.windowsio.buffer.data = NULL; @@ -98,8 +99,10 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode) w_right = (a_mode || SDL_strchr(mode, '+') || truncate) ? GENERIC_WRITE : 0; - if (!r_right && !w_right) /* inconsistent mode */ - return -1; /* failed (invalid call) */ + if (!r_right && !w_right) { + return -1; /* inconsistent mode */ + } + /* failed (invalid call) */ context->hidden.windowsio.buffer.data = (char *) SDL_malloc(READAHEAD_BUFFER_SIZE); @@ -143,7 +146,7 @@ windows_file_size(SDL_RWops * context) { LARGE_INTEGER size; - if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) { + if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) { return SDL_SetError("windows_file_size: invalid context/file not opened"); } @@ -160,7 +163,7 @@ windows_file_seek(SDL_RWops * context, Sint64 offset, int whence) DWORD windowswhence; LARGE_INTEGER windowsoffset; - if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) { + if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) { return SDL_SetError("windows_file_seek: invalid context/file not opened"); } @@ -201,7 +204,7 @@ windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) total_need = size * maxnum; - if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !total_need) { + if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !total_need) { return 0; } @@ -242,7 +245,7 @@ windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) } total_read += byte_read; } - return (total_read / size); + return total_read / size; } static size_t SDLCALL @@ -256,7 +259,7 @@ windows_file_write(SDL_RWops * context, const void *ptr, size_t size, total_bytes = size * num; - if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !size || !total_bytes) { + if (context == NULL || context->hidden.windowsio.h == INVALID_HANDLE_VALUE || !size || !total_bytes) { return 0; } @@ -509,7 +512,7 @@ mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) SDL_memcpy(ptr, context->hidden.mem.here, total_bytes); context->hidden.mem.here += total_bytes; - return (total_bytes / size); + return total_bytes / size; } static size_t SDLCALL @@ -546,7 +549,7 @@ SDL_RWops * SDL_RWFromFile(const char *file, const char *mode) { SDL_RWops *rwops = NULL; - if (!file || !*file || !mode || !*mode) { + if (file == NULL || !*file || mode == NULL || !*mode) { SDL_SetError("SDL_RWFromFile(): No file or no mode specified"); return NULL; } @@ -579,8 +582,10 @@ SDL_RWFromFile(const char *file, const char *mode) /* Try to open the file from the asset system */ rwops = SDL_AllocRW(); - if (!rwops) - return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ + if (rwops == NULL) { + return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ + } + if (Android_JNI_FileOpen(rwops, file, mode) < 0) { SDL_FreeRW(rwops); return NULL; @@ -594,8 +599,10 @@ SDL_RWFromFile(const char *file, const char *mode) #elif defined(__WIN32__) || defined(__GDK__) rwops = SDL_AllocRW(); - if (!rwops) - return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ + if (rwops == NULL) { + return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ + } + if (windows_file_open(rwops, file, mode) < 0) { SDL_FreeRW(rwops); return NULL; @@ -635,7 +642,7 @@ SDL_RWops * SDL_RWFromMem(void *mem, int size) { SDL_RWops *rwops = NULL; - if (!mem) { + if (mem == NULL) { SDL_InvalidParamError("mem"); return rwops; } @@ -663,7 +670,7 @@ SDL_RWops * SDL_RWFromConstMem(const void *mem, int size) { SDL_RWops *rwops = NULL; - if (!mem) { + if (mem == NULL) { SDL_InvalidParamError("mem"); return rwops; } @@ -716,7 +723,7 @@ SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc) size_t size_read, size_total; void *data = NULL, *newdata; - if (!src) { + if (src == NULL) { SDL_InvalidParamError("src"); return NULL; } @@ -732,7 +739,7 @@ SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc) if ((((Sint64)size_total) + FILE_CHUNK_SIZE) > size) { size = (size_total + FILE_CHUNK_SIZE); newdata = SDL_realloc(data, (size_t)(size + 1)); - if (!newdata) { + if (newdata == NULL) { SDL_free(data); data = NULL; SDL_OutOfMemory(); @@ -870,49 +877,49 @@ SDL_ReadBE64(SDL_RWops * src) size_t SDL_WriteU8(SDL_RWops * dst, Uint8 value) { - return SDL_RWwrite(dst, &value, sizeof (value), 1); + return SDL_RWwrite(dst, &value, sizeof(value), 1); } size_t SDL_WriteLE16(SDL_RWops * dst, Uint16 value) { const Uint16 swapped = SDL_SwapLE16(value); - return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); + return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1); } size_t SDL_WriteBE16(SDL_RWops * dst, Uint16 value) { const Uint16 swapped = SDL_SwapBE16(value); - return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); + return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1); } size_t SDL_WriteLE32(SDL_RWops * dst, Uint32 value) { const Uint32 swapped = SDL_SwapLE32(value); - return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); + return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1); } size_t SDL_WriteBE32(SDL_RWops * dst, Uint32 value) { const Uint32 swapped = SDL_SwapBE32(value); - return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); + return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1); } size_t SDL_WriteLE64(SDL_RWops * dst, Uint64 value) { const Uint64 swapped = SDL_SwapLE64(value); - return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); + return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1); } size_t SDL_WriteBE64(SDL_RWops * dst, Uint64 value) { const Uint64 swapped = SDL_SwapBE64(value); - return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1); + return SDL_RWwrite(dst, &swapped, sizeof(swapped), 1); } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/filesystem/android/SDL_sysfilesystem.c b/src/filesystem/android/SDL_sysfilesystem.c index 99cd97db09..8943998037 100644 --- a/src/filesystem/android/SDL_sysfilesystem.c +++ b/src/filesystem/android/SDL_sysfilesystem.c @@ -44,7 +44,7 @@ SDL_GetPrefPath(const char *org, const char *app) if (path) { size_t pathlen = SDL_strlen(path)+2; char *fullpath = (char *)SDL_malloc(pathlen); - if (!fullpath) { + if (fullpath == NULL) { SDL_OutOfMemory(); return NULL; } diff --git a/src/filesystem/emscripten/SDL_sysfilesystem.c b/src/filesystem/emscripten/SDL_sysfilesystem.c index 075c0e2648..27b95be4c3 100644 --- a/src/filesystem/emscripten/SDL_sysfilesystem.c +++ b/src/filesystem/emscripten/SDL_sysfilesystem.c @@ -45,17 +45,17 @@ SDL_GetPrefPath(const char *org, const char *app) char *ptr = NULL; size_t len = 0; - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if (!org) { + if (org == NULL) { org = ""; } len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; retval = (char *) SDL_malloc(len); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } @@ -69,8 +69,9 @@ SDL_GetPrefPath(const char *org, const char *app) for (ptr = retval+1; *ptr; ptr++) { if (*ptr == '/') { *ptr = '\0'; - if (mkdir(retval, 0700) != 0 && errno != EEXIST) + if (mkdir(retval, 0700) != 0 && errno != EEXIST) { goto error; + } *ptr = '/'; } } diff --git a/src/filesystem/haiku/SDL_sysfilesystem.cc b/src/filesystem/haiku/SDL_sysfilesystem.cc index 5faa1d239a..e2570bf59f 100644 --- a/src/filesystem/haiku/SDL_sysfilesystem.cc +++ b/src/filesystem/haiku/SDL_sysfilesystem.cc @@ -54,7 +54,7 @@ SDL_GetBasePath(void) const size_t len = SDL_strlen(str); char *retval = (char *) SDL_malloc(len + 2); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } @@ -74,11 +74,11 @@ SDL_GetPrefPath(const char *org, const char *app) const char *append = "/config/settings/"; size_t len = SDL_strlen(home); - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if (!org) { + if (org == NULL) { org = ""; } @@ -87,7 +87,7 @@ SDL_GetPrefPath(const char *org, const char *app) } len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; char *retval = (char *) SDL_malloc(len); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); } else { if (*org) { diff --git a/src/filesystem/ps2/SDL_sysfilesystem.c b/src/filesystem/ps2/SDL_sysfilesystem.c index 5b1b8c353c..a5a524d9c3 100644 --- a/src/filesystem/ps2/SDL_sysfilesystem.c +++ b/src/filesystem/ps2/SDL_sysfilesystem.c @@ -39,8 +39,9 @@ SDL_GetBasePath(void) getcwd(cwd, sizeof(cwd)); len = SDL_strlen(cwd) + 1; retval = (char *) SDL_malloc(len); - if (retval) + if (retval) { SDL_memcpy(retval, cwd, len); + } return retval; } @@ -54,15 +55,17 @@ static void recursive_mkdir(const char *dir) { snprintf(tmp, sizeof(tmp),"%s",dir); len = strlen(tmp); - if (tmp[len - 1] == '/') + if (tmp[len - 1] == '/') { tmp[len - 1] = 0; + } for (p = tmp + 1; *p; p++) { if (*p == '/') { *p = 0; // Just creating subfolders from current path - if (strstr(tmp, base) != NULL) + if (strstr(tmp, base) != NULL) { mkdir(tmp, S_IRWXU); + } *p = '/'; } @@ -78,11 +81,11 @@ SDL_GetPrefPath(const char *org, const char *app) char *retval = NULL; size_t len; char *base = SDL_GetBasePath(); - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if(!org) { + if (org == NULL) { org = ""; } diff --git a/src/filesystem/psp/SDL_sysfilesystem.c b/src/filesystem/psp/SDL_sysfilesystem.c index 28455d67eb..797c32e64e 100644 --- a/src/filesystem/psp/SDL_sysfilesystem.c +++ b/src/filesystem/psp/SDL_sysfilesystem.c @@ -50,11 +50,11 @@ SDL_GetPrefPath(const char *org, const char *app) char *retval = NULL; size_t len; char *base = SDL_GetBasePath(); - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if(!org) { + if (org == NULL) { org = ""; } diff --git a/src/filesystem/riscos/SDL_sysfilesystem.c b/src/filesystem/riscos/SDL_sysfilesystem.c index c1ef52a525..c505132bb1 100644 --- a/src/filesystem/riscos/SDL_sysfilesystem.c +++ b/src/filesystem/riscos/SDL_sysfilesystem.c @@ -36,22 +36,23 @@ SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, int filetype) { const char *const in_buf = buffer; /* = NULL if we allocate the buffer. */ - if (!buffer) { + if (buffer == NULL) { /* This matches the logic in __unixify, with an additional byte for the * extra path separator. */ buf_len = SDL_strlen(ro_path) + 14 + 1; buffer = SDL_malloc(buf_len); - if (!buffer) { + if (buffer == NULL) { SDL_OutOfMemory(); return NULL; } } if (!__unixify_std(ro_path, buffer, buf_len, filetype)) { - if (!in_buf) + if (in_buf == NULL) { SDL_free(buffer); + } SDL_SetError("Could not convert '%s' to a Unix-style path", ro_path); return NULL; @@ -90,7 +91,7 @@ canonicalisePath(const char *path, const char *pathVar) regs.r[5] = 1 - regs.r[5]; buf = SDL_malloc(regs.r[5]); - if (!buf) { + if (buf == NULL) { SDL_OutOfMemory(); return NULL; } @@ -120,8 +121,9 @@ createDirectoryRecursive(char *path) *ptr = '\0'; error = _kernel_swi(OS_File, ®s, ®s); *ptr = '.'; - if (error != NULL) + if (error != NULL) { return error; + } } } return _kernel_swi(OS_File, ®s, ®s); @@ -140,14 +142,15 @@ SDL_GetBasePath(void) } canon = canonicalisePath((const char *)regs.r[0], "Run$Path"); - if (!canon) { + if (canon == NULL) { return NULL; } /* chop off filename. */ ptr = SDL_strrchr(canon, '.'); - if (ptr != NULL) + if (ptr != NULL) { *ptr = '\0'; + } retval = SDL_unixify_std(canon, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED); SDL_free(canon); @@ -161,22 +164,22 @@ SDL_GetPrefPath(const char *org, const char *app) size_t len; _kernel_oserror *error; - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if (!org) { + if (org == NULL) { org = ""; } canon = canonicalisePath("", "Run$Path"); - if (!canon) { + if (canon == NULL) { return NULL; } len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4; dir = (char *) SDL_malloc(len); - if (!dir) { + if (dir == NULL) { SDL_OutOfMemory(); SDL_free(canon); return NULL; diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c index 5405ee633f..3e8fd9f49f 100644 --- a/src/filesystem/unix/SDL_sysfilesystem.c +++ b/src/filesystem/unix/SDL_sysfilesystem.c @@ -46,8 +46,7 @@ readSymLink(const char *path) ssize_t len = 64; ssize_t rc = -1; - while (1) - { + while (1) { char *ptr = (char *) SDL_realloc(retval, (size_t) len); if (ptr == NULL) { SDL_OutOfMemory(); @@ -80,13 +79,13 @@ static char *search_path_for_binary(const char *bin) char *start = envr; char *ptr; - if (!envr) { + if (envr == NULL) { SDL_SetError("No $PATH set"); return NULL; } envr = SDL_strdup(envr); - if (!envr) { + if (envr == NULL) { SDL_OutOfMemory(); return NULL; } @@ -135,7 +134,7 @@ SDL_GetBasePath(void) const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) { retval = SDL_strdup(fullpath); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } @@ -149,13 +148,13 @@ SDL_GetBasePath(void) if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) { char *exe, *pwddst; char *realpathbuf = (char *) SDL_malloc(PATH_MAX + 1); - if (!realpathbuf) { + if (realpathbuf == NULL) { SDL_OutOfMemory(); return NULL; } cmdline = SDL_malloc(len); - if (!cmdline) { + if (cmdline == NULL) { SDL_free(realpathbuf); SDL_OutOfMemory(); return NULL; @@ -193,7 +192,7 @@ SDL_GetBasePath(void) } } - if (!retval) { + if (retval == NULL) { SDL_free(realpathbuf); } @@ -204,7 +203,7 @@ SDL_GetBasePath(void) const char *path = getexecname(); if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */ retval = SDL_strdup(path); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } @@ -212,7 +211,7 @@ SDL_GetBasePath(void) #endif /* is a Linux-style /proc filesystem available? */ - if (!retval && (access("/proc", F_OK) == 0)) { + if (retval == NULL && (access("/proc", F_OK) == 0)) { /* !!! FIXME: after 2.0.6 ships, let's delete this code and just use the /proc/%llu version. There's no reason to have two copies of this plus all the #ifdefs. --ryan. */ @@ -251,8 +250,9 @@ SDL_GetBasePath(void) if (retval != NULL) { /* try to shrink buffer... */ char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1); - if (ptr != NULL) - retval = ptr; /* oh well if it failed. */ + if (ptr != NULL) { + retval = ptr; /* oh well if it failed. */ + } } return retval; @@ -274,18 +274,18 @@ SDL_GetPrefPath(const char *org, const char *app) char *ptr = NULL; size_t len = 0; - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if (!org) { + if (org == NULL) { org = ""; } - if (!envr) { + if (envr == NULL) { /* You end up with "$HOME/.local/share/Game Name 2" */ envr = SDL_getenv("HOME"); - if (!envr) { + if (envr == NULL) { /* we could take heroic measures with /etc/passwd, but oh well. */ SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set"); return NULL; @@ -296,12 +296,13 @@ SDL_GetPrefPath(const char *org, const char *app) } len = SDL_strlen(envr); - if (envr[len - 1] == '/') + if (envr[len - 1] == '/') { append += 1; + } len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; retval = (char *) SDL_malloc(len); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } @@ -315,8 +316,9 @@ SDL_GetPrefPath(const char *org, const char *app) for (ptr = retval+1; *ptr; ptr++) { if (*ptr == '/') { *ptr = '\0'; - if (mkdir(retval, 0700) != 0 && errno != EEXIST) + if (mkdir(retval, 0700) != 0 && errno != EEXIST) { goto error; + } *ptr = '/'; } } diff --git a/src/filesystem/vita/SDL_sysfilesystem.c b/src/filesystem/vita/SDL_sysfilesystem.c index 671cc82b62..35f0432868 100644 --- a/src/filesystem/vita/SDL_sysfilesystem.c +++ b/src/filesystem/vita/SDL_sysfilesystem.c @@ -51,11 +51,11 @@ SDL_GetPrefPath(const char *org, const char *app) char *ptr = NULL; size_t len = 0; - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if (!org) { + if (org == NULL) { org = ""; } @@ -63,7 +63,7 @@ SDL_GetPrefPath(const char *org, const char *app) len += SDL_strlen(org) + SDL_strlen(app) + 3; retval = (char *) SDL_malloc(len); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } diff --git a/src/filesystem/windows/SDL_sysfilesystem.c b/src/filesystem/windows/SDL_sysfilesystem.c index d7ef17e8e9..5de2ebf090 100644 --- a/src/filesystem/windows/SDL_sysfilesystem.c +++ b/src/filesystem/windows/SDL_sysfilesystem.c @@ -40,7 +40,7 @@ SDL_GetBasePath(void) while (SDL_TRUE) { void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR)); - if (!ptr) { + if (ptr == NULL) { SDL_free(path); SDL_OutOfMemory(); return NULL; @@ -98,11 +98,11 @@ SDL_GetPrefPath(const char *org, const char *app) size_t new_wpath_len = 0; BOOL api_result = FALSE; - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if (!org) { + if (org == NULL) { org = ""; } diff --git a/src/filesystem/winrt/SDL_sysfilesystem.cpp b/src/filesystem/winrt/SDL_sysfilesystem.cpp index 39a59ad7a4..975bf099b8 100644 --- a/src/filesystem/winrt/SDL_sysfilesystem.cpp +++ b/src/filesystem/winrt/SDL_sysfilesystem.cpp @@ -106,7 +106,7 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType) } const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType); - if (!ucs2Path) { + if (ucs2Path == NULL) { return NULL; } @@ -123,14 +123,14 @@ SDL_GetBasePath(void) size_t destPathLen; char * destPath = NULL; - if (!srcPath) { + if (srcPath == NULL) { SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError()); return NULL; } destPathLen = SDL_strlen(srcPath) + 2; destPath = (char *) SDL_malloc(destPathLen); - if (!destPath) { + if (destPath == NULL) { SDL_OutOfMemory(); return NULL; } @@ -156,16 +156,16 @@ SDL_GetPrefPath(const char *org, const char *app) size_t new_wpath_len = 0; BOOL api_result = FALSE; - if (!app) { + if (app == NULL) { SDL_InvalidParamError("app"); return NULL; } - if (!org) { + if (org == NULL) { org = ""; } srcPath = SDL_WinRTGetFSPathUNICODE(SDL_WINRT_PATH_LOCAL_FOLDER); - if ( ! srcPath) { + if (srcPath == NULL) { SDL_SetError("Unable to find a source path"); return NULL; } diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index 3f87143ca6..3c02ae65b5 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -60,8 +60,7 @@ ValidHaptic(SDL_Haptic * haptic) valid = 0; if (haptic != NULL) { hapticlist = SDL_haptics; - while ( hapticlist ) - { + while ( hapticlist ) { if (hapticlist == haptic) { valid = 1; break; @@ -123,8 +122,7 @@ SDL_HapticOpen(int device_index) /* If the haptic is already open, return it * TODO: Should we create haptic instance IDs like the Joystick API? */ - while ( hapticlist ) - { + while ( hapticlist ) { if (device_index == hapticlist->index) { haptic = hapticlist; ++haptic->ref_count; @@ -156,10 +154,12 @@ SDL_HapticOpen(int device_index) SDL_haptics = haptic; /* Disable autocenter and set gain to max. */ - if (haptic->supported & SDL_HAPTIC_GAIN) + if (haptic->supported & SDL_HAPTIC_GAIN) { SDL_HapticSetGain(haptic, 100); - if (haptic->supported & SDL_HAPTIC_AUTOCENTER) + } + if (haptic->supported & SDL_HAPTIC_AUTOCENTER) { SDL_HapticSetAutocenter(haptic, 0); + } return haptic; } @@ -184,8 +184,7 @@ SDL_HapticOpened(int device_index) opened = 0; hapticlist = SDL_haptics; /* TODO Should this use an instance ID? */ - while ( hapticlist ) - { + while ( hapticlist ) { if (hapticlist->index == (Uint8) device_index) { opened = 1; break; @@ -216,8 +215,9 @@ SDL_HapticIndex(SDL_Haptic * haptic) int SDL_MouseIsHaptic(void) { - if (SDL_SYS_HapticMouse() < 0) + if (SDL_SYS_HapticMouse() < 0) { return SDL_FALSE; + } return SDL_TRUE; } @@ -295,8 +295,7 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick) hapticlist = SDL_haptics; /* Check to see if joystick's haptic is already open */ - while ( hapticlist ) - { + while ( hapticlist ) { if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) { haptic = hapticlist; ++haptic->ref_count; @@ -362,17 +361,12 @@ SDL_HapticClose(SDL_Haptic * haptic) /* Remove from the list */ hapticlist = SDL_haptics; hapticlistprev = NULL; - while ( hapticlist ) - { - if (haptic == hapticlist) - { - if ( hapticlistprev ) - { + while ( hapticlist ) { + if (haptic == hapticlist) { + if ( hapticlistprev ) { /* unlink this entry */ hapticlistprev->next = hapticlist->next; - } - else - { + } else { SDL_haptics = haptic->next; } @@ -464,8 +458,9 @@ SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect) return -1; } - if ((haptic->supported & effect->type) != 0) + if ((haptic->supported & effect->type) != 0) { return SDL_TRUE; + } return SDL_FALSE; } @@ -646,10 +641,11 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain) max_gain = SDL_atoi(env); /* Check for sanity. */ - if (max_gain < 0) + if (max_gain < 0) { max_gain = 0; - else if (max_gain > 100) + } else if (max_gain > 100) { max_gain = 100; + } /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */ real_gain = (gain * max_gain) / 100; @@ -747,7 +743,7 @@ SDL_HapticRumbleSupported(SDL_Haptic * haptic) } /* Most things can use SINE, but XInput only has LEFTRIGHT. */ - return ((haptic->supported & (SDL_HAPTIC_SINE|SDL_HAPTIC_LEFTRIGHT)) != 0); + return (haptic->supported & (SDL_HAPTIC_SINE | SDL_HAPTIC_LEFTRIGHT)) != 0; } /* diff --git a/src/haptic/android/SDL_syshaptic.c b/src/haptic/android/SDL_syshaptic.c index 78e11c0556..47cb5f605a 100644 --- a/src/haptic/android/SDL_syshaptic.c +++ b/src/haptic/android/SDL_syshaptic.c @@ -54,13 +54,13 @@ SDL_SYS_HapticInit(void) timeout = SDL_GetTicks() + 3000; Android_JNI_PollHapticDevices(); } - return (numhaptics); + return numhaptics; } int SDL_SYS_NumHaptics(void) { - return (numhaptics); + return numhaptics; } static SDL_hapticlist_item * @@ -133,19 +133,19 @@ OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item) static SDL_hapticlist_item * OpenHapticByOrder(SDL_Haptic *haptic, int index) { - return OpenHaptic (haptic, HapticByOrder(index)); + return OpenHaptic(haptic, HapticByOrder(index)); } static SDL_hapticlist_item * OpenHapticByDevId(SDL_Haptic *haptic, int device_id) { - return OpenHaptic (haptic, HapticByDevId(device_id)); + return OpenHaptic(haptic, HapticByDevId(device_id)); } int SDL_SYS_HapticOpen(SDL_Haptic *haptic) { - return (OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0); + return OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0; } @@ -168,14 +168,14 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick) int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) { - return (OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0); + return OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0; } int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) { - return (((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0); + return ((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0; } diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index 717a07b861..869d897f5c 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -226,8 +226,7 @@ MacHaptic_MaybeAddDevice( io_object_t device ) } /* Make sure we don't already have it */ - for (item = SDL_hapticlist; item ; item = item->next) - { + for (item = SDL_hapticlist; item ; item = item->next) { if (IOObjectIsEqualTo((io_object_t) item->dev, device)) { /* Already added */ return -1; diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index fa79e8b131..0ac9865ae0 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -78,8 +78,10 @@ static SDL_hapticlist_item *SDL_hapticlist = NULL; static SDL_hapticlist_item *SDL_hapticlist_tail = NULL; static int numhaptics = 0; -#define EV_TEST(ev,f) \ - if (test_bit((ev), features)) ret |= (f); +#define EV_TEST(ev,f) \ + if (test_bit((ev), features)) { \ + ret |= (f); \ + } /* * Test whether a device has haptic properties. * Returns available properties or 0 if there are none. @@ -753,8 +755,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) /* Header */ dest->type = FF_CONSTANT; - if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1) + if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1) { return -1; + } /* Replay */ dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ? @@ -788,8 +791,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) /* Header */ dest->type = FF_PERIODIC; - if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1) + if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1) { return -1; + } /* Replay */ dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ? @@ -801,17 +805,18 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) dest->trigger.interval = CLAMP(periodic->interval); /* Periodic */ - if (periodic->type == SDL_HAPTIC_SINE) + if (periodic->type == SDL_HAPTIC_SINE) { dest->u.periodic.waveform = FF_SINE; /* !!! FIXME: put this back when we have more bits in 2.1 */ /* else if (periodic->type == SDL_HAPTIC_SQUARE) dest->u.periodic.waveform = FF_SQUARE; */ - else if (periodic->type == SDL_HAPTIC_TRIANGLE) + } else if (periodic->type == SDL_HAPTIC_TRIANGLE) { dest->u.periodic.waveform = FF_TRIANGLE; - else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP) + } else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP) { dest->u.periodic.waveform = FF_SAW_UP; - else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN) + } else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN) { dest->u.periodic.waveform = FF_SAW_DOWN; + } dest->u.periodic.period = CLAMP(periodic->period); dest->u.periodic.magnitude = periodic->magnitude; dest->u.periodic.offset = periodic->offset; @@ -835,14 +840,16 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) condition = &src->condition; /* Header */ - if (condition->type == SDL_HAPTIC_SPRING) + if (condition->type == SDL_HAPTIC_SPRING) { dest->type = FF_SPRING; - else if (condition->type == SDL_HAPTIC_DAMPER) + } else if (condition->type == SDL_HAPTIC_DAMPER) { dest->type = FF_DAMPER; - else if (condition->type == SDL_HAPTIC_INERTIA) + } else if (condition->type == SDL_HAPTIC_INERTIA) { dest->type = FF_INERTIA; - else if (condition->type == SDL_HAPTIC_FRICTION) + } else if (condition->type == SDL_HAPTIC_FRICTION) { dest->type = FF_FRICTION; + } + dest->direction = 0; /* Handled by the condition-specifics. */ /* Replay */ @@ -881,8 +888,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) /* Header */ dest->type = FF_RAMP; - if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1) + if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1) { return -1; + } /* Replay */ dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ? diff --git a/src/haptic/windows/SDL_dinputhaptic.c b/src/haptic/windows/SDL_dinputhaptic.c index 130bf9a470..fb276b3295 100644 --- a/src/haptic/windows/SDL_dinputhaptic.c +++ b/src/haptic/windows/SDL_dinputhaptic.c @@ -569,18 +569,22 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes) case SDL_HAPTIC_CARTESIAN: effect->dwFlags |= DIEFF_CARTESIAN; rglDir[0] = dir->dir[0]; - if (naxes > 1) + if (naxes > 1) { rglDir[1] = dir->dir[1]; - if (naxes > 2) + } + if (naxes > 2) { rglDir[2] = dir->dir[2]; + } return 0; case SDL_HAPTIC_SPHERICAL: effect->dwFlags |= DIEFF_SPHERICAL; rglDir[0] = dir->dir[0]; - if (naxes > 1) + if (naxes > 1) { rglDir[1] = dir->dir[1]; - if (naxes > 2) + } + if (naxes > 2) { rglDir[2] = dir->dir[2]; + } return 0; case SDL_HAPTIC_STEERING_AXIS: effect->dwFlags |= DIEFF_CARTESIAN; @@ -1092,8 +1096,9 @@ SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effe return DI_SetError("Getting effect status", ret); } - if (status == 0) + if (status == 0) { return SDL_FALSE; + } return SDL_TRUE; } diff --git a/src/haptic/windows/SDL_xinputhaptic.c b/src/haptic/windows/SDL_xinputhaptic.c index 56b1c49087..c150aa78cc 100644 --- a/src/haptic/windows/SDL_xinputhaptic.c +++ b/src/haptic/windows/SDL_xinputhaptic.c @@ -228,7 +228,7 @@ SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item) int SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) { - return (haptic->hwdata->userid == joystick->hwdata->userid); + return haptic->hwdata->userid == joystick->hwdata->userid; } int diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c index 2cd0b8d0ab..b77d04752e 100644 --- a/src/hidapi/SDL_hidapi.c +++ b/src/hidapi/SDL_hidapi.c @@ -182,7 +182,9 @@ static int SDL_inotify_init1(void) { #else static int SDL_inotify_init1(void) { int fd = inotify_init(); - if (fd < 0) return -1; + if (fd < 0) { + return -1; + } fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(fd, F_SETFD, FD_CLOEXEC); return fd; @@ -192,7 +194,7 @@ static int SDL_inotify_init1(void) { static int StrHasPrefix(const char *string, const char *prefix) { - return (SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0); + return SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0; } static int @@ -321,8 +323,7 @@ HIDAPI_InitializeDiscovery() SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE; } } - } - else + } else #endif /* SDL_USE_LIBUDEV */ { #if defined(HAVE_INOTIFY) @@ -418,15 +419,14 @@ HIDAPI_UpdateDiscovery() if (pUdevDevice) { const char *action = NULL; action = usyms->udev_device_get_action(pUdevDevice); - if (!action || SDL_strcmp(action, "add") == 0 || SDL_strcmp(action, "remove") == 0) { + if (action == NULL || SDL_strcmp(action, "add") == 0 || SDL_strcmp(action, "remove") == 0) { ++SDL_HIDAPI_discovery.m_unDeviceChangeCounter; } usyms->udev_device_unref(pUdevDevice); } } } - } - else + } else #endif /* SDL_USE_LIBUDEV */ { #if defined(HAVE_INOTIFY) @@ -478,8 +478,9 @@ HIDAPI_ShutdownDiscovery() } #if defined(__WIN32__) || defined(__WINGDK__) - if (SDL_HIDAPI_discovery.m_hNotify) + if (SDL_HIDAPI_discovery.m_hNotify) { UnregisterDeviceNotification(SDL_HIDAPI_discovery.m_hNotify); + } if (SDL_HIDAPI_discovery.m_hwndMsg) { DestroyWindow(SDL_HIDAPI_discovery.m_hwndMsg); @@ -506,8 +507,7 @@ HIDAPI_ShutdownDiscovery() SDL_UDEV_ReleaseUdevSyms(); usyms = NULL; } - } - else + } else #endif /* SDL_USE_LIBUDEV */ { #if defined(HAVE_INOTIFY) @@ -805,14 +805,8 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev, uint8_t descriptor_index, uint16_t lang_id, unsigned char *data, int length) { - return libusb_control_transfer(dev, - LIBUSB_ENDPOINT_IN | 0x0, /* Endpoint 0 IN */ - LIBUSB_REQUEST_GET_DESCRIPTOR, - (LIBUSB_DT_STRING << 8) | descriptor_index, - lang_id, - data, - (uint16_t) length, - 1000); + return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id, + data, (uint16_t)length, 1000); /* Endpoint 0 IN */ } #define libusb_get_string_descriptor SDL_libusb_get_string_descriptor #endif /* __FreeBSD__ */ @@ -1237,7 +1231,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned #endif for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) { new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info)); - if (!new_dev) { + if (new_dev == NULL) { LIBUSB_hid_free_enumeration(usb_devs); SDL_hid_free_enumeration(devs); SDL_OutOfMemory(); @@ -1310,7 +1304,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned #endif if (!bFound) { new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info)); - if (!new_dev) { + if (new_dev == NULL) { #ifdef HAVE_LIBUSB if (libusb_ctx.libhandle) { LIBUSB_hid_free_enumeration(usb_devs); diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 9bd3000821..efb1f4cdac 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -164,7 +164,7 @@ SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list) spot = (char *)hint; } - if (!spot) { + if (spot == NULL) { return; } @@ -172,7 +172,7 @@ SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list) entry = (Uint16)SDL_strtol(spot, &spot, 0); entry <<= 16; spot = SDL_strstr(spot, "0x"); - if (!spot) { + if (spot == NULL) { break; } entry |= (Uint16)SDL_strtol(spot, &spot, 0); @@ -218,9 +218,9 @@ static SDL_bool HasSameOutput(SDL_ExtendedGameControllerBind *a, SDL_ExtendedGam } if (a->outputType == SDL_CONTROLLER_BINDTYPE_AXIS) { - return (a->output.axis.axis == b->output.axis.axis); + return a->output.axis.axis == b->output.axis.axis; } else { - return (a->output.button == b->output.button); + return a->output.button == b->output.button; } } @@ -262,7 +262,7 @@ static void HandleJoystickAxis(SDL_GameController *gamecontroller, int axis, int } } - if (last_match && (!match || !HasSameOutput(last_match, match))) { + if (last_match && (match == NULL || !HasSameOutput(last_match, match))) { /* Clear the last input that this axis generated */ ResetOutput(gamecontroller, last_match); } @@ -545,8 +545,7 @@ static ControllerMapping_t *SDL_CreateMappingForAndroidController(SDL_JoystickGU SDL_strlcat(mapping_string, "righttrigger:a5,", sizeof(mapping_string)); } - return SDL_PrivateAddMappingForGUID(guid, mapping_string, - &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); + return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); } #endif /* __ANDROID__ */ @@ -677,8 +676,7 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI } } - return SDL_PrivateAddMappingForGUID(guid, mapping_string, - &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); + return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); } /* @@ -692,8 +690,7 @@ static ControllerMapping_t *SDL_CreateMappingForRAWINPUTController(SDL_JoystickG SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string)); SDL_strlcat(mapping_string, "a:b0,b:b1,x:b2,y:b3,back:b6,guide:b10,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", sizeof(mapping_string)); - return SDL_PrivateAddMappingForGUID(guid, mapping_string, - &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); + return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); } /* @@ -711,8 +708,7 @@ static ControllerMapping_t *SDL_CreateMappingForWGIController(SDL_JoystickGUID g SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string)); SDL_strlcat(mapping_string, "a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:b10,dpdown:b12,dpleft:b13,dpright:b11,leftx:a1,lefty:a0~,rightx:a3,righty:a2~,lefttrigger:a4,righttrigger:a5,", sizeof(mapping_string)); - return SDL_PrivateAddMappingForGUID(guid, mapping_string, - &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); + return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); } /* @@ -804,7 +800,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG return s_pXInputMapping; } #endif - if (!mapping) { + if (mapping == NULL) { if (SDL_IsJoystickHIDAPI(guid)) { mapping = SDL_CreateMappingForHIDAPIController(guid); } else if (SDL_IsJoystickRAWINPUT(guid)) { @@ -843,13 +839,14 @@ SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(const char *pchString ++pchString; } - if (!pchString || !pchString[0]) { + if (pchString == NULL || !pchString[0]) { return SDL_CONTROLLER_AXIS_INVALID; } for (entry = 0; map_StringForControllerAxis[entry]; ++entry) { - if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry])) - return (SDL_GameControllerAxis) entry; + if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry])) { + return (SDL_GameControllerAxis)entry; + } } return SDL_CONTROLLER_AXIS_INVALID; } @@ -896,12 +893,14 @@ static const char* map_StringForControllerButton[] = { SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchString) { int entry; - if (!pchString || !pchString[0]) + if (pchString == NULL || !pchString[0]) { return SDL_CONTROLLER_BUTTON_INVALID; + } for (entry = 0; map_StringForControllerButton[entry]; ++entry) { - if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0) - return (SDL_GameControllerButton) entry; + if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0) { + return (SDL_GameControllerButton)entry; + } } return SDL_CONTROLLER_BUTTON_INVALID; } @@ -1110,7 +1109,7 @@ static char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping) const char *pFirstComma = SDL_strchr(pMapping, ','); if (pFirstComma) { char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1); - if (!pchGUID) { + if (pchGUID == NULL) { SDL_OutOfMemory(); return NULL; } @@ -1150,15 +1149,17 @@ static char *SDL_PrivateGetControllerNameFromMappingString(const char *pMapping) char *pchName; pFirstComma = SDL_strchr(pMapping, ','); - if (!pFirstComma) + if (pFirstComma == NULL) { return NULL; + } pSecondComma = SDL_strchr(pFirstComma + 1, ','); - if (!pSecondComma) + if (pSecondComma == NULL) { return NULL; + } pchName = SDL_malloc(pSecondComma - pFirstComma); - if (!pchName) { + if (pchName == NULL) { SDL_OutOfMemory(); return NULL; } @@ -1176,12 +1177,14 @@ static char *SDL_PrivateGetControllerMappingFromMappingString(const char *pMappi const char *pFirstComma, *pSecondComma; pFirstComma = SDL_strchr(pMapping, ','); - if (!pFirstComma) + if (pFirstComma == NULL) { return NULL; + } pSecondComma = SDL_strchr(pFirstComma + 1, ','); - if (!pSecondComma) + if (pSecondComma == NULL) { return NULL; + } return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */ } @@ -1221,13 +1224,13 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString, Uint16 crc; pchName = SDL_PrivateGetControllerNameFromMappingString(mappingString); - if (!pchName) { + if (pchName == NULL) { SDL_SetError("Couldn't parse name from %s", mappingString); return NULL; } pchMapping = SDL_PrivateGetControllerMappingFromMappingString(mappingString); - if (!pchMapping) { + if (pchMapping == NULL) { SDL_free(pchName); SDL_SetError("Couldn't parse %s", mappingString); return NULL; @@ -1284,7 +1287,7 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString, *existing = SDL_TRUE; } else { pControllerMapping = SDL_malloc(sizeof(*pControllerMapping)); - if (!pControllerMapping) { + if (pControllerMapping == NULL) { SDL_free(pchName); SDL_free(pchMapping); SDL_OutOfMemory(); @@ -1327,7 +1330,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const mapping = SDL_PrivateGetControllerMappingForGUID(guid); #ifdef __LINUX__ - if (!mapping && name) { + if (mapping == NULL && name) { if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) { /* The Linux driver xpad.c maps the wireless dpad to buttons */ SDL_bool existing; @@ -1340,7 +1343,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const } #endif /* __LINUX__ */ - if (!mapping) { + if (mapping == NULL) { mapping = s_pDefaultMapping; } return mapping; @@ -1422,8 +1425,7 @@ static ControllerMapping_t *SDL_PrivateGenerateAutomaticControllerMapping(const SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "lefttrigger", &raw_map->lefttrigger); SDL_PrivateAppendToMappingString(mapping, sizeof(mapping), "righttrigger", &raw_map->righttrigger); - return SDL_PrivateAddMappingForGUID(guid, mapping, - &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); + return SDL_PrivateAddMappingForGUID(guid, mapping, &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); } static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) @@ -1437,13 +1439,13 @@ static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) { SDL_SetError("There are %d joysticks available", SDL_NumJoysticks()); SDL_UnlockJoysticks(); - return (NULL); + return NULL; } name = SDL_JoystickNameForIndex(device_index); guid = SDL_JoystickGetDeviceGUID(device_index); mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid); - if (!mapping) { + if (mapping == NULL) { SDL_GamepadMapping raw_map; SDL_zero(raw_map); @@ -1540,7 +1542,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap SDL_bool existing = SDL_FALSE; ControllerMapping_t *pControllerMapping; - if (!mappingString) { + if (mappingString == NULL) { return SDL_InvalidParamError("mappingString"); } @@ -1607,7 +1609,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap #endif pchGUID = SDL_PrivateGetControllerGUIDFromMappingString(mappingString); - if (!pchGUID) { + if (pchGUID == NULL) { return SDL_SetError("Couldn't parse GUID from %s", mappingString); } if (!SDL_strcasecmp(pchGUID, "default")) { @@ -1619,7 +1621,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap SDL_free(pchGUID); pControllerMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing, priority); - if (!pControllerMapping) { + if (pControllerMapping == NULL) { return -1; } @@ -1687,7 +1689,7 @@ CreateMappingString(ControllerMapping_t *mapping, SDL_JoystickGUID guid) } pMappingString = SDL_malloc(needed); - if (!pMappingString) { + if (pMappingString == NULL) { SDL_OutOfMemory(); return NULL; } @@ -1774,8 +1776,9 @@ SDL_GameControllerLoadHints() char *pchNewLine = NULL; pchNewLine = SDL_strchr(pUserMappings, '\n'); - if (pchNewLine) + if (pchNewLine) { *pchNewLine = '\0'; + } SDL_PrivateGameControllerAddMapping(pUserMappings, SDL_CONTROLLER_MAPPING_PRIORITY_USER); @@ -1837,7 +1840,7 @@ SDL_GameControllerInitMappings(void) SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT, SDL_GameControllerIgnoreDevicesExceptChanged, NULL); - return (0); + return 0; } int @@ -1858,7 +1861,7 @@ SDL_GameControllerInit(void) } } - return (0); + return 0; } @@ -1926,7 +1929,7 @@ SDL_GameControllerMappingForDeviceIndex(int joystick_index) /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */ needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; pMappingString = SDL_malloc(needed); - if (!pMappingString) { + if (pMappingString == NULL) { SDL_OutOfMemory(); SDL_UnlockJoysticks(); return NULL; @@ -2081,14 +2084,14 @@ SDL_GameControllerOpen(int device_index) gamecontroller = gamecontrollerlist; ++gamecontroller->ref_count; SDL_UnlockJoysticks(); - return (gamecontroller); + return gamecontroller; } gamecontrollerlist = gamecontrollerlist->next; } /* Find a controller mapping */ pSupportedController = SDL_PrivateGetControllerMapping(device_index); - if (!pSupportedController) { + if (pSupportedController == NULL) { SDL_SetError("Couldn't find mapping for device (%d)", device_index); SDL_UnlockJoysticks(); return NULL; @@ -2142,7 +2145,7 @@ SDL_GameControllerOpen(int device_index) SDL_UnlockJoysticks(); - return (gamecontroller); + return gamecontroller; } /* @@ -2373,7 +2376,7 @@ int SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_S SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); int i; - if (!joystick) { + if (joystick == NULL) { return -1; } @@ -2435,7 +2438,7 @@ SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_Sens SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); int i; - if (!joystick) { + if (joystick == NULL) { return 0.0f; } @@ -2467,7 +2470,7 @@ SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller, SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); int i; - if (!joystick) { + if (joystick == NULL) { return -1; } @@ -2503,7 +2506,7 @@ SDL_GameControllerPath(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return NULL; } return SDL_JoystickPath(joystick); @@ -2514,7 +2517,7 @@ SDL_GameControllerGetType(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return SDL_CONTROLLER_TYPE_UNKNOWN; } return SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGetGUID(joystick), SDL_JoystickName(joystick)); @@ -2525,7 +2528,7 @@ SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return -1; } return SDL_JoystickGetPlayerIndex(joystick); @@ -2539,7 +2542,7 @@ SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_ { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return; } SDL_JoystickSetPlayerIndex(joystick, player_index); @@ -2550,7 +2553,7 @@ SDL_GameControllerGetVendor(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return 0; } return SDL_JoystickGetVendor(joystick); @@ -2561,7 +2564,7 @@ SDL_GameControllerGetProduct(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return 0; } return SDL_JoystickGetProduct(joystick); @@ -2572,7 +2575,7 @@ SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return 0; } return SDL_JoystickGetProductVersion(joystick); @@ -2583,7 +2586,7 @@ SDL_GameControllerGetFirmwareVersion(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return 0; } return SDL_JoystickGetFirmwareVersion(joystick); @@ -2594,7 +2597,7 @@ SDL_GameControllerGetSerial(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return NULL; } return SDL_JoystickGetSerial(joystick); @@ -2670,8 +2673,9 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController CHECK_GAMECONTROLLER_MAGIC(gamecontroller, bind); - if (axis == SDL_CONTROLLER_AXIS_INVALID) + if (axis == SDL_CONTROLLER_AXIS_INVALID) { return bind; + } for (i = 0; i < gamecontroller->num_bindings; ++i) { SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i]; @@ -2704,8 +2708,9 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameControll CHECK_GAMECONTROLLER_MAGIC(gamecontroller, bind); - if (button == SDL_CONTROLLER_BUTTON_INVALID) + if (button == SDL_CONTROLLER_BUTTON_INVALID) { return bind; + } for (i = 0; i < gamecontroller->num_bindings; ++i) { SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i]; @@ -2731,7 +2736,7 @@ SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequenc { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return -1; } return SDL_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms); @@ -2742,7 +2747,7 @@ SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return -1; } return SDL_JoystickRumbleTriggers(joystick, left_rumble, right_rumble, duration_ms); @@ -2753,7 +2758,7 @@ SDL_GameControllerHasLED(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return SDL_FALSE; } return SDL_JoystickHasLED(joystick); @@ -2764,7 +2769,7 @@ SDL_GameControllerHasRumble(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return SDL_FALSE; } return SDL_JoystickHasRumble(joystick); @@ -2775,7 +2780,7 @@ SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller) { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return SDL_FALSE; } return SDL_JoystickHasRumbleTriggers(joystick); @@ -2786,7 +2791,7 @@ SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 gr { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return -1; } return SDL_JoystickSetLED(joystick, red, green, blue); @@ -2797,7 +2802,7 @@ SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *dat { SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller); - if (!joystick) { + if (joystick == NULL) { return -1; } return SDL_JoystickSendEffect(joystick, data, size); @@ -2808,8 +2813,9 @@ SDL_GameControllerClose(SDL_GameController *gamecontroller) { SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev; - if (!gamecontroller || gamecontroller->magic != &gamecontroller_magic) + if (gamecontroller == NULL || gamecontroller->magic != &gamecontroller_magic) { return; + } SDL_LockJoysticks(); @@ -2913,7 +2919,7 @@ SDL_PrivateGameControllerAxis(SDL_GameController *gamecontroller, SDL_GameContro posted = SDL_PushEvent(&event) == 1; } #endif /* !SDL_EVENTS_DISABLED */ - return (posted); + return posted; } @@ -2942,7 +2948,7 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont break; default: /* Invalid state -- bail */ - return (0); + return 0; } #endif /* !SDL_EVENTS_DISABLED */ @@ -2953,12 +2959,12 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont if (gamecontroller->joystick->delayed_guide_button) { /* Skip duplicate press */ - return (0); + return 0; } } else { if (!SDL_TICKS_PASSED(now, gamecontroller->guide_button_down+SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS)) { gamecontroller->joystick->delayed_guide_button = SDL_TRUE; - return (0); + return 0; } gamecontroller->joystick->delayed_guide_button = SDL_FALSE; } @@ -2974,7 +2980,7 @@ SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameCont posted = SDL_PushEvent(&event) == 1; } #endif /* !SDL_EVENTS_DISABLED */ - return (posted); + return posted; } /* @@ -3009,7 +3015,7 @@ SDL_GameControllerEventState(int state) } break; } - return (state); + return state; #endif /* SDL_EVENTS_DISABLED */ } diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 73355e9fcf..e2b723b296 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -257,7 +257,7 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id) if (player_index >= SDL_joystick_player_count) { SDL_JoystickID *new_players = (SDL_JoystickID *)SDL_realloc(SDL_joystick_players, (player_index + 1)*sizeof(*SDL_joystick_players)); - if (!new_players) { + if (new_players == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -309,7 +309,7 @@ SDL_JoystickInit(void) int i, status; /* Create the joystick list lock */ - if (!SDL_joystick_lock) { + if (SDL_joystick_lock == NULL) { SDL_joystick_lock = SDL_CreateMutex(); } @@ -403,7 +403,7 @@ SDL_JoystickPathForIndex(int device_index) SDL_UnlockJoysticks(); /* FIXME: Really we should reference count this path so it doesn't go away after unlock */ - if (!path) { + if (path == NULL) { SDL_Unsupported(); } return path; @@ -1382,7 +1382,7 @@ static void UpdateEventsForDeviceRemoval(int device_index, Uint32 type) } events = SDL_small_alloc(SDL_Event, num_events, &isstack); - if (!events) { + if (events == NULL) { return; } @@ -1903,10 +1903,10 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c return SDL_strdup(custom_name); } - if (!vendor_name) { + if (vendor_name == NULL) { vendor_name = ""; } - if (!product_name) { + if (product_name == NULL) { product_name = ""; } @@ -1958,7 +1958,7 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c name = SDL_strdup("Controller"); } - if (!name) { + if (name == NULL) { return NULL; } @@ -2023,7 +2023,7 @@ SDL_CreateJoystickGUID(Uint16 bus, Uint16 vendor, Uint16 product, Uint16 version SDL_zero(guid); - if (!name) { + if (name == NULL) { name = ""; } @@ -2213,7 +2213,7 @@ SDL_bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_XBoxOneController); + return eType == k_eControllerType_XBoxOneController; } SDL_bool @@ -2287,71 +2287,68 @@ SDL_bool SDL_IsJoystickPS4(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_PS4Controller); + return eType == k_eControllerType_PS4Controller; } SDL_bool SDL_IsJoystickPS5(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_PS5Controller); + return eType == k_eControllerType_PS5Controller; } SDL_bool SDL_IsJoystickNintendoSwitchPro(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_SwitchProController || - eType == k_eControllerType_SwitchInputOnlyController); + return eType == k_eControllerType_SwitchProController || eType == k_eControllerType_SwitchInputOnlyController; } SDL_bool SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_SwitchInputOnlyController); + return eType == k_eControllerType_SwitchInputOnlyController; } SDL_bool SDL_IsJoystickNintendoSwitchJoyCon(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_SwitchJoyConLeft || - eType == k_eControllerType_SwitchJoyConRight); + return eType == k_eControllerType_SwitchJoyConLeft || eType == k_eControllerType_SwitchJoyConRight; } SDL_bool SDL_IsJoystickNintendoSwitchJoyConLeft(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_SwitchJoyConLeft); + return eType == k_eControllerType_SwitchJoyConLeft; } SDL_bool SDL_IsJoystickNintendoSwitchJoyConRight(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_SwitchJoyConRight); + return eType == k_eControllerType_SwitchJoyConRight; } SDL_bool SDL_IsJoystickNintendoSwitchJoyConGrip(Uint16 vendor_id, Uint16 product_id) { - return (vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP); + return vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP; } SDL_bool SDL_IsJoystickNintendoSwitchJoyConPair(Uint16 vendor_id, Uint16 product_id) { - return (vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR); + return vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR; } SDL_bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id) { EControllerType eType = GuessControllerType(vendor_id, product_id); - return (eType == k_eControllerType_SteamController || - eType == k_eControllerType_SteamControllerV2); + return eType == k_eControllerType_SteamController || eType == k_eControllerType_SteamControllerV2; } SDL_bool diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index 1c2d829d66..3c83256e02 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -615,7 +615,7 @@ ANDROID_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->nbuttons = item->nbuttons; joystick->naxes = item->naxes; - return (0); + return 0; } static int diff --git a/src/joystick/bsd/SDL_bsdjoystick.c b/src/joystick/bsd/SDL_bsdjoystick.c index 9d44a88aac..5399e9a0b7 100644 --- a/src/joystick/bsd/SDL_bsdjoystick.c +++ b/src/joystick/bsd/SDL_bsdjoystick.c @@ -320,8 +320,9 @@ CreateHwData(const char *path) hw->type = BSDJOY_UHID; { int ax; - for (ax = 0; ax < JOYAXE_count; ax++) + for (ax = 0; ax < JOYAXE_count; ax++) { hw->axis_map[ax] = -1; + } } hw->repdesc = hid_get_report_desc(fd); if (hw->repdesc == NULL) { @@ -355,8 +356,9 @@ CreateHwData(const char *path) SDL_SetError("%s: Cannot start HID parser", path); goto usberr; } - for (i = 0; i < JOYAXE_count; i++) + for (i = 0; i < JOYAXE_count; i++) { hw->axis_map[i] = -1; + } while (hid_get_item(hdata, &hitem) > 0) { switch (hitem.kind) { @@ -394,9 +396,11 @@ CreateHwData(const char *path) } } hid_end_parse(hdata); - for (i = 0; i < JOYAXE_count; i++) - if (hw->axis_map[i] > 0) + for (i = 0; i < JOYAXE_count; i++) { + if (hw->axis_map[i] > 0) { hw->axis_map[i] = hw->naxes++; + } + } if (hw->naxes == 0 && hw->nbuttons == 0 && hw->nhats == 0) { SDL_SetError("%s: Not a joystick, ignoring", path); @@ -446,7 +450,7 @@ MaybeAddDevice(const char *path) } hw = CreateHwData(path); - if (!hw) { + if (hw == NULL) { return -1; } @@ -476,7 +480,7 @@ MaybeAddDevice(const char *path) } #endif /* USB_GET_DEVICEINFO */ } - if (!name) { + if (name == NULL) { name = SDL_strdup(path); guid = SDL_CreateJoystickGUIDForName(name); } @@ -633,7 +637,7 @@ BSD_JoystickOpen(SDL_Joystick *joy, int device_index) } hw = CreateHwData(item->path); - if (!hw) { + if (hw == NULL) { return -1; } @@ -738,16 +742,13 @@ BSD_JoystickUpdate(SDL_Joystick *joy) else if (usage == HUG_DPAD_UP) { dpad[0] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem); SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad)); - } - else if (usage == HUG_DPAD_DOWN) { + } else if (usage == HUG_DPAD_DOWN) { dpad[1] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem); SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad)); - } - else if (usage == HUG_DPAD_RIGHT) { + } else if (usage == HUG_DPAD_RIGHT) { dpad[2] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem); SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad)); - } - else if (usage == HUG_DPAD_LEFT) { + } else if (usage == HUG_DPAD_LEFT) { dpad[3] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem); SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad)); } diff --git a/src/joystick/darwin/SDL_iokitjoystick.c b/src/joystick/darwin/SDL_iokitjoystick.c index 5352da14fd..cb6a4ca5be 100644 --- a/src/joystick/darwin/SDL_iokitjoystick.c +++ b/src/joystick/darwin/SDL_iokitjoystick.c @@ -41,7 +41,7 @@ static recDevice *gpDeviceList = NULL; void FreeRumbleEffectData(FFEFFECT *effect) { - if (!effect) { + if (effect == NULL) { return; } SDL_free(effect->rgdwAxes); @@ -57,7 +57,7 @@ FFEFFECT *CreateRumbleEffectData(Sint16 magnitude) /* Create the effect */ effect = (FFEFFECT *)SDL_calloc(1, sizeof(*effect)); - if (!effect) { + if (effect == NULL) { return NULL; } effect->dwSize = sizeof(*effect); @@ -81,7 +81,7 @@ FFEFFECT *CreateRumbleEffectData(Sint16 magnitude) effect->dwFlags |= FFEFF_CARTESIAN; periodic = (FFPERIODIC *)SDL_calloc(1, sizeof(*periodic)); - if (!periodic) { + if (periodic == NULL) { FreeRumbleEffectData(effect); return NULL; } @@ -99,8 +99,9 @@ static recDevice *GetDeviceForIndex(int device_index) recDevice *device = gpDeviceList; while (device) { if (!device->removed) { - if (device_index == 0) + if (device_index == 0) { break; + } --device_index; } @@ -206,13 +207,10 @@ GetHIDScaledCalibratedState(recDevice * pDevice, recElement * pElement, SInt32 m const float deviceScale = max - min; const float readScale = pElement->maxReport - pElement->minReport; int returnValue = SDL_FALSE; - if (GetHIDElementState(pDevice, pElement, pValue)) - { + if (GetHIDElementState(pDevice, pElement, pValue)) { if (readScale == 0) { returnValue = SDL_TRUE; /* no scaling at all */ - } - else - { + } else { *pValue = ((*pValue - pElement->minReport) * deviceScale / readScale) + min; returnValue = SDL_TRUE; } @@ -545,7 +543,7 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic } device = (recDevice *) SDL_calloc(1, sizeof(recDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); return; } @@ -578,7 +576,7 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic } /* Add device to the end of the list */ - if ( !gpDeviceList ) { + if (gpDeviceList == NULL) { gpDeviceList = device; } else { recDevice *curdevice; @@ -889,7 +887,7 @@ DARWIN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint1 /* Scale and average the two rumble strengths */ Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2); - if (!device) { + if (device == NULL) { return SDL_SetError("Rumble failed, device disconnected"); } @@ -932,7 +930,7 @@ DARWIN_JoystickGetCapabilities(SDL_Joystick *joystick) recDevice *device = joystick->hwdata; Uint32 result = 0; - if (!device) { + if (device == NULL) { return 0; } @@ -969,7 +967,7 @@ DARWIN_JoystickUpdate(SDL_Joystick *joystick) SInt32 value, range; int i, goodRead = SDL_FALSE; - if (!device) { + if (device == NULL) { return; } diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c index 971109f2f7..0d8cc02ff8 100644 --- a/src/joystick/emscripten/SDL_sysjoystick.c +++ b/src/joystick/emscripten/SDL_sysjoystick.c @@ -73,11 +73,11 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa item->timestamp = gamepadEvent->timestamp; - for( i = 0; i < item->naxes; i++) { + for ( i = 0; i < item->naxes; i++) { item->axis[i] = gamepadEvent->axis[i]; } - for( i = 0; i < item->nbuttons; i++) { + for ( i = 0; i < item->nbuttons; i++) { item->analogButton[i] = gamepadEvent->analogButton[i]; item->digitalButton[i] = gamepadEvent->digitalButton[i]; } @@ -195,7 +195,7 @@ EMSCRIPTEN_JoystickInit(void) /* handle already connected gamepads */ if (numjs > 0) { - for(i = 0; i < numjs; i++) { + for (i = 0; i < numjs; i++) { retval = emscripten_get_gamepad_status(i, &gamepadState); if (retval == EMSCRIPTEN_RESULT_SUCCESS) { Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED, @@ -209,7 +209,7 @@ EMSCRIPTEN_JoystickInit(void) 0, Emscripten_JoyStickConnected); - if(retval != EMSCRIPTEN_RESULT_SUCCESS) { + if (retval != EMSCRIPTEN_RESULT_SUCCESS) { EMSCRIPTEN_JoystickQuit(); return SDL_SetError("Could not set gamepad connect callback"); } @@ -217,7 +217,7 @@ EMSCRIPTEN_JoystickInit(void) retval = emscripten_set_gamepaddisconnected_callback(NULL, 0, Emscripten_JoyStickDisconnected); - if(retval != EMSCRIPTEN_RESULT_SUCCESS) { + if (retval != EMSCRIPTEN_RESULT_SUCCESS) { EMSCRIPTEN_JoystickQuit(); return SDL_SetError("Could not set gamepad disconnect callback"); } @@ -328,7 +328,7 @@ EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->nbuttons = item->nbuttons; joystick->naxes = item->naxes; - return (0); + return 0; } /* Function to update the state of a joystick - called as a device poll. @@ -347,10 +347,10 @@ EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick) if (item) { result = emscripten_get_gamepad_status(item->index, &gamepadState); - if( result == EMSCRIPTEN_RESULT_SUCCESS) { - if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) { - for(i = 0; i < item->nbuttons; i++) { - if(item->digitalButton[i] != gamepadState.digitalButton[i]) { + if ( result == EMSCRIPTEN_RESULT_SUCCESS) { + if (gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) { + for (i = 0; i < item->nbuttons; i++) { + if (item->digitalButton[i] != gamepadState.digitalButton[i]) { buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED; SDL_PrivateJoystickButton(item->joystick, i, buttonState); } @@ -360,8 +360,8 @@ EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick) item->digitalButton[i] = gamepadState.digitalButton[i]; } - for(i = 0; i < item->naxes; i++) { - if(item->axis[i] != gamepadState.axis[i]) { + for (i = 0; i < item->naxes; i++) { + if (item->axis[i] != gamepadState.axis[i]) { /* do we need to do conversion? */ SDL_PrivateJoystickAxis(item->joystick, i, (Sint16) (32767.*gamepadState.axis[i])); diff --git a/src/joystick/haiku/SDL_haikujoystick.cc b/src/joystick/haiku/SDL_haikujoystick.cc index 99bfdc67af..8b0bc25884 100644 --- a/src/joystick/haiku/SDL_haikujoystick.cc +++ b/src/joystick/haiku/SDL_haikujoystick.cc @@ -67,8 +67,7 @@ extern "C" numjoysticks = 0; SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport)); SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname)); - for (i = 0; (numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i) - { + for (i = 0; (numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i) { if (joystick.GetDeviceName(i, name) == B_OK) { if (joystick.Open(name) != B_ERROR) { BString stick_name; diff --git a/src/joystick/hidapi/SDL_hidapi_gamecube.c b/src/joystick/hidapi/SDL_hidapi_gamecube.c index 14b4cfed00..eac564311d 100644 --- a/src/joystick/hidapi/SDL_hidapi_gamecube.c +++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c @@ -141,7 +141,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device) #endif ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -253,7 +253,7 @@ HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_Driver } joystick = SDL_JoystickFromInstanceID(ctx->joysticks[i]); - if (!joystick) { + if (joystick == NULL) { /* Hasn't been opened yet, skip */ return; } diff --git a/src/joystick/hidapi/SDL_hidapi_luna.c b/src/joystick/hidapi/SDL_hidapi_luna.c index 162368078d..98b4e5b06c 100644 --- a/src/joystick/hidapi/SDL_hidapi_luna.c +++ b/src/joystick/hidapi/SDL_hidapi_luna.c @@ -63,9 +63,7 @@ HIDAPI_DriverLuna_UnregisterHints(SDL_HintCallback callback, void *userdata) static SDL_bool HIDAPI_DriverLuna_IsEnabled(void) { - return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_LUNA, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)); + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_LUNA, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); } static SDL_bool @@ -80,7 +78,7 @@ HIDAPI_DriverLuna_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverLuna_Context *ctx; ctx = (SDL_DriverLuna_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -286,14 +284,11 @@ HIDAPI_DriverLuna_HandleBluetoothStatePacket(SDL_Joystick *joystick, SDL_DriverL int level = data[1] * 100 / 0xFF; if (level == 0) { SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_EMPTY); - } - else if (level <= 20) { + } else if (level <= 20) { SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_LOW); - } - else if (level <= 70) { + } else if (level <= 70) { SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_MEDIUM); - } - else { + } else { SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_FULL); } @@ -413,7 +408,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device) #ifdef DEBUG_LUNA_PROTOCOL HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size); #endif - if (!joystick) { + if (joystick == NULL) { continue; } @@ -431,7 +426,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_ps3.c b/src/joystick/hidapi/SDL_hidapi_ps3.c index a00d2ba294..979d3a234a 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps3.c +++ b/src/joystick/hidapi/SDL_hidapi_ps3.c @@ -140,7 +140,7 @@ HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device) } ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -223,7 +223,7 @@ HIDAPI_DriverPS3_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID { SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; - if (!ctx) { + if (ctx == NULL) { return; } @@ -506,7 +506,7 @@ HIDAPI_DriverPS3_UpdateDevice(SDL_HIDAPI_Device *device) #ifdef DEBUG_PS3_PROTOCOL HIDAPI_DumpPacket("PS3 packet: size = %d", data, size); #endif - if (!joystick) { + if (joystick == NULL) { continue; } @@ -548,7 +548,7 @@ HIDAPI_DriverPS3_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void @@ -629,7 +629,7 @@ HIDAPI_DriverPS3ThirdParty_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverPS3_Context *ctx; ctx = (SDL_DriverPS3_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -837,7 +837,7 @@ HIDAPI_DriverPS3ThirdParty_UpdateDevice(SDL_HIDAPI_Device *device) #ifdef DEBUG_PS3_PROTOCOL HIDAPI_DumpPacket("PS3 packet: size = %d", data, size); #endif - if (!joystick) { + if (joystick == NULL) { continue; } @@ -854,7 +854,7 @@ HIDAPI_DriverPS3ThirdParty_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index de7841b804..49510dea33 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -167,9 +167,7 @@ HIDAPI_DriverPS4_UnregisterHints(SDL_HintCallback callback, void *userdata) static SDL_bool HIDAPI_DriverPS4_IsEnabled(void) { - return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)); + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); } static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length) @@ -244,7 +242,7 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device) SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER; ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -421,7 +419,7 @@ HIDAPI_DriverPS4_LoadCalibrationData(SDL_HIDAPI_Device *device) return; } - for( tries = 0; tries < 5; ++tries ) { + for ( tries = 0; tries < 5; ++tries ) { /* For Bluetooth controllers, this report switches them into advanced report mode */ size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdGyroCalibration_USB, data, sizeof(data)); if (size < 35) { @@ -1072,7 +1070,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device) ++packet_count; ctx->last_packet = now; - if (!joystick) { + if (joystick == NULL) { continue; } @@ -1146,7 +1144,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c index 2a196d95f3..03c588c0b8 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps5.c +++ b/src/joystick/hidapi/SDL_hidapi_ps5.c @@ -250,9 +250,7 @@ HIDAPI_DriverPS5_UnregisterHints(SDL_HintCallback callback, void *userdata) static SDL_bool HIDAPI_DriverPS5_IsEnabled(void) { - return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)); + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); } static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length) @@ -345,7 +343,7 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device) SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER; ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -1350,7 +1348,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device) ++packet_count; ctx->last_packet = now; - if (!joystick) { + if (joystick == NULL) { continue; } @@ -1410,7 +1408,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_rumble.c b/src/joystick/hidapi/SDL_hidapi_rumble.c index 5e222ed617..e9cf2edb6d 100644 --- a/src/joystick/hidapi/SDL_hidapi_rumble.c +++ b/src/joystick/hidapi/SDL_hidapi_rumble.c @@ -213,7 +213,7 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const } request = (SDL_HIDAPI_RumbleRequest *)SDL_calloc(1, sizeof(*request)); - if (!request) { + if (request == NULL) { SDL_HIDAPI_UnlockRumble(); return SDL_OutOfMemory(); } diff --git a/src/joystick/hidapi/SDL_hidapi_shield.c b/src/joystick/hidapi/SDL_hidapi_shield.c index 1219b70042..184bc84ade 100644 --- a/src/joystick/hidapi/SDL_hidapi_shield.c +++ b/src/joystick/hidapi/SDL_hidapi_shield.c @@ -103,9 +103,7 @@ HIDAPI_DriverShield_UnregisterHints(SDL_HintCallback callback, void *userdata) static SDL_bool HIDAPI_DriverShield_IsEnabled(void) { - return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SHIELD, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)); + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SHIELD, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); } static SDL_bool @@ -120,7 +118,7 @@ HIDAPI_DriverShield_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverShield_Context *ctx; ctx = (SDL_DriverShield_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -504,7 +502,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device) /* Byte 0 is HID report ID */ switch (data[0]) { case k_ShieldReportIdControllerState: - if (!joystick) { + if (joystick == NULL) { break; } if (size == 16) { @@ -514,7 +512,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device) } break; case k_ShieldReportIdControllerTouch: - if (!joystick) { + if (joystick == NULL) { break; } HIDAPI_DriverShield_HandleTouchPacketV103(joystick, ctx, data, size); @@ -578,7 +576,7 @@ HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_stadia.c b/src/joystick/hidapi/SDL_hidapi_stadia.c index 157d9eac40..eca272b92c 100644 --- a/src/joystick/hidapi/SDL_hidapi_stadia.c +++ b/src/joystick/hidapi/SDL_hidapi_stadia.c @@ -59,9 +59,7 @@ HIDAPI_DriverStadia_UnregisterHints(SDL_HintCallback callback, void *userdata) static SDL_bool HIDAPI_DriverStadia_IsEnabled(void) { - return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STADIA, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)); + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STADIA, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); } static SDL_bool @@ -76,7 +74,7 @@ HIDAPI_DriverStadia_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverStadia_Context *ctx; ctx = (SDL_DriverStadia_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -280,7 +278,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device) #ifdef DEBUG_STADIA_PROTOCOL HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size); #endif - if (!joystick) { + if (joystick == NULL) { continue; } @@ -291,7 +289,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_steam.c b/src/joystick/hidapi/SDL_hidapi_steam.c index 0cc52eec52..4041aca641 100644 --- a/src/joystick/hidapi/SDL_hidapi_steam.c +++ b/src/joystick/hidapi/SDL_hidapi_steam.c @@ -199,8 +199,9 @@ static uint8_t GetSegmentHeader( int nSegmentNumber, bool bLastPacket ) { uint8_t header = REPORT_SEGMENT_DATA_FLAG; header |= nSegmentNumber; - if ( bLastPacket ) + if (bLastPacket) { header |= REPORT_SEGMENT_LAST_FLAG; + } return header; } @@ -208,8 +209,9 @@ static uint8_t GetSegmentHeader( int nSegmentNumber, bool bLastPacket ) static void hexdump( const uint8_t *ptr, int len ) { int i; - for ( i = 0; i < len ; ++i ) + for (i = 0; i < len; ++i) { printf("%02x ", ptr[i]); + } printf("\n"); } @@ -232,21 +234,18 @@ static void InitializeSteamControllerPacketAssembler( SteamControllerPacketAssem // Complete packet size on completion static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAssembler *pAssembler, const uint8_t *pSegment, int nSegmentLength ) { - if ( pAssembler->bIsBle ) - { + if ( pAssembler->bIsBle ) { uint8_t uSegmentHeader = pSegment[ 1 ]; int nSegmentNumber = uSegmentHeader & 0x07; HEXDUMP( pSegment, nSegmentLength ); - if ( pSegment[ 0 ] != BLE_REPORT_NUMBER ) - { + if ( pSegment[ 0 ] != BLE_REPORT_NUMBER ) { // We may get keyboard/mouse input events until controller stops sending them return 0; } - if ( nSegmentLength != MAX_REPORT_SEGMENT_SIZE ) - { + if ( nSegmentLength != MAX_REPORT_SEGMENT_SIZE ) { printf( "Bad segment size! %d\n", (int)nSegmentLength ); hexdump( pSegment, nSegmentLength ); ResetSteamControllerPacketAssembler( pAssembler ); @@ -255,18 +254,15 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs DPRINTF("GOT PACKET HEADER = 0x%x\n", uSegmentHeader); - if ( ( uSegmentHeader & REPORT_SEGMENT_DATA_FLAG ) == 0 ) - { + if ( ( uSegmentHeader & REPORT_SEGMENT_DATA_FLAG ) == 0 ) { // We get empty segments, just ignore them return 0; } - if ( nSegmentNumber != pAssembler->nExpectedSegmentNumber ) - { + if ( nSegmentNumber != pAssembler->nExpectedSegmentNumber ) { ResetSteamControllerPacketAssembler( pAssembler ); - if ( nSegmentNumber ) - { + if ( nSegmentNumber ) { // This happens occasionally DPRINTF("Bad segment number, got %d, expected %d\n", nSegmentNumber, pAssembler->nExpectedSegmentNumber ); @@ -278,16 +274,13 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs pSegment + 2, // ignore header and report number MAX_REPORT_SEGMENT_PAYLOAD_SIZE ); - if ( uSegmentHeader & REPORT_SEGMENT_LAST_FLAG ) - { + if ( uSegmentHeader & REPORT_SEGMENT_LAST_FLAG ) { pAssembler->nExpectedSegmentNumber = 0; return ( nSegmentNumber + 1 ) * MAX_REPORT_SEGMENT_PAYLOAD_SIZE; } pAssembler->nExpectedSegmentNumber++; - } - else - { + } else { // Just pass through SDL_memcpy( pAssembler->uBuffer, pSegment, @@ -307,20 +300,19 @@ static int SetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65], int DPRINTF("SetFeatureReport %p %p %d\n", dev, uBuffer, nActualDataLen); - if ( bBle ) - { + if ( bBle ) { int nSegmentNumber = 0; uint8_t uPacketBuffer[ MAX_REPORT_SEGMENT_SIZE ]; unsigned char *pBufferPtr = uBuffer + 1; - if ( nActualDataLen < 1 ) + if (nActualDataLen < 1) { return -1; + } // Skip report number in data nActualDataLen--; - while ( nActualDataLen > 0 ) - { + while ( nActualDataLen > 0 ) { int nBytesInPacket = nActualDataLen > MAX_REPORT_SEGMENT_PAYLOAD_SIZE ? MAX_REPORT_SEGMENT_PAYLOAD_SIZE : nActualDataLen; nActualDataLen -= nBytesInPacket; @@ -349,8 +341,7 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] ) DPRINTF("GetFeatureReport( %p %p )\n", dev, uBuffer ); - if ( bBle ) - { + if ( bBle ) { int nRetries = 0; uint8_t uSegmentBuffer[ MAX_REPORT_SEGMENT_SIZE + 1 ]; uint8_t ucBytesToRead = MAX_REPORT_SEGMENT_SIZE; @@ -367,8 +358,7 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] ) ++ucDataStartOffset; #endif - while( nRetries < BLE_MAX_READ_RETRIES ) - { + while ( nRetries < BLE_MAX_READ_RETRIES ) { SDL_memset( uSegmentBuffer, 0, sizeof( uSegmentBuffer ) ); uSegmentBuffer[ 0 ] = BLE_REPORT_NUMBER; nRet = SDL_hid_get_feature_report( dev, uSegmentBuffer, ucBytesToRead ); @@ -382,14 +372,12 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] ) else nRetries++; - if ( nRet > 0 ) - { + if ( nRet > 0 ) { int nPacketLength = WriteSegmentToSteamControllerPacketAssembler( &assembler, uSegmentBuffer + ucDataStartOffset, nRet - ucDataStartOffset ); - if ( nPacketLength > 0 && nPacketLength < 65 ) - { + if ( nPacketLength > 0 && nPacketLength < 65 ) { // Leave space for "report number" uBuffer[ 0 ] = 0; SDL_memcpy( uBuffer + 1, assembler.uBuffer, nPacketLength ); @@ -412,14 +400,16 @@ static int ReadResponse( SDL_hid_device *dev, uint8_t uBuffer[65], int nExpected DPRINTF("ReadResponse( %p %p %d )\n", dev, uBuffer, nExpectedResponse ); - if ( nRet < 0 ) + if (nRet < 0) { return nRet; + } DPRINTF("ReadResponse got %d bytes of data: ", nRet ); HEXDUMP( uBuffer, nRet ); - if ( uBuffer[1] != nExpectedResponse ) + if (uBuffer[1] != nExpectedResponse) { return -1; + } return nRet; } @@ -443,35 +433,34 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew, buf[0] = 0; buf[1] = ID_GET_ATTRIBUTES_VALUES; res = SetFeatureReport( dev, buf, 2 ); - if ( res < 0 ) - { - if ( !bSuppressErrorSpew ) - printf( "GET_ATTRIBUTES_VALUES failed for controller %p\n", dev ); + if ( res < 0 ) { + if (!bSuppressErrorSpew) { + printf("GET_ATTRIBUTES_VALUES failed for controller %p\n", dev); + } return false; } // Retrieve GET_ATTRIBUTES_VALUES result // Wireless controller endpoints without a connected controller will return nAttrs == 0 res = ReadResponse( dev, buf, ID_GET_ATTRIBUTES_VALUES ); - if ( res < 0 || buf[1] != ID_GET_ATTRIBUTES_VALUES ) - { + if ( res < 0 || buf[1] != ID_GET_ATTRIBUTES_VALUES ) { HEXDUMP(buf, res); - if ( !bSuppressErrorSpew ) - printf( "Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev ); + if (!bSuppressErrorSpew) { + printf("Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev); + } return false; } nAttributesLength = buf[ 2 ]; - if ( nAttributesLength > res ) - { - if ( !bSuppressErrorSpew ) - printf( "Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev ); + if ( nAttributesLength > res ) { + if (!bSuppressErrorSpew) { + printf("Bad GET_ATTRIBUTES_VALUES response for controller %p\n", dev); + } return false; } msg = (FeatureReportMsg *)&buf[1]; - for ( i = 0; i < (int)msg->header.length / sizeof( ControllerAttribute ); ++i ) - { + for ( i = 0; i < (int)msg->header.length / sizeof( ControllerAttribute ); ++i ) { uint8_t unAttribute = msg->payload.getAttributes.attributes[i].attributeTag; uint32_t unValue = msg->payload.getAttributes.attributes[i].attributeValue; @@ -490,8 +479,7 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew, break; } } - if ( punUpdateRateUS ) - { + if ( punUpdateRateUS ) { *punUpdateRateUS = unUpdateRateUS; } @@ -499,10 +487,10 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew, buf[0] = 0; buf[1] = ID_CLEAR_DIGITAL_MAPPINGS; res = SetFeatureReport( dev, buf, 2 ); - if ( res < 0 ) - { - if ( !bSuppressErrorSpew ) - printf( "CLEAR_DIGITAL_MAPPINGS failed for controller %p\n", dev ); + if ( res < 0 ) { + if (!bSuppressErrorSpew) { + printf("CLEAR_DIGITAL_MAPPINGS failed for controller %p\n", dev); + } return false; } @@ -511,10 +499,10 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew, buf[1] = ID_LOAD_DEFAULT_SETTINGS; buf[2] = 0; res = SetFeatureReport( dev, buf, 3 ); - if ( res < 0 ) - { - if ( !bSuppressErrorSpew ) - printf( "LOAD_DEFAULT_SETTINGS failed for controller %p\n", dev ); + if ( res < 0 ) { + if (!bSuppressErrorSpew) { + printf("LOAD_DEFAULT_SETTINGS failed for controller %p\n", dev); + } return false; } @@ -541,10 +529,10 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \ buf[2] = nSettings*3; res = SetFeatureReport( dev, buf, 3+nSettings*3 ); - if ( res < 0 ) - { - if ( !bSuppressErrorSpew ) - printf( "SET_SETTINGS failed for controller %p\n", dev ); + if ( res < 0 ) { + if (!bSuppressErrorSpew) { + printf("SET_SETTINGS failed for controller %p\n", dev); + } return false; } @@ -552,37 +540,32 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \ // Wait for ID_CLEAR_DIGITAL_MAPPINGS to be processed on the controller bool bMappingsCleared = false; int iRetry; - for ( iRetry = 0; iRetry < 2; ++iRetry ) - { + for ( iRetry = 0; iRetry < 2; ++iRetry ) { SDL_memset( buf, 0, 65 ); buf[1] = ID_GET_DIGITAL_MAPPINGS; buf[2] = 1; // one byte - requesting from index 0 buf[3] = 0; res = SetFeatureReport( dev, buf, 4 ); - if ( res < 0 ) - { + if ( res < 0 ) { printf( "GET_DIGITAL_MAPPINGS failed for controller %p\n", dev ); return false; } res = ReadResponse( dev, buf, ID_GET_DIGITAL_MAPPINGS ); - if ( res < 0 || buf[1] != ID_GET_DIGITAL_MAPPINGS ) - { + if ( res < 0 || buf[1] != ID_GET_DIGITAL_MAPPINGS ) { printf( "Bad GET_DIGITAL_MAPPINGS response for controller %p\n", dev ); return false; } // If the length of the digital mappings result is not 1 (index byte, no mappings) then clearing hasn't executed - if ( buf[2] == 1 && buf[3] == 0xFF ) - { + if ( buf[2] == 1 && buf[3] == 0xFF ) { bMappingsCleared = true; break; } usleep( CONTROLLER_CONFIGURATION_DELAY_US ); } - if ( !bMappingsCleared && !bSuppressErrorSpew ) - { + if ( !bMappingsCleared && !bSuppressErrorSpew ) { printf( "Warning: CLEAR_DIGITAL_MAPPINGS never completed for controller %p\n", dev ); } @@ -598,10 +581,10 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \ buf[8] = MOUSE_BTN_RIGHT; res = SetFeatureReport( dev, buf, 9 ); - if ( res < 0 ) - { - if ( !bSuppressErrorSpew ) - printf( "SET_DIGITAL_MAPPINGS failed for controller %p\n", dev ); + if ( res < 0 ) { + if (!bSuppressErrorSpew) { + printf("SET_DIGITAL_MAPPINGS failed for controller %p\n", dev); + } return false; } #endif // ENABLE_MOUSE_MODE @@ -655,12 +638,9 @@ static void CloseSteamController( SDL_hid_device *dev ) //--------------------------------------------------------------------------- static float RemapValClamped( float val, float A, float B, float C, float D) { - if ( A == B ) - { + if ( A == B ) { return ( val - B ) >= 0.0f ? D : C; - } - else - { + } else { float cVal = (val - A) / (B - A); cVal = clamp( cVal, 0.0f, 1.0f ); @@ -713,65 +693,52 @@ static void FormatStatePacketUntilGyro( SteamControllerStateInternal_t *pState, pState->ulButtons &= ~0xFFFF000000LL; // The firmware uses this bit to tell us what kind of data is packed into the left two axises - if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) - { + if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK) { // Finger-down bit not set; "left pad" is actually trackpad pState->sLeftPadX = pState->sPrevLeftPad[0] = pStatePacket->sLeftPadX; pState->sLeftPadY = pState->sPrevLeftPad[1] = pStatePacket->sLeftPadY; - if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) - { + if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) { // The controller is interleaving both stick and pad data, both are active pState->sLeftStickX = pState->sPrevLeftStick[0]; pState->sLeftStickY = pState->sPrevLeftStick[1]; - } - else - { + } else { // The stick is not active pState->sPrevLeftStick[0] = 0; pState->sPrevLeftStick[1] = 0; } - } - else - { + } else { // Finger-down bit not set; "left pad" is actually joystick // XXX there's a firmware bug where sometimes padX is 0 and padY is a large number (acutally the battery voltage) // If that happens skip this packet and report last frames stick /* - if ( m_eControllerType == k_eControllerType_SteamControllerV2 && pStatePacket->sLeftPadY > 900 ) - { + if ( m_eControllerType == k_eControllerType_SteamControllerV2 && pStatePacket->sLeftPadY > 900 ) { pState->sLeftStickX = pState->sPrevLeftStick[0]; pState->sLeftStickY = pState->sPrevLeftStick[1]; - } - else + } else */ { pState->sPrevLeftStick[0] = pState->sLeftStickX = pStatePacket->sLeftPadX; pState->sPrevLeftStick[1] = pState->sLeftStickY = pStatePacket->sLeftPadY; } /* - if (m_eControllerType == k_eControllerType_SteamControllerV2) - { + if (m_eControllerType == k_eControllerType_SteamControllerV2) { UpdateV2JoystickCap(&state); } */ - if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) - { + if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) { // The controller is interleaving both stick and pad data, both are active pState->sLeftPadX = pState->sPrevLeftPad[0]; pState->sLeftPadY = pState->sPrevLeftPad[1]; - } - else - { + } else { // The trackpad is not active pState->sPrevLeftPad[0] = 0; pState->sPrevLeftPad[1] = 0; // Old controllers send trackpad click for joystick button when trackpad is not active - if (pState->ulButtons & STEAM_BUTTON_LEFTPAD_CLICKED_MASK) - { + if (pState->ulButtons & STEAM_BUTTON_LEFTPAD_CLICKED_MASK) { pState->ulButtons &= ~STEAM_BUTTON_LEFTPAD_CLICKED_MASK; pState->ulButtons |= STEAM_JOYSTICK_BUTTON_MASK; } @@ -780,8 +747,9 @@ static void FormatStatePacketUntilGyro( SteamControllerStateInternal_t *pState, // Fingerdown bit indicates if the packed left axis data was joystick or pad, // but if we are interleaving both, the left finger is definitely on the pad. - if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) + if (pStatePacket->ButtonTriggerData.ulButtons & STEAM_LEFTPAD_AND_JOYSTICK_MASK) { pState->ulButtons |= STEAM_LEFTPAD_FINGERDOWN_MASK; + } pState->sRightPadX = pStatePacket->sRightPadX; pState->sRightPadY = pStatePacket->sRightPadY; @@ -827,35 +795,30 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize, pState->unPacketNum++; ucOptionDataMask = ( *pData++ & 0xF0 ); ucOptionDataMask |= (uint32_t)(*pData++) << 8; - if ( ucOptionDataMask & k_EBLEButtonChunk1 ) - { + if ( ucOptionDataMask & k_EBLEButtonChunk1 ) { SDL_memcpy( &pState->ulButtons, pData, 3 ); pData += 3; } - if ( ucOptionDataMask & k_EBLEButtonChunk2 ) - { + if ( ucOptionDataMask & k_EBLEButtonChunk2 ) { // The middle 2 bytes of the button bits over the wire are triggers when over the wire and non-SC buttons in the internal controller state packet pState->sTriggerL = (unsigned short)RemapValClamped( (float)(( pData[ 0 ] << 7 ) | pData[ 0 ]), 0, STEAMCONTROLLER_TRIGGER_MAX_ANALOG, 0, SDL_MAX_SINT16 ); pState->sTriggerR = (unsigned short)RemapValClamped( (float)(( pData[ 1 ] << 7 ) | pData[ 1 ]), 0, STEAMCONTROLLER_TRIGGER_MAX_ANALOG, 0, SDL_MAX_SINT16 ); pData += 2; } - if ( ucOptionDataMask & k_EBLEButtonChunk3 ) - { + if ( ucOptionDataMask & k_EBLEButtonChunk3 ) { uint8_t *pButtonByte = (uint8_t *)&pState->ulButtons; pButtonByte[ 5 ] = *pData++; pButtonByte[ 6 ] = *pData++; pButtonByte[ 7 ] = *pData++; } - if ( ucOptionDataMask & k_EBLELeftJoystickChunk ) - { + if ( ucOptionDataMask & k_EBLELeftJoystickChunk ) { // This doesn't handle any of the special headcrab stuff for raw joystick which is OK for now since that FW doesn't support // this protocol yet either int nLength = sizeof( pState->sLeftStickX ) + sizeof( pState->sLeftStickY ); SDL_memcpy( &pState->sLeftStickX, pData, nLength ); pData += nLength; } - if ( ucOptionDataMask & k_EBLELeftTrackpadChunk ) - { + if ( ucOptionDataMask & k_EBLELeftTrackpadChunk ) { int nLength = sizeof( pState->sLeftPadX ) + sizeof( pState->sLeftPadY ); int nPadOffset; SDL_memcpy( &pState->sLeftPadX, pData, nLength ); @@ -869,8 +832,7 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize, pState->sLeftPadY = clamp( pState->sLeftPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16 ); pData += nLength; } - if ( ucOptionDataMask & k_EBLERightTrackpadChunk ) - { + if ( ucOptionDataMask & k_EBLERightTrackpadChunk ) { int nLength = sizeof( pState->sRightPadX ) + sizeof( pState->sRightPadY ); int nPadOffset = 0; @@ -886,20 +848,17 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize, pState->sRightPadY = clamp( pState->sRightPadY + nPadOffset, SDL_MIN_SINT16, SDL_MAX_SINT16 ); pData += nLength; } - if ( ucOptionDataMask & k_EBLEIMUAccelChunk ) - { + if ( ucOptionDataMask & k_EBLEIMUAccelChunk ) { int nLength = sizeof( pState->sAccelX ) + sizeof( pState->sAccelY ) + sizeof( pState->sAccelZ ); SDL_memcpy( &pState->sAccelX, pData, nLength ); pData += nLength; } - if ( ucOptionDataMask & k_EBLEIMUGyroChunk ) - { + if ( ucOptionDataMask & k_EBLEIMUGyroChunk ) { int nLength = sizeof( pState->sAccelX ) + sizeof( pState->sAccelY ) + sizeof( pState->sAccelZ ); SDL_memcpy( &pState->sGyroX, pData, nLength ); pData += nLength; } - if ( ucOptionDataMask & k_EBLEIMUQuatChunk ) - { + if ( ucOptionDataMask & k_EBLEIMUQuatChunk ) { int nLength = sizeof( pState->sGyroQuatW ) + sizeof( pState->sGyroQuatX ) + sizeof( pState->sGyroQuatY ) + sizeof( pState->sGyroQuatZ ); SDL_memcpy( &pState->sGyroQuatW, pData, nLength ); pData += nLength; @@ -915,10 +874,8 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste { ValveInReport_t *pInReport = (ValveInReport_t*)pData; - if ( pInReport->header.unReportVersion != k_ValveInReportMsgVersion ) - { - if ( ( pData[ 0 ] & 0x0F ) == k_EBLEReportState ) - { + if ( pInReport->header.unReportVersion != k_ValveInReportMsgVersion ) { + if ( ( pData[ 0 ] & 0x0F ) == k_EBLEReportState ) { return UpdateBLESteamControllerState( pData, nDataSize, pState ); } return false; @@ -930,13 +887,13 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste return false; } - if ( pInReport->header.ucType == ID_CONTROLLER_STATE ) - { + if ( pInReport->header.ucType == ID_CONTROLLER_STATE ) { ValveControllerStatePacket_t *pStatePacket = &pInReport->payload.controllerState; // No new data to process; indicate that we received a state packet, but otherwise do nothing. - if ( pState->unPacketNum == pStatePacket->unPacketNum ) + if (pState->unPacketNum == pStatePacket->unPacketNum) { return true; + } FormatStatePacketUntilGyro( pState, pStatePacket ); @@ -953,15 +910,14 @@ static bool UpdateSteamControllerState( const uint8_t *pData, int nDataSize, Ste pState->sGyroY = pStatePacket->sGyroY; pState->sGyroZ = pStatePacket->sGyroZ; - } - else if ( pInReport->header.ucType == ID_CONTROLLER_BLE_STATE ) - { + } else if ( pInReport->header.ucType == ID_CONTROLLER_BLE_STATE ) { ValveControllerBLEStatePacket_t *pBLEStatePacket = &pInReport->payload.controllerBLEState; ValveControllerStatePacket_t *pStatePacket = &pInReport->payload.controllerState; // No new data to process; indicate that we received a state packet, but otherwise do nothing. - if ( pState->unPacketNum == pStatePacket->unPacketNum ) + if (pState->unPacketNum == pStatePacket->unPacketNum) { return true; + } FormatStatePacketUntilGyro( pState, pStatePacket ); @@ -1037,7 +993,7 @@ HIDAPI_DriverSteam_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverSteam_Context *ctx; ctx = (SDL_DriverSteam_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -1167,8 +1123,7 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device) return SDL_FALSE; } - for (;;) - { + for (;;) { uint8_t data[128]; int r, nPacketLength; const Uint8 *pPacket; @@ -1178,7 +1133,7 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device) break; } - if (!joystick) { + if (joystick == NULL) { continue; } diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index dd044a2fc5..85d8b735fc 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -396,9 +396,9 @@ static SDL_bool WritePacket(SDL_DriverSwitch_Context *ctx, void *pBuf, Uint8 ucL ucLen = (Uint8)unWriteSize; } if (ctx->m_bSyncWrite) { - return (SDL_hid_write(ctx->device->dev, (Uint8 *)pBuf, ucLen) >= 0); + return SDL_hid_write(ctx->device->dev, (Uint8 *)pBuf, ucLen) >= 0; } else { - return (WriteOutput(ctx, (Uint8 *)pBuf, ucLen) >= 0); + return WriteOutput(ctx, (Uint8 *)pBuf, ucLen) >= 0; } } @@ -407,7 +407,7 @@ static SDL_bool WriteSubcommand(SDL_DriverSwitch_Context *ctx, ESwitchSubcommand SwitchSubcommandInputPacket_t *reply = NULL; int nTries; - for (nTries = 1; !reply && nTries <= ctx->m_nMaxWriteAttempts; ++nTries) { + for (nTries = 1; reply == NULL && nTries <= ctx->m_nMaxWriteAttempts; ++nTries) { SwitchSubcommandOutputPacket_t commandPacket; ConstructSubcommand(ctx, ucCommandID, pBuf, ucLen, &commandPacket); @@ -431,7 +431,7 @@ static SDL_bool WriteProprietary(SDL_DriverSwitch_Context *ctx, ESwitchProprieta for (nTries = 1; nTries <= ctx->m_nMaxWriteAttempts; ++nTries) { SwitchProprietaryOutputPacket_t packet; - if ((!pBuf && ucLen > 0) || ucLen > sizeof(packet.rgucProprietaryData)) { + if ((pBuf == NULL && ucLen > 0) || ucLen > sizeof(packet.rgucProprietaryData)) { return SDL_FALSE; } @@ -592,8 +592,9 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx) ctx->m_eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)status->ucDeviceType); - for (i = 0; i < sizeof (ctx->m_rgucMACAddress); ++i) - ctx->m_rgucMACAddress[i] = status->rgucMACAddress[ sizeof(ctx->m_rgucMACAddress) - i - 1 ]; + for (i = 0; i < sizeof(ctx->m_rgucMACAddress); ++i) { + ctx->m_rgucMACAddress[i] = status->rgucMACAddress[sizeof(ctx->m_rgucMACAddress) - i - 1]; + } return SDL_TRUE; } @@ -772,14 +773,14 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_ } for (stick = 0; stick < 2; ++stick) { - for(axis = 0; axis < 2; ++axis) { + for (axis = 0; axis < 2; ++axis) { ctx->m_StickExtents[stick].axis[axis].sMin = -(Sint16)(ctx->m_StickCalData[stick].axis[axis].sMin * 0.7f); ctx->m_StickExtents[stick].axis[axis].sMax = (Sint16)(ctx->m_StickCalData[stick].axis[axis].sMax * 0.7f); } } for (stick = 0; stick < 2; ++stick) { - for(axis = 0; axis < 2; ++axis) { + for (axis = 0; axis < 2; ++axis) { ctx->m_SimpleStickExtents[stick].axis[axis].sMin = (Sint16)(SDL_MIN_SINT16 * 0.5f); ctx->m_SimpleStickExtents[stick].axis[axis].sMax = (Sint16)(SDL_MAX_SINT16 * 0.5f); } @@ -865,7 +866,8 @@ static Sint16 ApplyStickCalibration(SDL_DriverSwitch_Context *ctx, int nStick, i ctx->m_StickExtents[nStick].axis[nAxis].sMin = sRawValue; } - return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_StickExtents[nStick].axis[nAxis].sMin, ctx->m_StickExtents[nStick].axis[nAxis].sMax, SDL_MIN_SINT16, SDL_MAX_SINT16); + return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_StickExtents[nStick].axis[nAxis].sMin, ctx->m_StickExtents[nStick].axis[nAxis].sMax, + SDL_MIN_SINT16, SDL_MAX_SINT16); } static Sint16 ApplySimpleStickCalibration(SDL_DriverSwitch_Context *ctx, int nStick, int nAxis, Sint16 sRawValue) @@ -882,7 +884,8 @@ static Sint16 ApplySimpleStickCalibration(SDL_DriverSwitch_Context *ctx, int nSt ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin = sRawValue; } - return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMax, SDL_MIN_SINT16, SDL_MAX_SINT16); + return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMin, ctx->m_SimpleStickExtents[nStick].axis[nAxis].sMax, + SDL_MIN_SINT16, SDL_MAX_SINT16); } static void SDLCALL SDL_GameControllerButtonReportingHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint) @@ -1047,9 +1050,7 @@ HIDAPI_DriverNintendoClassic_UnregisterHints(SDL_HintCallback callback, void *us static SDL_bool HIDAPI_DriverNintendoClassic_IsEnabled(void) { - return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)); + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); } static SDL_bool @@ -1093,9 +1094,7 @@ HIDAPI_DriverJoyCons_UnregisterHints(SDL_HintCallback callback, void *userdata) static SDL_bool HIDAPI_DriverJoyCons_IsEnabled(void) { - return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)); + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); } static SDL_bool @@ -1135,9 +1134,7 @@ HIDAPI_DriverSwitch_UnregisterHints(SDL_HintCallback callback, void *userdata) static SDL_bool HIDAPI_DriverSwitch_IsEnabled(void) { - return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)); + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); } static SDL_bool @@ -1228,7 +1225,7 @@ HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverSwitch_Context *ctx; ctx = (SDL_DriverSwitch_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -2138,7 +2135,7 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device) ++packet_count; ctx->m_unLastInput = now; - if (!joystick) { + if (joystick == NULL) { continue; } @@ -2197,7 +2194,7 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_wii.c b/src/joystick/hidapi/SDL_hidapi_wii.c index 9ef4281994..2c71bd1b85 100644 --- a/src/joystick/hidapi/SDL_hidapi_wii.c +++ b/src/joystick/hidapi/SDL_hidapi_wii.c @@ -211,13 +211,13 @@ static SDL_bool WriteOutput(SDL_DriverWii_Context *ctx, const Uint8 *data, int s } #endif if (sync) { - return (SDL_hid_write(ctx->device->dev, data, size) >= 0); + return SDL_hid_write(ctx->device->dev, data, size) >= 0; } else { /* Use the rumble thread for general asynchronous writes */ if (SDL_HIDAPI_LockRumble() < 0) { return SDL_FALSE; } - return (SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size) >= 0); + return SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size) >= 0; } } @@ -229,7 +229,7 @@ static SDL_bool ReadInputSync(SDL_DriverWii_Context *ctx, EWiiInputReportIDs exp int nRead = 0; while ((nRead = ReadInput(ctx)) != -1) { if (nRead > 0) { - if (ctx->m_rgucReadBuffer[0] == expectedID && (!isMine || isMine(ctx->m_rgucReadBuffer))) { + if (ctx->m_rgucReadBuffer[0] == expectedID && (isMine == NULL || isMine(ctx->m_rgucReadBuffer))) { return SDL_TRUE; } } else { @@ -729,7 +729,7 @@ HIDAPI_DriverWii_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverWii_Context *ctx; ctx = (SDL_DriverWii_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -1524,7 +1524,7 @@ HIDAPI_DriverWii_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 26eda3e9e3..dce6aed428 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -60,9 +60,7 @@ static SDL_bool HIDAPI_DriverXbox360_IsEnabled(void) { return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX_360, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT))); + SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT))); } static SDL_bool @@ -145,7 +143,7 @@ HIDAPI_DriverXbox360_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverXbox360_Context *ctx; ctx = (SDL_DriverXbox360_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -343,7 +341,7 @@ HIDAPI_DriverXbox360_UpdateDevice(SDL_HIDAPI_Device *device) #ifdef DEBUG_XBOX_PROTOCOL HIDAPI_DumpPacket("Xbox 360 packet: size = %d", data, size); #endif - if (!joystick) { + if (joystick == NULL) { continue; } @@ -356,7 +354,7 @@ HIDAPI_DriverXbox360_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360w.c b/src/joystick/hidapi/SDL_hidapi_xbox360w.c index bdb60607c3..c388f777c9 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360w.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360w.c @@ -63,10 +63,7 @@ static SDL_bool HIDAPI_DriverXbox360W_IsEnabled(void) { return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_WIRELESS, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX_360, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT)))); + SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX_360, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)))); } static SDL_bool @@ -142,7 +139,7 @@ HIDAPI_DriverXbox360W_InitDevice(SDL_HIDAPI_Device *device) HIDAPI_SetDeviceName(device, "Xbox 360 Wireless Controller"); ctx = (SDL_DriverXbox360W_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -171,7 +168,7 @@ HIDAPI_DriverXbox360W_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_Joysti { SDL_DriverXbox360W_Context *ctx = (SDL_DriverXbox360W_Context *)device->context; - if (!ctx) { + if (ctx == NULL) { return; } @@ -356,7 +353,7 @@ HIDAPI_DriverXbox360W_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index b48d3a3c35..c23563a285 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -136,7 +136,7 @@ typedef struct { static SDL_bool ControllerHasColorLED(Uint16 vendor_id, Uint16 product_id) { - return (vendor_id == USB_VENDOR_MICROSOFT && product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2); + return vendor_id == USB_VENDOR_MICROSOFT && product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2; } static SDL_bool @@ -353,9 +353,7 @@ static SDL_bool HIDAPI_DriverXboxOne_IsEnabled(void) { return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX, - SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, - SDL_HIDAPI_DEFAULT))); + SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_XBOX, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT))); } static SDL_bool @@ -376,7 +374,7 @@ HIDAPI_DriverXboxOne_InitDevice(SDL_HIDAPI_Device *device) SDL_DriverXboxOne_Context *ctx; ctx = (SDL_DriverXboxOne_Context *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -1101,7 +1099,7 @@ HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device) if (ctx->bluetooth) { switch (data[0]) { case 0x01: - if (!joystick) { + if (joystick == NULL) { break; } if (size >= 16) { @@ -1113,13 +1111,13 @@ HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device) } break; case 0x02: - if (!joystick) { + if (joystick == NULL) { break; } HIDAPI_DriverXboxOneBluetooth_HandleGuidePacket(joystick, ctx, data, size); break; case 0x04: - if (!joystick) { + if (joystick == NULL) { break; } HIDAPI_DriverXboxOneBluetooth_HandleBatteryPacket(joystick, ctx, data, size); @@ -1167,7 +1165,7 @@ HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device) break; case 0x03: /* Controller status update */ - if (!joystick) { + if (joystick == NULL) { /* We actually want to handle this packet any time it arrives */ /*break;*/ } @@ -1180,7 +1178,7 @@ HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device) /* Unknown chatty controller information, sent by both sides */ break; case 0x07: - if (!joystick) { + if (joystick == NULL) { break; } HIDAPI_DriverXboxOne_HandleModePacket(joystick, ctx, data, size); @@ -1195,7 +1193,7 @@ HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device) The controller sends that in response to this request: 0x1E 0x30 0x07 0x01 0x04 */ - if (!joystick) { + if (joystick == NULL) { break; } #ifdef SET_SERIAL_AFTER_OPEN @@ -1214,7 +1212,7 @@ HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device) #endif break; } - if (!joystick) { + if (joystick == NULL) { break; } HIDAPI_DriverXboxOne_HandleStatePacket(joystick, ctx, data, size); @@ -1249,7 +1247,7 @@ HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device) /* Read error, device is disconnected */ HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return (size >= 0); + return size >= 0; } static void diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index a6bb2b1b16..7228d0381f 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -389,7 +389,7 @@ HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device, SDL_bool *removed) for (curr = SDL_HIDAPI_devices; curr && curr != device; curr = curr->next) { continue; } - if (!curr) { + if (curr == NULL) { *removed = SDL_TRUE; if (dev) { SDL_hid_close(dev); @@ -397,7 +397,7 @@ HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device, SDL_bool *removed) return; } - if (!dev) { + if (dev == NULL) { SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "HIDAPI_SetupDeviceDriver() couldn't open %s: %s\n", device->path, SDL_GetError()); @@ -513,7 +513,7 @@ static SDL_bool HIDAPI_AddJoystickInstanceToDevice(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID) { SDL_JoystickID *joysticks = (SDL_JoystickID *)SDL_realloc(device->joysticks, (device->num_joysticks + 1)*sizeof(*device->joysticks)); - if (!joysticks) { + if (joysticks == NULL) { return SDL_FALSE; } @@ -583,7 +583,7 @@ HIDAPI_HasConnectedUSBDevice(const char *serial) { SDL_HIDAPI_Device *device; - if (!serial) { + if (serial == NULL) { return SDL_FALSE; } @@ -608,7 +608,7 @@ HIDAPI_DisconnectBluetoothDevice(const char *serial) { SDL_HIDAPI_Device *device; - if (!serial) { + if (serial == NULL) { return; } @@ -713,7 +713,7 @@ HIDAPI_ConvertString(const wchar_t *wide_string) if (wide_string) { string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)wide_string, (SDL_wcslen(wide_string)+1)*sizeof(wchar_t)); - if (!string) { + if (string == NULL) { switch (sizeof(wchar_t)) { case 2: string = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char*)wide_string, (SDL_wcslen(wide_string)+1)*sizeof(wchar_t)); @@ -739,7 +739,7 @@ HIDAPI_AddDevice(const struct SDL_hid_device_info *info, int num_children, SDL_H } device = (SDL_HIDAPI_Device *)SDL_calloc(1, sizeof(*device)); - if (!device) { + if (device == NULL) { return NULL; } device->path = SDL_strdup(info->path); @@ -903,7 +903,7 @@ HIDAPI_CreateCombinedJoyCons() if (joycons[0] && joycons[1]) { SDL_hid_device_info info; SDL_HIDAPI_Device **children = (SDL_HIDAPI_Device **)SDL_malloc(2 * sizeof(SDL_HIDAPI_Device *)); - if (!children) { + if (children == NULL) { return SDL_FALSE; } children[0] = joycons[0]; @@ -1295,13 +1295,13 @@ HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index) SDL_HIDAPI_Device *device = HIDAPI_GetDeviceByIndex(device_index, &joystickID); struct joystick_hwdata *hwdata; - if (!device || !device->driver) { + if (device == NULL || !device->driver) { /* This should never happen - validated before being called */ return SDL_SetError("Couldn't find HIDAPI device at index %d\n", device_index); } hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(*hwdata)); - if (!hwdata) { + if (hwdata == NULL) { return SDL_OutOfMemory(); } hwdata->device = device; diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index ed889eaf69..6fbb9cc4da 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -172,7 +172,7 @@ GuessIsJoystick(int fd) (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) < 0) || (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) { - return (0); + return 0; } devclass = SDL_EVDEV_GuessDeviceClass(evbit, absbit, keybit, relbit); @@ -212,7 +212,7 @@ IsJoystick(const char *path, int fd, char **name_return, SDL_JoystickGUID *guid) } name = SDL_CreateJoystickName(inpid.vendor, inpid.product, NULL, product_string); - if (!name) { + if (name == NULL) { return 0; } @@ -484,7 +484,7 @@ static void SteamControllerDisconnectedCallback(int device_instance) static int StrHasPrefix(const char *string, const char *prefix) { - return (SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0); + return SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0; } static int @@ -512,7 +512,7 @@ IsJoystickJSNode(const char *node) if (last_slash) { node = last_slash + 1; } - return (StrHasPrefix(node, "js") && StrIsInteger(node + 2)); + return StrHasPrefix(node, "js") && StrIsInteger(node + 2); } static SDL_bool @@ -522,7 +522,7 @@ IsJoystickEventNode(const char *node) if (last_slash) { node = last_slash + 1; } - return (StrHasPrefix(node, "event") && StrIsInteger(node + 5)); + return StrHasPrefix(node, "event") && StrIsInteger(node + 5); } static SDL_bool @@ -543,7 +543,9 @@ static int SDL_inotify_init1(void) { #else static int SDL_inotify_init1(void) { int fd = inotify_init(); - if (fd < 0) return -1; + if (fd < 0) { + return -1; + } fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(fd, F_SETFD, FD_CLOEXEC); return fd; @@ -577,8 +579,7 @@ LINUX_InotifyJoystickDetect(void) if (buf.event.mask & (IN_CREATE | IN_MOVED_TO | IN_ATTRIB)) { MaybeAddDevice(path); - } - else if (buf.event.mask & (IN_DELETE | IN_MOVED_FROM)) { + } else if (buf.event.mask & (IN_DELETE | IN_MOVED_FROM)) { MaybeRemoveDevice(path); } } @@ -654,7 +655,7 @@ sort_entries(const void *_a, const void *_b) } } } - return (numA - numB); + return numA - numB; } static void @@ -697,14 +698,12 @@ LINUX_JoystickDetect(void) #if SDL_USE_LIBUDEV if (enumeration_method == ENUMERATION_LIBUDEV) { SDL_UDEV_Poll(); - } - else + } else #endif #ifdef HAVE_INOTIFY if (inotify_fd >= 0 && last_joy_detect_time != 0) { LINUX_InotifyJoystickDetect(); - } - else + } else #endif { LINUX_FallbackJoystickDetect(); @@ -781,8 +780,7 @@ LINUX_JoystickInit(void) /* Force a scan to build the initial device list */ SDL_UDEV_Scan(); - } - else + } else #endif { #if defined(HAVE_INOTIFY) @@ -882,13 +880,13 @@ allocate_hatdata(SDL_Joystick *joystick) (struct hwdata_hat *) SDL_malloc(joystick->nhats * sizeof(struct hwdata_hat)); if (joystick->hwdata->hats == NULL) { - return (-1); + return -1; } for (i = 0; i < joystick->nhats; ++i) { joystick->hwdata->hats[i].axis[0] = 1; joystick->hwdata->hats[i].axis[1] = 1; } - return (0); + return 0; } static int @@ -900,13 +898,13 @@ allocate_balldata(SDL_Joystick *joystick) (struct hwdata_ball *) SDL_malloc(joystick->nballs * sizeof(struct hwdata_ball)); if (joystick->hwdata->balls == NULL) { - return (-1); + return -1; } for (i = 0; i < joystick->nballs; ++i) { joystick->hwdata->balls[i].axis[0] = 0; joystick->hwdata->balls[i].axis[1] = 0; } - return (0); + return 0; } static SDL_bool @@ -919,22 +917,24 @@ GuessIfAxesAreDigitalHat(struct input_absinfo *absinfo_x, struct input_absinfo * * other continuous analog axis, so we have to guess. */ /* If both axes are missing, they're not anything. */ - if (!absinfo_x && !absinfo_y) + if (absinfo_x == NULL && absinfo_y == NULL) { return SDL_FALSE; + } /* If the hint says so, treat all hats as digital. */ - if (SDL_GetHintBoolean(SDL_HINT_LINUX_DIGITAL_HATS, SDL_FALSE)) + if (SDL_GetHintBoolean(SDL_HINT_LINUX_DIGITAL_HATS, SDL_FALSE)) { return SDL_TRUE; + } /* If both axes have ranges constrained between -1 and 1, they're definitely digital. */ - if ((!absinfo_x || (absinfo_x->minimum == -1 && absinfo_x->maximum == 1)) && - (!absinfo_y || (absinfo_y->minimum == -1 && absinfo_y->maximum == 1))) + if ((absinfo_x == NULL || (absinfo_x->minimum == -1 && absinfo_x->maximum == 1)) && (absinfo_y == NULL || (absinfo_y->minimum == -1 && absinfo_y->maximum == 1))) { return SDL_TRUE; + } /* If both axes lack fuzz, flat, and resolution values, they're probably digital. */ - if ((!absinfo_x || (!absinfo_x->fuzz && !absinfo_x->flat && !absinfo_x->resolution)) && - (!absinfo_y || (!absinfo_y->fuzz && !absinfo_y->flat && !absinfo_y->resolution))) + if ((absinfo_x == NULL || (!absinfo_x->fuzz && !absinfo_x->flat && !absinfo_x->resolution)) && (absinfo_y == NULL || (!absinfo_y->fuzz && !absinfo_y->flat && !absinfo_y->resolution))) { return SDL_TRUE; + } /* Otherwise, treat them as analog. */ return SDL_FALSE; @@ -983,10 +983,12 @@ ConfigJoystick(SDL_Joystick *joystick, int fd) int hat_y = -1; struct input_absinfo absinfo_x; struct input_absinfo absinfo_y; - if (test_bit(i, absbit)) + if (test_bit(i, absbit)) { hat_x = ioctl(fd, EVIOCGABS(i), &absinfo_x); - if (test_bit(i + 1, absbit)) + } + if (test_bit(i + 1, absbit)) { hat_y = ioctl(fd, EVIOCGABS(i + 1), &absinfo_y); + } if (GuessIfAxesAreDigitalHat((hat_x < 0 ? (void*)0 : &absinfo_x), (hat_y < 0 ? (void*)0 : &absinfo_y))) { const int hat_index = (i - ABS_HAT0X) / 2; diff --git a/src/joystick/n3ds/SDL_sysjoystick.c b/src/joystick/n3ds/SDL_sysjoystick.c index e1e344a119..bd6c7e14c6 100644 --- a/src/joystick/n3ds/SDL_sysjoystick.c +++ b/src/joystick/n3ds/SDL_sysjoystick.c @@ -194,7 +194,7 @@ static SDL_bool N3DS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out) { /* There is only one possible mapping. */ - *out = (SDL_GamepadMapping){ + *out = (SDL_GamepadMapping) { .a = { EMappingKind_Button, 0 }, .b = { EMappingKind_Button, 1 }, .x = { EMappingKind_Button, 10 }, diff --git a/src/joystick/ps2/SDL_sysjoystick.c b/src/joystick/ps2/SDL_sysjoystick.c index a8002a4fc3..0bbac2357c 100644 --- a/src/joystick/ps2/SDL_sysjoystick.c +++ b/src/joystick/ps2/SDL_sysjoystick.c @@ -58,8 +58,9 @@ static struct JoyInfo joyInfo[MAX_CONTROLLERS]; static inline int16_t convert_u8_to_s16(uint8_t val) { - if (val == 0) + if (val == 0) { return -0x7fff; + } return val * 0x0101 - 0x8000; } @@ -93,11 +94,13 @@ static int PS2_JoystickInit(void) uint32_t port = 0; uint32_t slot = 0; - if(init_joystick_driver(true) < 0) + if (init_joystick_driver(true) < 0) { return -1; + } - for (port = 0; port < PS2_MAX_PORT; port++) + for (port = 0; port < PS2_MAX_PORT; port++) { mtapPortOpen(port); + } /* it can fail - we dont care, we will check it more strictly when padPortOpen */ for (slot = 0; slot < PS2_MAX_SLOT; slot++) { @@ -114,7 +117,7 @@ static int PS2_JoystickInit(void) */ struct JoyInfo *info = &joyInfo[enabled_pads]; - if(padPortOpen(port, slot, (void *)info->padBuf) > 0) { + if (padPortOpen(port, slot, (void *)info->padBuf) > 0) { info->port = (uint8_t)port; info->slot = (uint8_t)slot; info->opened = 1; @@ -140,8 +143,9 @@ static void PS2_JoystickDetect() /* Function to get the device-dependent name of a joystick */ static const char *PS2_JoystickGetDeviceName(int index) { - if (index >= 0 && index < enabled_pads) + if (index >= 0 && index < enabled_pads) { return "PS2 Controller"; + } SDL_SetError("No joystick available with that index"); return NULL; @@ -283,8 +287,9 @@ static void PS2_JoystickUpdate(SDL_Joystick *joystick) mask = (1 << i); previous = info->btns & mask; current = pressed_buttons & mask; - if (previous != current) + if (previous != current) { SDL_PrivateJoystickButton(joystick, i, current ? SDL_PRESSED : SDL_RELEASED); + } } } info->btns = pressed_buttons; @@ -298,8 +303,9 @@ static void PS2_JoystickUpdate(SDL_Joystick *joystick) for (i = 0; i < PS2_TOTAL_AXIS; i++) { previous_axis = info->analog_state[i]; current_axis = all_axis[i]; - if (previous_axis != current_axis) + if (previous_axis != current_axis) { SDL_PrivateJoystickAxis(joystick, i, convert_u8_to_s16(current_axis)); + } info->analog_state[i] = current_axis; } diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c index 0969474f22..61725cee20 100644 --- a/src/joystick/psp/SDL_sysjoystick.c +++ b/src/joystick/psp/SDL_sysjoystick.c @@ -87,8 +87,7 @@ static int PSP_JoystickInit(void) /* Create an accurate map from analog inputs (0 to 255) to SDL joystick positions (-32768 to 32767) */ - for (i = 0; i < 128; i++) - { + for (i = 0; i < 128; i++) { float t = (float)i/127.0f; analog_map[i+128] = calc_bezier_y(t); analog_map[127-i] = -1 * analog_map[i+128]; @@ -109,11 +108,12 @@ static void PSP_JoystickDetect(void) /* Function to get the device-dependent name of a joystick */ static const char *PSP_JoystickGetDeviceName(int device_index) { - if (device_index == 0) + if (device_index == 0) { return "PSP builtin joypad"; + } SDL_SetError("No joystick available with that index"); - return(NULL); + return NULL; } static const char *PSP_JoystickGetDevicePath(int index) @@ -208,11 +208,11 @@ static void PSP_JoystickUpdate(SDL_Joystick *joystick) y = pad.Ly; /* Axes */ - if(old_x != x) { + if (old_x != x) { SDL_PrivateJoystickAxis(joystick, 0, analog_map[x]); old_x = x; } - if(old_y != y) { + if (old_y != y) { SDL_PrivateJoystickAxis(joystick, 1, analog_map[y]); old_y = y; } @@ -220,7 +220,7 @@ static void PSP_JoystickUpdate(SDL_Joystick *joystick) /* Buttons */ changed = old_buttons ^ buttons; old_buttons = buttons; - if(changed) { + if (changed) { for (i = 0; i < SDL_arraysize(button_map); i++) { if (changed & button_map[i]) { SDL_PrivateJoystickButton( diff --git a/src/joystick/virtual/SDL_virtualjoystick.c b/src/joystick/virtual/SDL_virtualjoystick.c index 3b6ada4248..4c796102cc 100644 --- a/src/joystick/virtual/SDL_virtualjoystick.c +++ b/src/joystick/virtual/SDL_virtualjoystick.c @@ -37,8 +37,9 @@ VIRTUAL_HWDataForIndex(int device_index) { joystick_hwdata *vjoy = g_VJoys; while (vjoy) { - if (device_index == 0) + if (device_index == 0) { break; + } --device_index; vjoy = vjoy->next; } @@ -52,7 +53,7 @@ VIRTUAL_FreeHWData(joystick_hwdata *hwdata) joystick_hwdata * cur = g_VJoys; joystick_hwdata * prev = NULL; - if (!hwdata) { + if (hwdata == NULL) { return; } @@ -103,7 +104,7 @@ SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *desc) int axis_triggerleft = -1; int axis_triggerright = -1; - if (!desc) { + if (desc == NULL) { return SDL_InvalidParamError("desc"); } if (desc->version != SDL_VIRTUAL_JOYSTICK_DESC_VERSION) { @@ -112,7 +113,7 @@ SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *desc) } hwdata = SDL_calloc(1, sizeof(joystick_hwdata)); - if (!hwdata) { + if (hwdata == NULL) { VIRTUAL_FreeHWData(hwdata); return SDL_OutOfMemory(); } @@ -252,7 +253,7 @@ SDL_JoystickDetachVirtualInner(int device_index) { SDL_JoystickID instance_id; joystick_hwdata *hwdata = VIRTUAL_HWDataForIndex(device_index); - if (!hwdata) { + if (hwdata == NULL) { return SDL_SetError("Virtual joystick data not found"); } instance_id = hwdata->instance_id; @@ -269,7 +270,7 @@ SDL_JoystickSetVirtualAxisInner(SDL_Joystick *joystick, int axis, Sint16 value) SDL_LockJoysticks(); - if (!joystick || !joystick->hwdata) { + if (joystick == NULL || !joystick->hwdata) { SDL_UnlockJoysticks(); return SDL_SetError("Invalid joystick"); } @@ -294,7 +295,7 @@ SDL_JoystickSetVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8 valu SDL_LockJoysticks(); - if (!joystick || !joystick->hwdata) { + if (joystick == NULL || !joystick->hwdata) { SDL_UnlockJoysticks(); return SDL_SetError("Invalid joystick"); } @@ -319,7 +320,7 @@ SDL_JoystickSetVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value) SDL_LockJoysticks(); - if (!joystick || !joystick->hwdata) { + if (joystick == NULL || !joystick->hwdata) { SDL_UnlockJoysticks(); return SDL_SetError("Invalid joystick"); } @@ -367,7 +368,7 @@ static const char * VIRTUAL_JoystickGetDeviceName(int device_index) { joystick_hwdata *hwdata = VIRTUAL_HWDataForIndex(device_index); - if (!hwdata) { + if (hwdata == NULL) { return NULL; } return hwdata->name; @@ -403,7 +404,7 @@ static SDL_JoystickGUID VIRTUAL_JoystickGetDeviceGUID(int device_index) { joystick_hwdata *hwdata = VIRTUAL_HWDataForIndex(device_index); - if (!hwdata) { + if (hwdata == NULL) { SDL_JoystickGUID guid; SDL_zero(guid); return guid; @@ -416,7 +417,7 @@ static SDL_JoystickID VIRTUAL_JoystickGetDeviceInstanceID(int device_index) { joystick_hwdata *hwdata = VIRTUAL_HWDataForIndex(device_index); - if (!hwdata) { + if (hwdata == NULL) { return -1; } return hwdata->instance_id; @@ -427,7 +428,7 @@ static int VIRTUAL_JoystickOpen(SDL_Joystick *joystick, int device_index) { joystick_hwdata *hwdata = VIRTUAL_HWDataForIndex(device_index); - if (!hwdata) { + if (hwdata == NULL) { return SDL_SetError("No such device"); } joystick->instance_id = hwdata->instance_id; @@ -551,7 +552,7 @@ VIRTUAL_JoystickUpdate(SDL_Joystick *joystick) joystick_hwdata *hwdata; int i; - if (!joystick) { + if (joystick == NULL) { return; } if (!joystick->hwdata) { diff --git a/src/joystick/vita/SDL_sysjoystick.c b/src/joystick/vita/SDL_sysjoystick.c index 1931c57e3a..58f14efa5b 100644 --- a/src/joystick/vita/SDL_sysjoystick.c +++ b/src/joystick/vita/SDL_sysjoystick.c @@ -113,8 +113,7 @@ int VITA_JoystickInit(void) /* Create an accurate map from analog inputs (0 to 255) to SDL joystick positions (-32768 to 32767) */ - for (i = 0; i < 128; i++) - { + for (i = 0; i < 128; i++) { float t = (float)i/127.0f; analog_map[i+128] = calc_bezier_y(t); analog_map[127-i] = -1 * analog_map[i+128]; @@ -132,10 +131,8 @@ int VITA_JoystickInit(void) // On Vita TV, port 0 and 1 are the same controller // and that is the first one, so start at port 2 - for (i=2; i<=4; i++) - { - if (myPortInfo.port[i]!=SCE_CTRL_TYPE_UNPAIRED) - { + for (i=2; i<=4; i++) { + if (myPortInfo.port[i]!=SCE_CTRL_TYPE_UNPAIRED) { SDL_PrivateJoystickAdded(SDL_numjoysticks); SDL_numjoysticks++; } @@ -160,17 +157,21 @@ SDL_JoystickID VITA_JoystickGetDeviceInstanceID(int device_index) const char *VITA_JoystickGetDeviceName(int index) { - if (index == 0) + if (index == 0) { return "PSVita Controller"; + } - if (index == 1) + if (index == 1) { return "PSVita Controller"; + } - if (index == 2) + if (index == 2) { return "PSVita Controller"; + } - if (index == 3) + if (index == 3) { return "PSVita Controller"; + } SDL_SetError("No joystick available with that index"); return NULL; diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c index f8d9c07158..54215b1993 100644 --- a/src/joystick/windows/SDL_dinputjoystick.c +++ b/src/joystick/windows/SDL_dinputjoystick.c @@ -270,7 +270,7 @@ QueryDeviceName(LPDIRECTINPUTDEVICE8 device, char** device_name) { DIPROPSTRING dipstr; - if (!device || !device_name) { + if (!device || device_name == NULL) { return SDL_FALSE; } @@ -293,7 +293,7 @@ QueryDevicePath(LPDIRECTINPUTDEVICE8 device, char** device_path) { DIPROPGUIDANDPATH dippath; - if (!device || !device_path) { + if (!device || device_path == NULL) { return SDL_FALSE; } @@ -319,7 +319,7 @@ QueryDeviceInfo(LPDIRECTINPUTDEVICE8 device, Uint16* vendor_id, Uint16* product_ { DIPROPDWORD dipdw; - if (!device || !vendor_id || !product_id) { + if (!device || vendor_id == NULL || product_id == NULL) { return SDL_FALSE; } @@ -341,7 +341,7 @@ QueryDeviceInfo(LPDIRECTINPUTDEVICE8 device, Uint16* vendor_id, Uint16* product_ void FreeRumbleEffectData(DIEFFECT *effect) { - if (!effect) { + if (effect == NULL) { return; } SDL_free(effect->rgdwAxes); @@ -357,7 +357,7 @@ DIEFFECT *CreateRumbleEffectData(Sint16 magnitude) /* Create the effect */ effect = (DIEFFECT *)SDL_calloc(1, sizeof(*effect)); - if (!effect) { + if (effect == NULL) { return NULL; } effect->dwSize = sizeof(*effect); @@ -381,7 +381,7 @@ DIEFFECT *CreateRumbleEffectData(Sint16 magnitude) effect->dwFlags |= DIEFF_CARTESIAN; periodic = (DIPERIODIC *)SDL_calloc(1, sizeof(*periodic)); - if (!periodic) { + if (periodic == NULL) { FreeRumbleEffectData(effect); return NULL; } @@ -441,7 +441,7 @@ SDL_DINPUT_JoystickInit(void) static BOOL CALLBACK EnumJoystickDetectCallback(LPCDIDEVICEINSTANCE pDeviceInstance, LPVOID pContext) { -#define CHECK(expression) { if(!(expression)) goto err; } +#define CHECK(expression) { if (!(expression)) goto err; } JoyStick_DeviceData *pNewJoystick = NULL; JoyStick_DeviceData *pPrevJoystick = NULL; Uint16 vendor = 0; @@ -468,8 +468,7 @@ EnumJoystickDetectCallback(LPCDIDEVICEINSTANCE pDeviceInstance, LPVOID pContext) /* if we are replacing the front of the list then update it */ if (pNewJoystick == *(JoyStick_DeviceData**)pContext) { *(JoyStick_DeviceData**)pContext = pNewJoystick->pNext; - } - else if (pPrevJoystick) { + } else if (pPrevJoystick) { pPrevJoystick->pNext = pNewJoystick->pNext; } @@ -554,7 +553,7 @@ typedef struct static BOOL CALLBACK EnumJoystickPresentCallback(LPCDIDEVICEINSTANCE pDeviceInstance, LPVOID pContext) { -#define CHECK(expression) { if(!(expression)) goto err; } +#define CHECK(expression) { if (!(expression)) goto err; } Joystick_PresentData *pData = (Joystick_PresentData *)pContext; Uint16 vendor = 0; Uint16 product = 0; @@ -690,10 +689,12 @@ SortDevFunc(const void *a, const void *b) const input_t *inputA = (const input_t*)a; const input_t *inputB = (const input_t*)b; - if (inputA->ofs < inputB->ofs) + if (inputA->ofs < inputB->ofs) { return -1; - if (inputA->ofs > inputB->ofs) + } + if (inputA->ofs > inputB->ofs) { return 1; + } return 0; } @@ -965,16 +966,18 @@ TranslatePOV(DWORD value) SDL_HAT_UP | SDL_HAT_LEFT }; - if (LOWORD(value) == 0xFFFF) + if (LOWORD(value) == 0xFFFF) { return SDL_HAT_CENTERED; + } /* Round the value up: */ value += 4500 / 2; value %= 36000; value /= 4500; - if (value >= 8) - return SDL_HAT_CENTERED; /* shouldn't happen */ + if (value >= 8) { + return SDL_HAT_CENTERED; /* shouldn't happen */ + } return HAT_VALS[value]; } @@ -1085,8 +1088,9 @@ UpdateDINPUTJoystickState_Buffered(SDL_Joystick * joystick) for (j = 0; j < joystick->hwdata->NumInputs; ++j) { const input_t *in = &joystick->hwdata->Inputs[j]; - if (evtbuf[i].dwOfs != in->ofs) + if (evtbuf[i].dwOfs != in->ofs) { continue; + } switch (in->type) { case AXIS: diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c index 9568360ef4..993bf90ae4 100644 --- a/src/joystick/windows/SDL_rawinputjoystick.c +++ b/src/joystick/windows/SDL_rawinputjoystick.c @@ -254,8 +254,9 @@ static void RAWINPUT_FillMatchState(WindowsMatchState *state, Uint64 match_state ((match_state & (1<xinput_buttons) + if (state->xinput_buttons) { state->any_data = SDL_TRUE; + } #endif #ifdef SDL_JOYSTICK_RAWINPUT_WGI @@ -292,8 +293,9 @@ static void RAWINPUT_FillMatchState(WindowsMatchState *state, Uint64 match_state ((match_state & (1<wgi_buttons) + if (state->wgi_buttons) { state->any_data = SDL_TRUE; + } #endif } @@ -467,11 +469,13 @@ static void RAWINPUT_UpdateWindowsGamingInput() { int ii; - if (!wgi_state.gamepad_statics) + if (!wgi_state.gamepad_statics) { return; + } - if (!wgi_state.dirty) + if (!wgi_state.dirty) { return; + } wgi_state.dirty = SDL_FALSE; @@ -515,7 +519,7 @@ RAWINPUT_UpdateWindowsGamingInput() return; } gamepad_state = SDL_calloc(1, sizeof(*gamepad_state)); - if (!gamepad_state) { + if (gamepad_state == NULL) { SDL_OutOfMemory(); return; } @@ -698,8 +702,9 @@ RAWINPUT_DeviceFromHandle(HANDLE hDevice) SDL_RAWINPUT_Device *curr; for (curr = SDL_RAWINPUT_devices; curr; curr = curr->next) { - if (curr->hDevice == hDevice) + if (curr->hDevice == hDevice) { return curr; + } } return NULL; } @@ -707,7 +712,7 @@ RAWINPUT_DeviceFromHandle(HANDLE hDevice) static void RAWINPUT_AddDevice(HANDLE hDevice) { -#define CHECK(expression) { if(!(expression)) goto err; } +#define CHECK(expression) { if (!(expression)) goto err; } SDL_RAWINPUT_Device *device = NULL; SDL_RAWINPUT_Device *curr, *last; RID_DEVICE_INFO rdi; @@ -1072,7 +1077,7 @@ RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) ULONG i; ctx = (RAWINPUT_DeviceContext *)SDL_calloc(1, sizeof(RAWINPUT_DeviceContext)); - if (!ctx) { + if (ctx == NULL) { return SDL_OutOfMemory(); } joystick->hwdata = ctx; @@ -1085,7 +1090,7 @@ RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) #ifdef SDL_JOYSTICK_RAWINPUT_XINPUT xinput_device_change = SDL_TRUE; ctx->xinput_enabled = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT, SDL_TRUE); - if (ctx->xinput_enabled && (WIN_LoadXInputDLL() < 0 || !XINPUTGETSTATE)) { + if (ctx->xinput_enabled && (WIN_LoadXInputDLL() < 0 || XINPUTGETSTATE == NULL)) { ctx->xinput_enabled = SDL_FALSE; } ctx->xinput_slot = XUSER_INDEX_ANY; @@ -1281,7 +1286,7 @@ RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uin if (!rumbled && ctx->xinput_correlated) { XINPUT_VIBRATION XVibration; - if (!XINPUTSETSTATE) { + if (XINPUTSETSTATE == NULL) { return SDL_Unsupported(); } @@ -1634,10 +1639,12 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick) correlated = SDL_TRUE; RAWINPUT_MarkWindowsGamingInputSlotUsed(ctx->wgi_slot, ctx); /* If the generalized Guide button was using us, it doesn't need to anymore */ - if (guide_button_candidate.joystick == joystick) + if (guide_button_candidate.joystick == joystick) { guide_button_candidate.joystick = NULL; - if (guide_button_candidate.last_joystick == joystick) + } + if (guide_button_candidate.last_joystick == joystick) { guide_button_candidate.last_joystick = NULL; + } } } else { /* someone else also possibly correlated to this device, start over */ @@ -1728,10 +1735,12 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick) correlated = SDL_TRUE; RAWINPUT_MarkXInputSlotUsed(ctx->xinput_slot); /* If the generalized Guide button was using us, it doesn't need to anymore */ - if (guide_button_candidate.joystick == joystick) + if (guide_button_candidate.joystick == joystick) { guide_button_candidate.joystick = NULL; - if (guide_button_candidate.last_joystick == joystick) + } + if (guide_button_candidate.last_joystick == joystick) { guide_button_candidate.last_joystick = NULL; + } } } else { /* someone else also possibly correlated to this device, start over */ @@ -1843,10 +1852,12 @@ RAWINPUT_JoystickClose(SDL_Joystick *joystick) RAWINPUT_DeviceContext *ctx = joystick->hwdata; #ifdef SDL_JOYSTICK_RAWINPUT_MATCHING - if (guide_button_candidate.joystick == joystick) + if (guide_button_candidate.joystick == joystick) { guide_button_candidate.joystick = NULL; - if (guide_button_candidate.last_joystick == joystick) + } + if (guide_button_candidate.last_joystick == joystick) { guide_button_candidate.last_joystick = NULL; + } #endif if (ctx) { diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c index c63b24ad5d..b0d6b33911 100644 --- a/src/joystick/windows/SDL_windows_gaming_input.c +++ b/src/joystick/windows/SDL_windows_gaming_input.c @@ -212,7 +212,7 @@ typedef struct RawGameControllerDelegate { static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_QueryInterface(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController * This, REFIID riid, void **ppvObject) { - if (!ppvObject) { + if (ppvObject == NULL) { return E_INVALIDARG; } @@ -302,7 +302,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde } __x_ABI_CWindows_CGaming_CInput_CIRawGameController2_Release(controller2); } - if (!name) { + if (name == NULL) { name = SDL_strdup(""); } @@ -660,7 +660,7 @@ WGI_JoystickOpen(SDL_Joystick *joystick, int device_index) boolean wireless = SDL_FALSE; hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(*hwdata)); - if (!hwdata) { + if (hwdata == NULL) { return SDL_OutOfMemory(); } joystick->hwdata = hwdata; diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c index f15fe8f870..ddf3af15bb 100644 --- a/src/joystick/windows/SDL_windowsjoystick.c +++ b/src/joystick/windows/SDL_windowsjoystick.c @@ -246,11 +246,13 @@ SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data) RAWINPUT_UnregisterNotifications(); #endif - if (data->hNotify) + if (data->hNotify) { UnregisterDeviceNotification(data->hNotify); + } - if (data->messageWindow) + if (data->messageWindow) { DestroyWindow(data->messageWindow); + } UnregisterClass(data->wincl.lpszClassName, data->wincl.hInstance); @@ -394,18 +396,18 @@ static int SDL_StartJoystickThread(void) { s_mutexJoyStickEnum = SDL_CreateMutex(); - if (!s_mutexJoyStickEnum) { + if (s_mutexJoyStickEnum == NULL) { return -1; } s_condJoystickThread = SDL_CreateCond(); - if (!s_condJoystickThread) { + if (s_condJoystickThread == NULL) { return -1; } s_bJoystickThreadQuit = SDL_FALSE; s_joystickThread = SDL_CreateThreadInternal(SDL_JoystickThread, "SDL_joystick", 64 * 1024, NULL); - if (!s_joystickThread) { + if (s_joystickThread == NULL) { return -1; } return 0; @@ -414,7 +416,7 @@ SDL_StartJoystickThread(void) static void SDL_StopJoystickThread(void) { - if (!s_joystickThread) { + if (s_joystickThread == NULL) { return; } @@ -588,8 +590,9 @@ WINDOWS_JoystickGetDeviceName(int device_index) JoyStick_DeviceData *device = SYS_Joystick; int index; - for (index = device_index; index > 0; index--) + for (index = device_index; index > 0; index--) { device = device->pNext; + } return device->joystickname; } @@ -600,8 +603,9 @@ WINDOWS_JoystickGetDevicePath(int device_index) JoyStick_DeviceData *device = SYS_Joystick; int index; - for (index = device_index; index > 0; index--) + for (index = device_index; index > 0; index--) { device = device->pNext; + } return device->path; } @@ -612,8 +616,9 @@ WINDOWS_JoystickGetDevicePlayerIndex(int device_index) JoyStick_DeviceData *device = SYS_Joystick; int index; - for (index = device_index; index > 0; index--) + for (index = device_index; index > 0; index--) { device = device->pNext; + } return device->bXInputDevice ? (int)device->XInputUserId : -1; } @@ -630,8 +635,9 @@ WINDOWS_JoystickGetDeviceGUID(int device_index) JoyStick_DeviceData *device = SYS_Joystick; int index; - for (index = device_index; index > 0; index--) + for (index = device_index; index > 0; index--) { device = device->pNext; + } return device->guid; } @@ -643,8 +649,9 @@ WINDOWS_JoystickGetDeviceInstanceID(int device_index) JoyStick_DeviceData *device = SYS_Joystick; int index; - for (index = device_index; index > 0; index--) + for (index = device_index; index > 0; index--) { device = device->pNext; + } return device->nInstanceID; } @@ -660,8 +667,9 @@ WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index) JoyStick_DeviceData *device = SYS_Joystick; int index; - for (index = device_index; index > 0; index--) + for (index = device_index; index > 0; index--) { device = device->pNext; + } /* allocate memory for system specific hardware data */ joystick->instance_id = device->nInstanceID; diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c index 488136f5fc..079f2f4671 100644 --- a/src/joystick/windows/SDL_xinputjoystick.c +++ b/src/joystick/windows/SDL_xinputjoystick.c @@ -47,7 +47,7 @@ SDL_XInputUseOldJoystickMapping() #ifdef __WINRT__ /* TODO: remove this __WINRT__ block, but only after integrating with UWP/WinRT's HID API */ /* FIXME: Why are Win8/10 different here? -flibit */ - return (NTDDI_VERSION < NTDDI_WIN10); + return NTDDI_VERSION < NTDDI_WIN10; #elif defined(__XBOXONE__) || defined(__XBOXSERIES__) return SDL_FALSE; #else @@ -55,7 +55,7 @@ SDL_XInputUseOldJoystickMapping() if (s_XInputUseOldJoystickMapping < 0) { s_XInputUseOldJoystickMapping = SDL_GetHintBoolean(SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING, SDL_FALSE); } - return (s_XInputUseOldJoystickMapping > 0); + return s_XInputUseOldJoystickMapping > 0; #endif } @@ -246,11 +246,13 @@ AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext) JoyStick_DeviceData *pPrevJoystick = NULL; JoyStick_DeviceData *pNewJoystick = *pContext; - if (SDL_XInputUseOldJoystickMapping() && SubType != XINPUT_DEVSUBTYPE_GAMEPAD) + if (SDL_XInputUseOldJoystickMapping() && SubType != XINPUT_DEVSUBTYPE_GAMEPAD) { return; + } - if (SubType == XINPUT_DEVSUBTYPE_UNKNOWN) + if (SubType == XINPUT_DEVSUBTYPE_UNKNOWN) { return; + } while (pNewJoystick) { if (pNewJoystick->bXInputDevice && (pNewJoystick->XInputUserId == userid) && (pNewJoystick->SubType == SubType)) { @@ -271,7 +273,7 @@ AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext) } pNewJoystick = (JoyStick_DeviceData *)SDL_calloc(1, sizeof(JoyStick_DeviceData)); - if (!pNewJoystick) { + if (pNewJoystick == NULL) { return; /* better luck next time? */ } @@ -519,8 +521,9 @@ SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick) XINPUT_STATE_EX XInputState; XINPUT_BATTERY_INFORMATION_EX XBatteryInformation; - if (!XINPUTGETSTATE) + if (!XINPUTGETSTATE) { return; + } result = XINPUTGETSTATE(joystick->hwdata->userid, &XInputState); if (result == ERROR_DEVICE_NOT_CONNECTED) { diff --git a/src/loadso/dlopen/SDL_sysloadso.c b/src/loadso/dlopen/SDL_sysloadso.c index c9f4f52161..74a0e3de8c 100644 --- a/src/loadso/dlopen/SDL_sysloadso.c +++ b/src/loadso/dlopen/SDL_sysloadso.c @@ -51,7 +51,7 @@ SDL_LoadObject(const char *sofile) if (handle == NULL) { SDL_SetError("Failed loading %s: %s", sofile, loaderror); } - return (handle); + return handle; } void * @@ -72,7 +72,7 @@ SDL_LoadFunction(void *handle, const char *name) (const char *) dlerror()); } } - return (symbol); + return symbol; } void diff --git a/src/loadso/dummy/SDL_sysloadso.c b/src/loadso/dummy/SDL_sysloadso.c index 8ec840760a..558ba508ee 100644 --- a/src/loadso/dummy/SDL_sysloadso.c +++ b/src/loadso/dummy/SDL_sysloadso.c @@ -31,7 +31,7 @@ SDL_LoadObject(const char *sofile) { const char *loaderror = "SDL_LoadObject() not implemented"; SDL_SetError("Failed loading %s: %s", sofile, loaderror); - return (NULL); + return NULL; } void * @@ -39,7 +39,7 @@ SDL_LoadFunction(void *handle, const char *name) { const char *loaderror = "SDL_LoadFunction() not implemented"; SDL_SetError("Failed loading %s: %s", name, loaderror); - return (NULL); + return NULL; } void diff --git a/src/loadso/windows/SDL_sysloadso.c b/src/loadso/windows/SDL_sysloadso.c index 1125f74649..ecdeddec0b 100644 --- a/src/loadso/windows/SDL_sysloadso.c +++ b/src/loadso/windows/SDL_sysloadso.c @@ -34,7 +34,7 @@ SDL_LoadObject(const char *sofile) void *handle; LPTSTR tstr; - if (!sofile) { + if (sofile == NULL) { SDL_InvalidParamError("sofile"); return NULL; } diff --git a/src/locale/SDL_locale.c b/src/locale/SDL_locale.c index 1ac15b8541..de5409bb0e 100644 --- a/src/locale/SDL_locale.c +++ b/src/locale/SDL_locale.c @@ -32,7 +32,7 @@ build_locales_from_csv_string(char *csv) SDL_Locale *loc; SDL_Locale *retval; - if (!csv || !csv[0]) { + if (csv == NULL || !csv[0]) { return NULL; /* nothing to report */ } @@ -48,7 +48,7 @@ build_locales_from_csv_string(char *csv) alloclen = slen + (num_locales * sizeof (SDL_Locale)); loc = retval = (SDL_Locale *) SDL_calloc(1, alloclen); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; /* oh well */ } @@ -56,7 +56,10 @@ build_locales_from_csv_string(char *csv) SDL_strlcpy(ptr, csv, slen); while (SDL_TRUE) { /* parse out the string */ - while (*ptr == ' ') ptr++; /* skip whitespace. */ + while (*ptr == ' ') { + ptr++; /* skip whitespace. */ + } + if (*ptr == '\0') { break; } diff --git a/src/locale/unix/SDL_syslocale.c b/src/locale/unix/SDL_syslocale.c index b9a3774394..518856a36d 100644 --- a/src/locale/unix/SDL_syslocale.c +++ b/src/locale/unix/SDL_syslocale.c @@ -74,7 +74,7 @@ SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) SDL_assert(buflen > 0); tmp = SDL_small_alloc(char, buflen, &isstack); - if (!tmp) { + if (tmp == NULL) { SDL_OutOfMemory(); return; } diff --git a/src/locale/vita/SDL_syslocale.c b/src/locale/vita/SDL_syslocale.c index 0a057cbfac..cde912cf85 100644 --- a/src/locale/vita/SDL_syslocale.c +++ b/src/locale/vita/SDL_syslocale.c @@ -59,8 +59,9 @@ SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) sceAppUtilInit(&initParam, &bootParam); sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG, &language); - if (language < 0 || language > SCE_SYSTEM_PARAM_LANG_TURKISH) + if (language < 0 || language > SCE_SYSTEM_PARAM_LANG_TURKISH) { language = SCE_SYSTEM_PARAM_LANG_ENGLISH_US; // default to english + } SDL_strlcpy(buf, vita_locales[language], buflen); diff --git a/src/locale/windows/SDL_syslocale.c b/src/locale/windows/SDL_syslocale.c index 2d033f476b..3bbaa1e68c 100644 --- a/src/locale/windows/SDL_syslocale.c +++ b/src/locale/windows/SDL_syslocale.c @@ -68,7 +68,7 @@ SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen) pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, NULL, &wbuflen); wbuf = SDL_small_alloc(WCHAR, wbuflen, &isstack); - if (!wbuf) { + if (wbuf == NULL) { SDL_OutOfMemory(); return; } diff --git a/src/locale/winrt/SDL_syslocale.c b/src/locale/winrt/SDL_syslocale.c index 1af2a95fcb..55de845217 100644 --- a/src/locale/winrt/SDL_syslocale.c +++ b/src/locale/winrt/SDL_syslocale.c @@ -40,8 +40,7 @@ SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) ret = GetSystemDefaultLocaleName(wbuffer, SDL_arraysize(wbuffer)); # endif - if (ret > 0) - { + if (ret > 0) { /* Need to convert LPWSTR to LPSTR, that is wide char to char. */ int i; diff --git a/src/main/dummy/SDL_dummy_main.c b/src/main/dummy/SDL_dummy_main.c index a6e99b74ea..824aeb1c71 100644 --- a/src/main/dummy/SDL_dummy_main.c +++ b/src/main/dummy/SDL_dummy_main.c @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) { - return (SDL_main(argc, argv)); + return SDL_main(argc, argv); } #else /* Nothing to do on this platform */ diff --git a/src/main/haiku/SDL_BeApp.cc b/src/main/haiku/SDL_BeApp.cc index 3e31d1b188..69a272c8be 100644 --- a/src/main/haiku/SDL_BeApp.cc +++ b/src/main/haiku/SDL_BeApp.cc @@ -63,8 +63,9 @@ StartBeApp(void *unused) BAppFileInfo app_info(&f); if (app_info.InitCheck() == B_OK) { char sig[B_MIME_TYPE_LENGTH]; - if (app_info.GetSignature(sig) == B_OK) + if (app_info.GetSignature(sig) == B_OK) { signature = strndup(sig, B_MIME_TYPE_LENGTH); + } } } } @@ -73,7 +74,7 @@ StartBeApp(void *unused) App->Run(); delete App; - return (0); + return 0; } /* Initialize the Be Application, if it's not already started */ @@ -114,7 +115,7 @@ SDL_InitBeApp(void) ++SDL_BeAppActive; /* The app is running, and we're ready to go */ - return (0); + return 0; } /* Quit the Be Application, if there's nothing left to do */ @@ -145,7 +146,7 @@ SDL_QuitBeApp(void) void SDL_BApp::ClearID(SDL_BWin *bwin) { _SetSDLWindow(NULL, bwin->GetID()); int32 i = _GetNumWindowSlots() - 1; - while(i >= 0 && GetSDLWindow(i) == NULL) { + while (i >= 0 && GetSDLWindow(i) == NULL) { _PopBackWindow(); --i; } diff --git a/src/main/ngage/SDL_ngage_main.cpp b/src/main/ngage/SDL_ngage_main.cpp index 8d7cf0d483..c861db2533 100644 --- a/src/main/ngage/SDL_ngage_main.cpp +++ b/src/main/ngage/SDL_ngage_main.cpp @@ -58,13 +58,10 @@ TInt E32Main() newHeap = User::ChunkHeap(NULL, heapSize, heapSize, KMinHeapGrowBy); - if (NULL == newHeap) - { + if (newHeap == NULL) { ret = 3; goto cleanup; - } - else - { + } else { oldHeap = User::SwitchHeap(newHeap); /* Call stdlib main */ SDL_SetMainReady(); diff --git a/src/main/ps2/SDL_ps2_main.c b/src/main/ps2/SDL_ps2_main.c index e98d460db9..10a7269040 100644 --- a/src/main/ps2/SDL_ps2_main.c +++ b/src/main/ps2/SDL_ps2_main.c @@ -25,9 +25,9 @@ __attribute__((weak)) void reset_IOP() { SifInitRpc(0); - while(!SifIopReset(NULL, 0)) { + while (!SifIopReset(NULL, 0)) { } - while(!SifIopSync()){ + while (!SifIopSync()) { } } @@ -56,7 +56,7 @@ static void waitUntilDeviceIsReady(char *path) int ret = -1; int retries = 50; - while(ret != 0 && retries > 0) { + while (ret != 0 && retries > 0) { ret = stat(path, &buffer); /* Wait until the device is ready */ nopdelay(); diff --git a/src/main/psp/SDL_psp_main.c b/src/main/psp/SDL_psp_main.c index c9d1214271..c2bda9f658 100644 --- a/src/main/psp/SDL_psp_main.c +++ b/src/main/psp/SDL_psp_main.c @@ -46,8 +46,9 @@ int sdl_psp_setup_callbacks(void) int thid; thid = sceKernelCreateThread("update_thread", sdl_psp_callback_thread, 0x11, 0xFA0, 0, 0); - if(thid >= 0) + if (thid >= 0) { sceKernelStartThread(thid, 0, 0); + } return thid; } diff --git a/src/main/windows/SDL_windows_main.c b/src/main/windows/SDL_windows_main.c index e626235e6f..3f003dcb1a 100644 --- a/src/main/windows/SDL_windows_main.c +++ b/src/main/windows/SDL_windows_main.c @@ -52,13 +52,13 @@ main_getcmdline(void) /* Parse it into argv and argc */ argv = (char **)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv)); - if (!argv) { + if (argv == NULL) { return OutOfMemory(); } for (i = 0; i < argc; ++i) { DWORD len; char *arg = WIN_StringToUTF8W(argvw[i]); - if (!arg) { + if (arg == NULL) { return OutOfMemory(); } len = (DWORD)SDL_strlen(arg); diff --git a/src/misc/SDL_url.c b/src/misc/SDL_url.c index eb258d9623..8091bd8d29 100644 --- a/src/misc/SDL_url.c +++ b/src/misc/SDL_url.c @@ -26,7 +26,7 @@ extern int SDL_SYS_OpenURL(const char *url); int SDL_OpenURL(const char *url) { - if (!url) { + if (url == NULL) { return SDL_InvalidParamError("url"); } return SDL_SYS_OpenURL(url); diff --git a/src/power/emscripten/SDL_syspower.c b/src/power/emscripten/SDL_syspower.c index e2a882f5ba..ced37f9552 100644 --- a/src/power/emscripten/SDL_syspower.c +++ b/src/power/emscripten/SDL_syspower.c @@ -32,8 +32,9 @@ SDL_GetPowerInfo_Emscripten(SDL_PowerState *state, int *seconds, int *percent) EmscriptenBatteryEvent batteryState; int haveBattery = 0; - if (emscripten_get_battery_status(&batteryState) == EMSCRIPTEN_RESULT_NOT_SUPPORTED) + if (emscripten_get_battery_status(&batteryState) == EMSCRIPTEN_RESULT_NOT_SUPPORTED) { return SDL_FALSE; + } haveBattery = batteryState.level != 1.0 || !batteryState.charging || batteryState.chargingTime != 0.0; diff --git a/src/power/linux/SDL_syspower.c b/src/power/linux/SDL_syspower.c index 24d80eea21..70cbfa5af4 100644 --- a/src/power/linux/SDL_syspower.c +++ b/src/power/linux/SDL_syspower.c @@ -302,11 +302,13 @@ next_string(char **_ptr, char **_str) } str = ptr; - while ((*ptr != ' ') && (*ptr != '\n') && (*ptr != '\0')) + while ((*ptr != ' ') && (*ptr != '\n') && (*ptr != '\0')) { ptr++; + } - if (*ptr != '\0') + if (*ptr != '\0') { *(ptr++) = '\0'; + } *_str = str; *_ptr = ptr; @@ -318,7 +320,7 @@ int_string(char *str, int *val) { char *endptr = NULL; *val = (int) SDL_strtol(str, &endptr, 0); - return ((*str != '\0') && (*endptr == '\0')); + return (*str != '\0') && (*endptr == '\0'); } /* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */ @@ -438,7 +440,7 @@ SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, int *second DIR *dirp; dirp = opendir(base); - if (!dirp) { + if (dirp == NULL) { return SDL_FALSE; } @@ -632,9 +634,9 @@ SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, int *second char **paths = NULL; int i, numpaths = 0; - if (!dbus || !SDL_DBus_CallMethodOnConnection(dbus->system_conn, UPOWER_DBUS_NODE, UPOWER_DBUS_PATH, UPOWER_DBUS_INTERFACE, "EnumerateDevices", - DBUS_TYPE_INVALID, - DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &numpaths, DBUS_TYPE_INVALID)) { + if (dbus == NULL || !SDL_DBus_CallMethodOnConnection(dbus->system_conn, UPOWER_DBUS_NODE, UPOWER_DBUS_PATH, UPOWER_DBUS_INTERFACE, "EnumerateDevices", + DBUS_TYPE_INVALID, + DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &numpaths, DBUS_TYPE_INVALID)) { return SDL_FALSE; /* try a different approach than UPower. */ } diff --git a/src/power/windows/SDL_syspower.c b/src/power/windows/SDL_syspower.c index 6bb1106526..3798ea86c5 100644 --- a/src/power/windows/SDL_syspower.c +++ b/src/power/windows/SDL_syspower.c @@ -33,8 +33,7 @@ SDL_GetPowerInfo_Windows(SDL_PowerState * state, int *seconds, int *percent) SDL_bool need_details = SDL_FALSE; /* This API should exist back to Win95. */ - if (!GetSystemPowerStatus(&status)) - { + if (!GetSystemPowerStatus(&status)) { /* !!! FIXME: push GetLastError() into SDL_GetError() */ *state = SDL_POWERSTATE_UNKNOWN; } else if (status.BatteryFlag == 0xFF) { /* unknown state */ diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 6344f6f84c..61ed046d3d 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -330,7 +330,7 @@ AllocateRenderCommand(SDL_Renderer *renderer) retval->next = NULL; } else { retval = SDL_calloc(1, sizeof (*retval)); - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } @@ -963,7 +963,7 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) Android_ActivityMutex_Lock_Running(); #endif - if (!window) { + if (window == NULL) { SDL_InvalidParamError("window"); goto error; } @@ -999,7 +999,7 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) } } - if (!renderer) { + if (renderer == NULL) { for (index = 0; index < n; ++index) { const SDL_RenderDriver *driver = render_drivers[index]; @@ -1013,7 +1013,7 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) } } } - if (!renderer) { + if (renderer == NULL) { SDL_SetError("Couldn't find matching render driver"); goto error; } @@ -1026,7 +1026,7 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) /* Create a new renderer instance */ renderer = render_drivers[index]->CreateRenderer(window, flags); batching = SDL_FALSE; - if (!renderer) { + if (renderer == NULL) { goto error; } } @@ -1251,7 +1251,7 @@ static SDL_ScaleMode SDL_GetScaleMode(void) { const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - if (!hint || SDL_strcasecmp(hint, "nearest") == 0) { + if (hint == NULL || SDL_strcasecmp(hint, "nearest") == 0) { return SDL_ScaleModeNearest; } else if (SDL_strcasecmp(hint, "linear") == 0) { return SDL_ScaleModeLinear; @@ -1293,7 +1293,7 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int return NULL; } texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); - if (!texture) { + if (texture == NULL) { SDL_OutOfMemory(); return NULL; } @@ -1385,7 +1385,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) CHECK_RENDERER_MAGIC(renderer, NULL); - if (!surface) { + if (surface == NULL) { SDL_InvalidParamError("SDL_CreateTextureFromSurface(): surface"); return NULL; } @@ -1449,7 +1449,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC, surface->w, surface->h); - if (!texture) { + if (texture == NULL) { return NULL; } @@ -1481,7 +1481,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) /* Set up a destination surface for the texture update */ dst_fmt = SDL_AllocFormat(format); - if (!dst_fmt) { + if (dst_fmt == NULL) { SDL_DestroyTexture(texture); return NULL; } @@ -1712,7 +1712,7 @@ SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect, const size_t alloclen = rect->h * temp_pitch; if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); - if (!temp_pixels) { + if (temp_pixels == NULL) { return SDL_OutOfMemory(); } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, @@ -1753,7 +1753,7 @@ SDL_UpdateTextureNative(SDL_Texture * texture, const SDL_Rect * rect, const size_t alloclen = rect->h * temp_pitch; if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); - if (!temp_pixels) { + if (temp_pixels == NULL) { return SDL_OutOfMemory(); } SDL_ConvertPixels(rect->w, rect->h, @@ -1774,7 +1774,7 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect, CHECK_TEXTURE_MAGIC(texture, -1); - if (!pixels) { + if (pixels == NULL) { return SDL_InvalidParamError("pixels"); } if (!pitch) { @@ -1849,7 +1849,7 @@ SDL_UpdateTextureYUVPlanar(SDL_Texture * texture, const SDL_Rect * rect, const size_t alloclen = rect->h * temp_pitch; if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); - if (!temp_pixels) { + if (temp_pixels == NULL) { return SDL_OutOfMemory(); } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, @@ -1900,7 +1900,7 @@ SDL_UpdateTextureNVPlanar(SDL_Texture * texture, const SDL_Rect * rect, const size_t alloclen = rect->h * temp_pitch; if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); - if (!temp_pixels) { + if (temp_pixels == NULL) { return SDL_OutOfMemory(); } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, @@ -1926,19 +1926,19 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect, CHECK_TEXTURE_MAGIC(texture, -1); - if (!Yplane) { + if (Yplane == NULL) { return SDL_InvalidParamError("Yplane"); } if (!Ypitch) { return SDL_InvalidParamError("Ypitch"); } - if (!Uplane) { + if (Uplane == NULL) { return SDL_InvalidParamError("Uplane"); } if (!Upitch) { return SDL_InvalidParamError("Upitch"); } - if (!Vplane) { + if (Vplane == NULL) { return SDL_InvalidParamError("Vplane"); } if (!Vpitch) { @@ -1992,13 +1992,13 @@ int SDL_UpdateNVTexture(SDL_Texture * texture, const SDL_Rect * rect, CHECK_TEXTURE_MAGIC(texture, -1); - if (!Yplane) { + if (Yplane == NULL) { return SDL_InvalidParamError("Yplane"); } if (!Ypitch) { return SDL_InvalidParamError("Ypitch"); } - if (!UVplane) { + if (UVplane == NULL) { return SDL_InvalidParamError("UVplane"); } if (!UVpitch) { @@ -2077,7 +2077,7 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, return SDL_SetError("SDL_LockTexture(): texture must be streaming"); } - if (!rect) { + if (rect == NULL) { full_rect.x = 0; full_rect.y = 0; full_rect.w = texture->w; @@ -2212,7 +2212,7 @@ SDL_UnlockTexture(SDL_Texture * texture) SDL_bool SDL_RenderTargetSupported(SDL_Renderer *renderer) { - if (!renderer || !renderer->SetRenderTarget) { + if (renderer == NULL || !renderer->SetRenderTarget) { return SDL_FALSE; } return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0; @@ -2326,7 +2326,7 @@ UpdateLogicalSize(SDL_Renderer *renderer, SDL_bool flush_viewport_cmd) } hint = SDL_GetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE); - if (hint && (*hint == '1' || SDL_strcasecmp(hint, "overscan") == 0)) { + if (hint && (*hint == '1' || SDL_strcasecmp(hint, "overscan") == 0)) { #if SDL_VIDEO_RENDER_D3D SDL_bool overscan_supported = SDL_TRUE; /* Unfortunately, Direct3D 9 doesn't support negative viewport numbers @@ -2724,7 +2724,7 @@ RenderDrawPointsWithRects(SDL_Renderer * renderer, } frects = SDL_small_alloc(SDL_FRect, count, &isstack); - if (!frects) { + if (frects == NULL) { return SDL_OutOfMemory(); } @@ -2753,7 +2753,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); - if (!points) { + if (points == NULL) { return SDL_InvalidParamError("SDL_RenderDrawPoints(): points"); } if (count < 1) { @@ -2771,7 +2771,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, retval = RenderDrawPointsWithRects(renderer, points, count); } else { fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack); - if (!fpoints) { + if (fpoints == NULL) { return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { @@ -2800,7 +2800,7 @@ RenderDrawPointsWithRectsF(SDL_Renderer * renderer, } frects = SDL_small_alloc(SDL_FRect, count, &isstack); - if (!frects) { + if (frects == NULL) { return SDL_OutOfMemory(); } @@ -2826,7 +2826,7 @@ SDL_RenderDrawPointsF(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); - if (!points) { + if (points == NULL) { return SDL_InvalidParamError("SDL_RenderDrawPointsF(): points"); } if (count < 1) { @@ -2920,7 +2920,7 @@ static int RenderDrawLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x } points = SDL_small_alloc(SDL_FPoint, numpixels, &isstack); - if (!points) { + if (points == NULL) { return SDL_OutOfMemory(); } for (i = 0; i < numpixels; ++i) { @@ -2964,7 +2964,7 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer, SDL_bool draw_last = SDL_FALSE; frects = SDL_small_alloc(SDL_FRect, count-1, &isstack); - if (!frects) { + if (frects == NULL) { return SDL_OutOfMemory(); } @@ -3035,7 +3035,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); - if (!points) { + if (points == NULL) { return SDL_InvalidParamError("SDL_RenderDrawLines(): points"); } if (count < 2) { @@ -3050,7 +3050,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, #endif fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack); - if (!fpoints) { + if (fpoints == NULL) { return SDL_OutOfMemory(); } @@ -3074,7 +3074,7 @@ SDL_RenderDrawLinesF(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); - if (!points) { + if (points == NULL) { return SDL_InvalidParamError("SDL_RenderDrawLinesF(): points"); } if (count < 2) { @@ -3248,7 +3248,7 @@ SDL_RenderDrawRectF(SDL_Renderer * renderer, const SDL_FRect * rect) CHECK_RENDERER_MAGIC(renderer, -1); /* If 'rect' == NULL, then outline the whole surface */ - if (!rect) { + if (rect == NULL) { RenderGetViewportSize(renderer, &frect); rect = &frect; } @@ -3274,7 +3274,7 @@ SDL_RenderDrawRects(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); - if (!rects) { + if (rects == NULL) { return SDL_InvalidParamError("SDL_RenderDrawRects(): rects"); } if (count < 1) { @@ -3304,7 +3304,7 @@ SDL_RenderDrawRectsF(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); - if (!rects) { + if (rects == NULL) { return SDL_InvalidParamError("SDL_RenderDrawRectsF(): rects"); } if (count < 1) { @@ -3353,7 +3353,7 @@ SDL_RenderFillRectF(SDL_Renderer * renderer, const SDL_FRect * rect) CHECK_RENDERER_MAGIC(renderer, -1); /* If 'rect' == NULL, then outline the whole surface */ - if (!rect) { + if (rect == NULL) { RenderGetViewportSize(renderer, &frect); rect = &frect; } @@ -3371,7 +3371,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); - if (!rects) { + if (rects == NULL) { return SDL_InvalidParamError("SDL_RenderFillRects(): rects"); } if (count < 1) { @@ -3386,7 +3386,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, #endif frects = SDL_small_alloc(SDL_FRect, count, &isstack); - if (!frects) { + if (frects == NULL) { return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { @@ -3414,7 +3414,7 @@ SDL_RenderFillRectsF(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); - if (!rects) { + if (rects == NULL) { return SDL_InvalidParamError("SDL_RenderFillRectsF(): rects"); } if (count < 1) { @@ -3429,7 +3429,7 @@ SDL_RenderFillRectsF(SDL_Renderer * renderer, #endif frects = SDL_small_alloc(SDL_FRect, count, &isstack); - if (!frects) { + if (frects == NULL) { return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { @@ -3981,7 +3981,7 @@ SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer, x2 = xy2_[0]; y2 = xy2_[1]; /* Check if triangle A B C is rectangle */ - if ((x0 == x2 && y1 == y2) || (y0 == y2 && x1 == x2)){ + if ((x0 == x2 && y1 == y2) || (y0 == y2 && x1 == x2)) { /* ok */ } else { is_quad = 0; @@ -3994,7 +3994,7 @@ SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer, x2 = xy2_[0]; y2 = xy2_[1]; /* Check if triangle A B C2 is rectangle */ - if ((x0 == x2 && y1 == y2) || (y0 == y2 && x1 == x2)){ + if ((x0 == x2 && y1 == y2) || (y0 == y2 && x1 == x2)) { /* ok */ } else { is_quad = 0; @@ -4103,7 +4103,7 @@ SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer, prev[1] = k1; prev[2] = k2; } - } /* End for(), next triangle */ + } /* End for (), next triangle */ if (prev[0] != -1) { /* flush the last triangle */ @@ -4155,15 +4155,15 @@ SDL_RenderGeometryRaw(SDL_Renderer *renderer, } } - if (!xy) { + if (xy == NULL) { return SDL_InvalidParamError("xy"); } - if (!color) { + if (color == NULL) { return SDL_InvalidParamError("color"); } - if (texture && !uv) { + if (texture && uv == NULL) { return SDL_InvalidParamError("uv"); } diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c index cd9a4fd0f2..2b92fe77cd 100644 --- a/src/render/SDL_yuv_sw.c +++ b/src/render/SDL_yuv_sw.c @@ -48,7 +48,7 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) } swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata)); - if (!swdata) { + if (swdata == NULL) { SDL_OutOfMemory(); return NULL; } @@ -124,7 +124,7 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) } /* We're all done.. */ - return (swdata); + return swdata; } int @@ -345,8 +345,7 @@ SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, if (rect && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w || rect->h != swdata->h)) { - return SDL_SetError - ("YV12, IYUV, NV12, NV21 textures only support full surface locks"); + return SDL_SetError("YV12, IYUV, NV12, NV21 textures only support full surface locks"); } break; } @@ -406,7 +405,7 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, Gmask, Bmask, Amask); if (!swdata->display) { - return (-1); + return -1; } } if (!swdata->stretch) { @@ -417,7 +416,7 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask, Gmask, Bmask, Amask); if (!swdata->stretch) { - return (-1); + return -1; } } pixels = swdata->stretch->pixels; diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index dd33a238e8..bd54dc8112 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -549,7 +549,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) DWORD usage; texturedata = (D3D_TextureData *) SDL_calloc(1, sizeof(*texturedata)); - if (!texturedata) { + if (texturedata == NULL) { return SDL_OutOfMemory(); } texturedata->scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? D3DTEXF_POINT : D3DTEXF_LINEAR; @@ -588,7 +588,7 @@ D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata; - if (!texturedata) { + if (texturedata == NULL) { return 0; } @@ -616,7 +616,7 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata; - if (!texturedata) { + if (texturedata == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -653,7 +653,7 @@ D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata; - if (!texturedata) { + if (texturedata == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -678,7 +678,7 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata; IDirect3DDevice9 *device = data->device; - if (!texturedata) { + if (texturedata == NULL) { return SDL_SetError("Texture is not currently available"); } #if SDL_HAVE_YUV @@ -729,7 +729,7 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata; - if (!texturedata) { + if (texturedata == NULL) { return; } #if SDL_HAVE_YUV @@ -739,8 +739,7 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) (void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format)); D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch); - } - else + } else #endif { IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0); @@ -759,7 +758,7 @@ D3D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Scal { D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata; - if (!texturedata) { + if (texturedata == NULL) { return; } @@ -787,7 +786,7 @@ D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture) } texturedata = (D3D_TextureData *)texture->driverdata; - if (!texturedata) { + if (texturedata == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -810,11 +809,11 @@ D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture) } result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture.texture, 0, &data->currentRenderTarget); - if(FAILED(result)) { + if (FAILED(result)) { return D3D_SetError("GetSurfaceLevel()", result); } result = IDirect3DDevice9_SetRenderTarget(data->device, 0, data->currentRenderTarget); - if(FAILED(result)) { + if (FAILED(result)) { return D3D_SetError("SetRenderTarget()", result); } @@ -846,7 +845,7 @@ D3D_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first); int i; - if (!verts) { + if (verts == NULL) { return -1; } @@ -872,7 +871,7 @@ D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t int count = indices ? num_indices : num_vertices; Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, count * sizeof (Vertex), 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -972,7 +971,7 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH SDL_assert(*shader == NULL); - if (!texturedata) { + if (texturedata == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -1029,7 +1028,7 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd) IDirect3DDevice9_SetTexture(data->device, 0, NULL); } #if SDL_HAVE_YUV - if ((!newtexturedata || !newtexturedata->yuv) && (oldtexturedata && oldtexturedata->yuv)) { + if ((newtexturedata == NULL || !newtexturedata->yuv) && (oldtexturedata && oldtexturedata->yuv)) { IDirect3DDevice9_SetTexture(data->device, 1, NULL); IDirect3DDevice9_SetTexture(data->device, 2, NULL); } @@ -1420,7 +1419,7 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) #endif } - if (!data) { + if (data == NULL) { return; } @@ -1601,13 +1600,13 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags) } renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); return NULL; } data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { SDL_free(renderer); SDL_OutOfMemory(); return NULL; diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c index a8744f9f7b..dbb92885a1 100644 --- a/src/render/direct3d11/SDL_render_d3d11.c +++ b/src/render/direct3d11/SDL_render_d3d11.c @@ -389,7 +389,7 @@ D3D11_CreateBlendState(SDL_Renderer * renderer, SDL_BlendMode blendMode) } blendModes = (D3D11_BlendMode *)SDL_realloc(data->blendModes, (data->blendModesCount + 1) * sizeof(*blendModes)); - if (!blendModes) { + if (blendModes == NULL) { SAFE_RELEASE(blendState); SDL_OutOfMemory(); return NULL; @@ -448,7 +448,7 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer) } CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)SDL_LoadFunction(data->hDXGIMod, "CreateDXGIFactory"); - if (!CreateDXGIFactoryFunc) { + if (CreateDXGIFactoryFunc == NULL) { result = E_FAIL; goto done; } @@ -1105,7 +1105,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) } textureData = (D3D11_TextureData*) SDL_calloc(1, sizeof(*textureData)); - if (!textureData) { + if (textureData == NULL) { SDL_OutOfMemory(); return -1; } @@ -1275,7 +1275,7 @@ D3D11_DestroyTexture(SDL_Renderer * renderer, { D3D11_TextureData *data = (D3D11_TextureData *)texture->driverdata; - if (!data) { + if (data == NULL) { return; } @@ -1385,7 +1385,7 @@ D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata; D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -1431,7 +1431,7 @@ D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata; D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -1456,7 +1456,7 @@ D3D11_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture, D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata; D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -1481,7 +1481,7 @@ D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D11_TEXTURE2D_DESC stagingTextureDesc; D3D11_MAPPED_SUBRESOURCE textureMemory; - if (!textureData) { + if (textureData == NULL) { return SDL_SetError("Texture is not currently available"); } #if SDL_HAVE_YUV @@ -1562,7 +1562,7 @@ D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return; } #if SDL_HAVE_YUV @@ -1599,7 +1599,7 @@ D3D11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Sc { D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return; } @@ -1645,7 +1645,7 @@ D3D11_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL color.b = cmd->data.draw.b; color.a = cmd->data.draw.a; - if (!verts) { + if (verts == NULL) { return -1; } @@ -1673,7 +1673,7 @@ D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture int count = indices ? num_indices : num_vertices; VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertexPositionColor), 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -1885,8 +1885,7 @@ D3D11_GetCurrentRenderTargetView(SDL_Renderer * renderer) D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; if (data->currentOffscreenRenderTargetView) { return data->currentOffscreenRenderTargetView; - } - else { + } else { return data->mainRenderTargetView; } } @@ -1954,9 +1953,9 @@ D3D11_SetDrawState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, ID3D11 break; } } - if (!blendState) { + if (blendState == NULL) { blendState = D3D11_CreateBlendState(renderer, blendMode); - if (!blendState) { + if (blendState == NULL) { return -1; } } @@ -2372,13 +2371,13 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags) D3D11_RenderData *data; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); return NULL; } data = (D3D11_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { SDL_free(renderer); SDL_OutOfMemory(); return NULL; diff --git a/src/render/direct3d11/SDL_render_winrt.cpp b/src/render/direct3d11/SDL_render_winrt.cpp index 0a34895b94..f2ea6c548a 100644 --- a/src/render/direct3d11/SDL_render_winrt.cpp +++ b/src/render/direct3d11/SDL_render_winrt.cpp @@ -49,7 +49,7 @@ extern "C" void * D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer) { SDL_Window * sdlWindow = renderer->window; - if ( ! renderer->window ) { + if (renderer->window == NULL) { return NULL; } diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c index 18cb5b65bf..66a009df2e 100644 --- a/src/render/direct3d12/SDL_render_d3d12.c +++ b/src/render/direct3d12/SDL_render_d3d12.c @@ -266,7 +266,7 @@ static const GUID SDL_IID_ID3D12InfoQueue = { 0x0742a90b, 0xc387, 0x483f, { 0xb9 UINT D3D12_Align(UINT location, UINT alignment) { - return ((location + (alignment - 1)) & ~(alignment - 1)); + return (location + (alignment - 1)) & ~(alignment - 1); } Uint32 @@ -402,8 +402,7 @@ D3D12_CPUtoGPUHandle(ID3D12DescriptorHeap * heap, D3D12_CPU_DESCRIPTOR_HANDLE CP static void D3D12_WaitForGPU(D3D12_RenderData * data) { - if (data->commandQueue && data->fence && data->fenceEvent) - { + if (data->commandQueue && data->fence && data->fenceEvent) { D3D_CALL(data->commandQueue, Signal, data->fence, data->fenceValue); if (D3D_CALL(data->fence, GetCompletedValue) < data->fenceValue) { D3D_CALL(data->fence, SetEventOnCompletion, @@ -646,7 +645,7 @@ D3D12_CreatePipelineState(SDL_Renderer * renderer, } pipelineStates = (D3D12_PipelineState*)SDL_realloc(data->pipelineStates, (data->pipelineStateCount + 1) * sizeof(*pipelineStates)); - if (!pipelineStates) { + if (pipelineStates == NULL) { SAFE_RELEASE(pipelineState); SDL_OutOfMemory(); return NULL; @@ -764,7 +763,7 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer) } } #endif - if (!CreateEventExFunc) { + if (CreateEventExFunc == NULL) { result = E_FAIL; goto done; } @@ -777,7 +776,7 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer) } CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)SDL_LoadFunction(data->hDXGIMod, "CreateDXGIFactory2"); - if (!CreateDXGIFactoryFunc) { + if (CreateDXGIFactoryFunc == NULL) { result = E_FAIL; goto done; } @@ -821,7 +820,7 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer) /* If the debug hint is set, also create the DXGI factory in debug mode */ DXGIGetDebugInterfaceFunc = (PFN_CREATE_DXGI_FACTORY)SDL_LoadFunction(data->hDXGIMod, "DXGIGetDebugInterface1"); - if (!DXGIGetDebugInterfaceFunc) { + if (DXGIGetDebugInterfaceFunc == NULL) { result = E_FAIL; goto done; } @@ -1476,12 +1475,11 @@ D3D12_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) D3D12_SHADER_RESOURCE_VIEW_DESC resourceViewDesc; if (textureFormat == DXGI_FORMAT_UNKNOWN) { - return SDL_SetError("%s, An unsupported SDL pixel format (0x%x) was specified", - __FUNCTION__, texture->format); + return SDL_SetError("%s, An unsupported SDL pixel format (0x%x) was specified", __FUNCTION__, texture->format); } textureData = (D3D12_TextureData*) SDL_calloc(1, sizeof(*textureData)); - if (!textureData) { + if (textureData == NULL) { SDL_OutOfMemory(); return -1; } @@ -1668,7 +1666,7 @@ D3D12_DestroyTexture(SDL_Renderer * renderer, D3D12_RenderData *rendererData = (D3D12_RenderData*)renderer->driverdata; D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return; } @@ -1852,7 +1850,7 @@ D3D12_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->driverdata; D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -1898,7 +1896,7 @@ D3D12_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->driverdata; D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -1923,7 +1921,7 @@ D3D12_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture, D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->driverdata; D3D12_TextureData *textureData = (D3D12_TextureData *)texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return SDL_SetError("Texture is not currently available"); } @@ -1953,7 +1951,7 @@ D3D12_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, BYTE *textureMemory; int bpp; - if (!textureData) { + if (textureData == NULL) { return SDL_SetError("Texture is not currently available"); } #if SDL_HAVE_YUV @@ -2045,8 +2043,7 @@ D3D12_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, pitchedDesc.Depth = 1; if (pitchedDesc.Format == DXGI_FORMAT_R8_UNORM) { bpp = 1; - } - else { + } else { bpp = 4; } pitchedDesc.RowPitch = D3D12_Align(rect->w * bpp, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); @@ -2077,7 +2074,7 @@ D3D12_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) D3D12_TEXTURE_COPY_LOCATION dstLocation; int bpp; - if (!textureData) { + if (textureData == NULL) { return; } #if SDL_HAVE_YUV @@ -2105,8 +2102,7 @@ D3D12_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) pitchedDesc.Depth = 1; if (pitchedDesc.Format == DXGI_FORMAT_R8_UNORM) { bpp = 1; - } - else { + } else { bpp = 4; } pitchedDesc.RowPitch = D3D12_Align(textureData->lockedRect.w * bpp, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); @@ -2151,7 +2147,7 @@ D3D12_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Sc { D3D12_TextureData *textureData = (D3D12_TextureData *) texture->driverdata; - if (!textureData) { + if (textureData == NULL) { return; } @@ -2212,7 +2208,7 @@ D3D12_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL color.b = cmd->data.draw.b; color.a = cmd->data.draw.a; - if (!verts) { + if (verts == NULL) { return -1; } @@ -2240,7 +2236,7 @@ D3D12_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture int count = indices ? num_indices : num_vertices; VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertexPositionColor), 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -2616,8 +2612,8 @@ D3D12_SetCopyState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, const D3D12_TransitionResource(rendererData, textureData->mainTextureV, textureData->mainResourceStateV, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); textureData->mainResourceStateV = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE; - return D3D12_SetDrawState(renderer, cmd, shader, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, - SDL_arraysize(shaderResources), shaderResources, textureSampler, matrix); + return D3D12_SetDrawState(renderer, cmd, shader, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, SDL_arraysize(shaderResources), shaderResources, + textureSampler, matrix); } else if (textureData->nv12) { D3D12_CPU_DESCRIPTOR_HANDLE shaderResources[] = { textureData->mainTextureResourceView, @@ -2645,14 +2641,14 @@ D3D12_SetCopyState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, const D3D12_TransitionResource(rendererData, textureData->mainTextureNV, textureData->mainResourceStateNV, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); textureData->mainResourceStateNV = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE; - return D3D12_SetDrawState(renderer, cmd, shader, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, - SDL_arraysize(shaderResources), shaderResources, textureSampler, matrix); + return D3D12_SetDrawState(renderer, cmd, shader, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, SDL_arraysize(shaderResources), shaderResources, + textureSampler, matrix); } #endif /* SDL_HAVE_YUV */ D3D12_TransitionResource(rendererData, textureData->mainTexture, textureData->mainResourceState, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); textureData->mainResourceState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE; - return D3D12_SetDrawState(renderer, cmd, SHADER_RGB, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, - 1, &textureData->mainTextureResourceView, textureSampler, matrix); + return D3D12_SetDrawState(renderer, cmd, SHADER_RGB, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, 1, &textureData->mainTextureResourceView, + textureSampler, matrix); } static void @@ -3047,13 +3043,13 @@ D3D12_CreateRenderer(SDL_Window * window, Uint32 flags) D3D12_RenderData *data; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); return NULL; } data = (D3D12_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { SDL_free(renderer); SDL_OutOfMemory(); return NULL; diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index fd93b69dee..31b036745e 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -172,8 +172,7 @@ GL_ClearErrors(SDL_Renderer *renderer) { GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - if (!data->debug_enabled) - { + if (!data->debug_enabled) { return; } if (data->GL_ARB_debug_output_supported) { @@ -200,8 +199,7 @@ GL_CheckAllErrors (const char *prefix, SDL_Renderer *renderer, const char *file, GL_RenderData *data = (GL_RenderData *) renderer->driverdata; int ret = 0; - if (!data->debug_enabled) - { + if (!data->debug_enabled) { return 0; } if (data->GL_ARB_debug_output_supported) { @@ -312,7 +310,7 @@ GL_GetFBO(GL_RenderData *data, Uint32 w, Uint32 h) result = result->next; } - if (!result) { + if (result == NULL) { result = SDL_malloc(sizeof(GL_FBOList)); if (result) { result->w = w; @@ -477,7 +475,7 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) } data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { return SDL_OutOfMemory(); } @@ -579,8 +577,7 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) renderdata->glTexImage2D(textype, 0, internalFormat, texture_w, texture_h, 0, format, type, data->pixels); renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); - } - else + } else #endif { renderdata->glTexImage2D(textype, 0, internalFormat, texture_w, @@ -937,7 +934,7 @@ GL_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FP GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (GLfloat), 0, &cmd->data.draw.first); int i; - if (!verts) { + if (verts == NULL) { return -1; } @@ -958,7 +955,7 @@ GL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPo const size_t vertlen = (sizeof (GLfloat) * 2) * count; GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } cmd->data.draw.count = count; @@ -1004,7 +1001,7 @@ GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te size_t sz = 2 * sizeof(GLfloat) + 4 * sizeof(Uint8) + (texture ? 2 : 0) * sizeof(GLfloat); verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -1458,7 +1455,7 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { + if (temp_pixels == NULL) { return SDL_OutOfMemory(); } @@ -1525,7 +1522,7 @@ GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) renderdata->drawstate.target = NULL; } - if (!data) { + if (data == NULL) { return; } if (data->texture) { @@ -1759,13 +1756,13 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags) #endif renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); goto error; } data = (GL_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { SDL_free(renderer); SDL_OutOfMemory(); goto error; @@ -1860,7 +1857,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags) } hint = SDL_getenv("GL_ARB_texture_non_power_of_two"); - if (!hint || *hint != '0') { + if (hint == NULL || *hint != '0') { SDL_bool isGL2 = SDL_FALSE; const char *verstr = (const char *)data->glGetString(GL_VERSION); if (verstr) { diff --git a/src/render/opengl/SDL_shaders_gl.c b/src/render/opengl/SDL_shaders_gl.c index dfdf924a8b..b91b5bfa35 100644 --- a/src/render/opengl/SDL_shaders_gl.c +++ b/src/render/opengl/SDL_shaders_gl.c @@ -477,7 +477,7 @@ CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data) } ctx->glUseProgramObjectARB(0); - return (ctx->glGetError() == GL_NO_ERROR); + return ctx->glGetError() == GL_NO_ERROR; } static void @@ -496,7 +496,7 @@ GL_CreateShaderContext(void) int i; ctx = (GL_ShaderContext *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { return NULL; } diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c index 35d8d5ae02..38d389a0ea 100644 --- a/src/render/opengles/SDL_render_gles.c +++ b/src/render/opengles/SDL_render_gles.c @@ -314,7 +314,7 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) } data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { return SDL_OutOfMemory(); } @@ -409,7 +409,7 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, src = (Uint8 *)pixels; if (pitch != srcPitch) { blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); - if (!blob) { + if (blob == NULL) { return SDL_OutOfMemory(); } src = blob; @@ -529,7 +529,7 @@ GLES_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_ GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (GLfloat), 0, &cmd->data.draw.first); int i; - if (!verts) { + if (verts == NULL) { return -1; } @@ -550,7 +550,7 @@ GLES_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F const size_t vertlen = (sizeof (GLfloat) * 2) * count; GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } cmd->data.draw.count = count; @@ -596,7 +596,7 @@ GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture * int sz = 2 + 4 + (texture ? 2 : 0); verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * sz * sizeof (GLfloat), 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -903,7 +903,7 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { + if (temp_pixels == NULL) { return SDL_OutOfMemory(); } @@ -964,7 +964,7 @@ GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) renderdata->drawstate.target = NULL; } - if (!data) { + if (data == NULL) { return; } if (data->texture) { @@ -1080,13 +1080,13 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags) } renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); goto error; } data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { GLES_DestroyRenderer(renderer); SDL_OutOfMemory(); goto error; diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 8a6175b68a..65a2159bb3 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -418,7 +418,7 @@ GLES2_CacheProgram(GLES2_RenderData *data, GLuint vertex, GLuint fragment) /* Create a program cache entry */ entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry)); - if (!entry) { + if (entry == NULL) { SDL_OutOfMemory(); return NULL; } @@ -497,7 +497,7 @@ GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, GLenum shader_t const GLchar *shader_src_list[3]; const GLchar *shader_body = GLES2_GetShader(type); - if (!shader_body) { + if (shader_body == NULL) { SDL_SetError("No shader body src"); return 0; } @@ -708,7 +708,7 @@ GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source, int w, int /* Generate a matching program */ program = GLES2_CacheProgram(data, vertex, fragment); - if (!program) { + if (program == NULL) { goto fault; } @@ -743,7 +743,7 @@ GLES2_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL color.b = cmd->data.draw.b; color.a = cmd->data.draw.a; - if (!verts) { + if (verts == NULL) { return -1; } @@ -777,7 +777,7 @@ GLES2_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_ color.b = cmd->data.draw.b; color.a = cmd->data.draw.a; - if (!verts) { + if (verts == NULL) { return -1; } @@ -836,7 +836,7 @@ GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture if (texture) { SDL_Vertex *verts = (SDL_Vertex *) SDL_AllocateRenderVertices(renderer, count * sizeof (*verts), 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -876,7 +876,7 @@ GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture } else { SDL_VertexSolid *verts = (SDL_VertexSolid *) SDL_AllocateRenderVertices(renderer, count * sizeof (*verts), 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -1452,7 +1452,7 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) /* Allocate a texture struct */ data = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData)); - if (!data) { + if (data == NULL) { return SDL_OutOfMemory(); } data->texture = 0; @@ -1588,12 +1588,11 @@ GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoffset, GLint src = (Uint8 *)pixels; if (pitch != src_pitch) { blob = (Uint8 *)SDL_malloc(src_pitch * height); - if (!blob) { + if (blob == NULL) { return SDL_OutOfMemory(); } src = blob; - for (y = 0; y < height; ++y) - { + for (y = 0; y < height; ++y) { SDL_memcpy(src, pixels, src_pitch); src += src_pitch; pixels = (Uint8 *)pixels + pitch; @@ -1606,7 +1605,7 @@ GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoffset, GLint int i; Uint32 *src32 = (Uint32 *)src; blob2 = (Uint32 *)SDL_malloc(src_pitch * height); - if (!blob2) { + if (blob2 == NULL) { if (blob) { SDL_free(blob); } @@ -1943,7 +1942,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, } temp_pixels = SDL_malloc(buflen); - if (!temp_pixels) { + if (temp_pixels == NULL) { return SDL_OutOfMemory(); } @@ -2107,13 +2106,13 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) /* Create the renderer struct */ renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); goto error; } data = (GLES2_RenderData *)SDL_calloc(1, sizeof(GLES2_RenderData)); - if (!data) { + if (data == NULL) { SDL_free(renderer); SDL_OutOfMemory(); goto error; diff --git a/src/render/opengles2/SDL_shaders_gles2.c b/src/render/opengles2/SDL_shaders_gles2.c index 5c6a03efd4..bd1df75a85 100644 --- a/src/render/opengles2/SDL_shaders_gles2.c +++ b/src/render/opengles2/SDL_shaders_gles2.c @@ -379,12 +379,15 @@ GLES2_ShaderIncludeType GLES2_GetTexCoordPrecisionEnumFromHint() const char *texcoord_hint = SDL_GetHint("SDL_RENDER_OPENGLES2_TEXCOORD_PRECISION"); GLES2_ShaderIncludeType value = GLES2_SHADER_FRAGMENT_INCLUDE_BEST_TEXCOORD_PRECISION; if (texcoord_hint) { - if (SDL_strcmp(texcoord_hint, "undefined") == 0) + if (SDL_strcmp(texcoord_hint, "undefined") == 0) { return GLES2_SHADER_FRAGMENT_INCLUDE_UNDEF_PRECISION; - if (SDL_strcmp(texcoord_hint, "high") == 0) + } + if (SDL_strcmp(texcoord_hint, "high") == 0) { return GLES2_SHADER_FRAGMENT_INCLUDE_HIGH_TEXCOORD_PRECISION; - if (SDL_strcmp(texcoord_hint, "medium") == 0) + } + if (SDL_strcmp(texcoord_hint, "medium") == 0) { return GLES2_SHADER_FRAGMENT_INCLUDE_MEDIUM_TEXCOORD_PRECISION; + } } return value; } diff --git a/src/render/ps2/SDL_render_ps2.c b/src/render/ps2/SDL_render_ps2.c index d4db196f7a..a0c4a9a2be 100644 --- a/src/render/ps2/SDL_render_ps2.c +++ b/src/render/ps2/SDL_render_ps2.c @@ -65,7 +65,9 @@ static int vsync_handler() /* Copy of gsKit_sync_flip, but without the 'flip' */ static void gsKit_sync(GSGLOBAL *gsGlobal) { - if (!gsGlobal->FirstFrame) WaitSema(vsync_sema_id); + if (!gsGlobal->FirstFrame) { + WaitSema(vsync_sema_id); + } while (PollSema(vsync_sema_id) >= 0) ; } @@ -73,10 +75,8 @@ static void gsKit_sync(GSGLOBAL *gsGlobal) /* Copy of gsKit_sync_flip, but without the 'sync' */ static void gsKit_flip(GSGLOBAL *gsGlobal) { - if (!gsGlobal->FirstFrame) - { - if (gsGlobal->DoubleBuffering == GS_SETTING_ON) - { + if (!gsGlobal->FirstFrame) { + if (gsGlobal->DoubleBuffering == GS_SETTING_ON) { GS_SET_DISPFB2( gsGlobal->ScreenBuffer[ gsGlobal->ActiveBuffer & 1] / 8192, gsGlobal->Width / 64, gsGlobal->PSM, 0, 0 ); @@ -110,16 +110,16 @@ PS2_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { GSTEXTURE* ps2_tex = (GSTEXTURE*) SDL_calloc(1, sizeof(GSTEXTURE)); - if (!ps2_tex) + if (ps2_tex == NULL) { return SDL_OutOfMemory(); + } ps2_tex->Width = texture->w; ps2_tex->Height = texture->h; ps2_tex->PSM = PixelFormatToPS2PSM(texture->format); ps2_tex->Mem = memalign(128, gsKit_texture_size_ee(ps2_tex->Width, ps2_tex->Height, ps2_tex->PSM)); - if (!ps2_tex->Mem) - { + if (!ps2_tex->Mem) { SDL_free(ps2_tex); return SDL_OutOfMemory(); } @@ -214,7 +214,7 @@ PS2_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F gs_rgbaq rgbaq; int i; - if (!vertices) { + if (vertices == NULL) { return -1; } @@ -249,7 +249,7 @@ PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t if (texture) { GSPRIMSTQPOINT *vertices = (GSPRIMSTQPOINT *) SDL_AllocateRenderVertices(renderer, count * sizeof (GSPRIMSTQPOINT), 4, &cmd->data.draw.first); - if (!vertices) { + if (vertices == NULL) { return -1; } @@ -282,7 +282,7 @@ PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t } else { GSPRIMPOINT *vertices = (GSPRIMPOINT *) SDL_AllocateRenderVertices(renderer, count * sizeof (GSPRIMPOINT), 4, &cmd->data.draw.first); - if (!vertices) { + if (vertices == NULL) { return -1; } @@ -332,7 +332,7 @@ PS2_RenderSetClipRect(SDL_Renderer *renderer, SDL_RenderCommand *cmd) const SDL_Rect *rect = &cmd->data.cliprect.rect; - if(cmd->data.cliprect.enabled){ + if (cmd->data.cliprect.enabled) { gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(rect->x, rect->y, rect->w, rect->h)); } else { gsKit_set_scissor(data->gsGlobal, GS_SCISSOR_RESET); @@ -520,18 +520,20 @@ PS2_RenderPresent(SDL_Renderer * renderer) PS2_RenderData *data = (PS2_RenderData *) renderer->driverdata; if (data->gsGlobal->DoubleBuffering == GS_SETTING_OFF) { - if (data->vsync == 2) // Dynamic + if (data->vsync == 2) { // Dynamic gsKit_sync(data->gsGlobal); - else if (data->vsync == 1) + } else if (data->vsync == 1) { gsKit_vsync_wait(); + } gsKit_queue_exec(data->gsGlobal); } else { gsKit_queue_exec(data->gsGlobal); gsKit_finish(); - if (data->vsync == 2) // Dynamic + if (data->vsync == 2) { // Dynamic gsKit_sync(data->gsGlobal); - else if (data->vsync == 1) + } else if (data->vsync == 1) { gsKit_vsync_wait(); + } gsKit_flip(data->gsGlobal); } gsKit_TexManager_nextFrame(data->gsGlobal); @@ -545,11 +547,13 @@ PS2_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) GSTEXTURE *ps2_texture = (GSTEXTURE *) texture->driverdata; PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata; - if (data == NULL) + if (data == NULL) { return; + } - if(ps2_texture == NULL) + if (ps2_texture == NULL) { return; + } // Free from vram gsKit_TexManager_free(data->gsGlobal, ps2_texture); @@ -573,8 +577,9 @@ PS2_DestroyRenderer(SDL_Renderer * renderer) SDL_free(data); } - if (vsync_sema_id >= 0) + if (vsync_sema_id >= 0) { DeleteSema(vsync_sema_id); + } SDL_free(renderer); } @@ -598,13 +603,13 @@ PS2_CreateRenderer(SDL_Window * window, Uint32 flags) SDL_bool dynamicVsync; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); return NULL; } data = (PS2_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { PS2_DestroyRenderer(renderer); SDL_OutOfMemory(); return NULL; diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c index 1e026f5c7b..443a698516 100644 --- a/src/render/psp/SDL_render_psp.c +++ b/src/render/psp/SDL_render_psp.c @@ -181,19 +181,22 @@ static int TextureNextPow2(unsigned int w) { unsigned int n = 2; - if(w == 0) + if (w == 0) { return 0; + } - while(w > n) + while (w > n) { n <<= 1; + } return n; } static void psp_on_vblank(u32 sub, PSP_RenderData *data) { - if (data) + if (data) { data->vblank_not_reached = SDL_FALSE; + } } @@ -217,10 +220,10 @@ PixelFormatToPSPFMT(Uint32 format) ///SECTION render target LRU management static void LRUTargetRelink(PSP_TextureData* psp_texture) { - if(psp_texture->prevhotw) { + if (psp_texture->prevhotw) { psp_texture->prevhotw->nexthotw = psp_texture->nexthotw; } - if(psp_texture->nexthotw) { + if (psp_texture->nexthotw) { psp_texture->nexthotw->prevhotw = psp_texture->prevhotw; } } @@ -228,11 +231,11 @@ LRUTargetRelink(PSP_TextureData* psp_texture) { static void LRUTargetPushFront(PSP_RenderData* data, PSP_TextureData* psp_texture) { psp_texture->nexthotw = data->most_recent_target; - if(data->most_recent_target) { + if (data->most_recent_target) { data->most_recent_target->prevhotw = psp_texture; } data->most_recent_target = psp_texture; - if(!data->least_recent_target) { + if (!data->least_recent_target) { data->least_recent_target = psp_texture; } } @@ -240,10 +243,10 @@ LRUTargetPushFront(PSP_RenderData* data, PSP_TextureData* psp_texture) { static void LRUTargetRemove(PSP_RenderData* data, PSP_TextureData* psp_texture) { LRUTargetRelink(psp_texture); - if(data->most_recent_target == psp_texture) { + if (data->most_recent_target == psp_texture) { data->most_recent_target = psp_texture->nexthotw; } - if(data->least_recent_target == psp_texture) { + if (data->least_recent_target == psp_texture) { data->least_recent_target = psp_texture->prevhotw; } psp_texture->prevhotw = NULL; @@ -252,7 +255,7 @@ LRUTargetRemove(PSP_RenderData* data, PSP_TextureData* psp_texture) { static void LRUTargetBringFront(PSP_RenderData* data, PSP_TextureData* psp_texture) { - if(data->most_recent_target == psp_texture) { + if (data->most_recent_target == psp_texture) { return; //nothing to do } LRUTargetRemove(data, psp_texture); @@ -261,7 +264,7 @@ LRUTargetBringFront(PSP_RenderData* data, PSP_TextureData* psp_texture) { static void TextureStorageFree(void* storage) { - if(InVram(storage)) { + if (InVram(storage)) { vfree(storage); } else { SDL_free(storage); @@ -278,8 +281,9 @@ TextureSwizzle(PSP_TextureData *psp_texture, void* dst) unsigned int *src = NULL; unsigned char *data = NULL; - if(psp_texture->swizzled) + if (psp_texture->swizzled) { return 1; + } bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); height = psp_texture->size / bytewidth; @@ -290,21 +294,21 @@ TextureSwizzle(PSP_TextureData *psp_texture, void* dst) src = (unsigned int*) psp_texture->data; data = dst; - if(!data) { + if (data == NULL) { data = SDL_malloc(psp_texture->size); } - if(!data) { + if (data == NULL) { return SDL_OutOfMemory(); } - for(j = 0; j < height; j++, blockaddress += 16) + for (j = 0; j < height; j++, blockaddress += 16) { unsigned int *block; block = (unsigned int*)&data[blockaddress]; - for(i = 0; i < rowblocks; i++) + for (i = 0; i < rowblocks; i++) { *block++ = *src++; *block++ = *src++; @@ -313,8 +317,9 @@ TextureSwizzle(PSP_TextureData *psp_texture, void* dst) block += 28; } - if((j & 0x7) == 0x7) + if ((j & 0x7) == 0x7) { blockaddress += rowblocksadd; + } } TextureStorageFree(psp_texture->data); @@ -337,8 +342,9 @@ TextureUnswizzle(PSP_TextureData *psp_texture, void* dst) unsigned char *data = NULL; unsigned char *ydst = NULL; - if(!psp_texture->swizzled) + if (!psp_texture->swizzled) { return 1; + } bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); height = psp_texture->size / bytewidth; @@ -353,26 +359,27 @@ TextureUnswizzle(PSP_TextureData *psp_texture, void* dst) data = dst; - if(!data) { + if (data == NULL) { data = SDL_malloc(psp_texture->size); } - if(!data) + if (data == NULL) { return SDL_OutOfMemory(); + } ydst = (unsigned char *)data; - for(blocky = 0; blocky < heightblocks; ++blocky) + for (blocky = 0; blocky < heightblocks; ++blocky) { unsigned char *xdst = ydst; - for(blockx = 0; blockx < widthblocks; ++blockx) + for (blockx = 0; blockx < widthblocks; ++blockx) { unsigned int *block; block = (unsigned int*)xdst; - for(j = 0; j < 8; ++j) + for (j = 0; j < 8; ++j) { *(block++) = *(src++); *(block++) = *(src++); @@ -401,10 +408,10 @@ static int TextureSpillToSram(PSP_RenderData* data, PSP_TextureData* psp_texture) { // Assumes the texture is in VRAM - if(psp_texture->swizzled) { + if (psp_texture->swizzled) { //Texture was swizzled in vram, just copy to system memory void* sdata = SDL_malloc(psp_texture->size); - if(!sdata) { + if (sdata == NULL) { return SDL_OutOfMemory(); } @@ -422,7 +429,7 @@ TexturePromoteToVram(PSP_RenderData* data, PSP_TextureData* psp_texture, SDL_boo { // Assumes texture in sram and a large enough continuous block in vram void* tdata = vramalloc(psp_texture->size); - if(psp_texture->swizzled && target) { + if (psp_texture->swizzled && target) { return TextureUnswizzle(psp_texture, tdata); } else { SDL_memcpy(tdata, psp_texture->data, psp_texture->size); @@ -435,8 +442,8 @@ TexturePromoteToVram(PSP_RenderData* data, PSP_TextureData* psp_texture, SDL_boo static int TextureSpillLRU(PSP_RenderData* data, size_t wanted) { PSP_TextureData* lru = data->least_recent_target; - if(lru) { - if(TextureSpillToSram(data, lru) < 0) { + if (lru) { + if (TextureSpillToSram(data, lru) < 0) { return -1; } LRUTargetRemove(data, lru); @@ -450,8 +457,8 @@ TextureSpillLRU(PSP_RenderData* data, size_t wanted) { static int TextureSpillTargetsForSpace(PSP_RenderData* data, size_t size) { - while(vlargestblock() < size) { - if(TextureSpillLRU(data, size) < 0) { + while (vlargestblock() < size) { + if (TextureSpillLRU(data, size) < 0) { return -1; } } @@ -462,12 +469,12 @@ static int TextureBindAsTarget(PSP_RenderData* data, PSP_TextureData* psp_texture) { unsigned int dstFormat; - if(!InVram(psp_texture->data)) { + if (!InVram(psp_texture->data)) { // Bring back the texture in vram - if(TextureSpillTargetsForSpace(data, psp_texture->size) < 0) { + if (TextureSpillTargetsForSpace(data, psp_texture->size) < 0) { return -1; } - if(TexturePromoteToVram(data, psp_texture, SDL_TRUE) < 0) { + if (TexturePromoteToVram(data, psp_texture, SDL_TRUE) < 0) { return -1; } } @@ -476,7 +483,7 @@ TextureBindAsTarget(PSP_RenderData* data, PSP_TextureData* psp_texture) { // Stencil alpha dst hack dstFormat = psp_texture->format; - if(dstFormat == GU_PSM_5551) { + if (dstFormat == GU_PSM_5551) { sceGuEnable(GU_STENCIL_TEST); sceGuStencilOp(GU_REPLACE, GU_REPLACE, GU_REPLACE); sceGuStencilFunc(GU_GEQUAL, 0xff, 0xff); @@ -501,8 +508,9 @@ PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) PSP_RenderData *data = renderer->driverdata; PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture)); - if(!psp_texture) + if (psp_texture == NULL) { return SDL_OutOfMemory(); + } psp_texture->swizzled = SDL_FALSE; psp_texture->width = texture->w; @@ -530,21 +538,20 @@ PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format); psp_texture->size = psp_texture->textureHeight*psp_texture->pitch; - if(texture->access & SDL_TEXTUREACCESS_TARGET) { - if(TextureSpillTargetsForSpace(renderer->driverdata, psp_texture->size) < 0){ + if (texture->access & SDL_TEXTUREACCESS_TARGET) { + if (TextureSpillTargetsForSpace(renderer->driverdata, psp_texture->size) < 0) { SDL_free(psp_texture); return -1; } psp_texture->data = vramalloc(psp_texture->size); - if(psp_texture->data) { + if (psp_texture->data) { LRUTargetPushFront(data, psp_texture); } } else { psp_texture->data = SDL_calloc(1, psp_texture->size); } - if(!psp_texture->data) - { + if (!psp_texture->data) { SDL_free(psp_texture); return SDL_OutOfMemory(); } @@ -568,8 +575,7 @@ TextureActivate(SDL_Texture * texture) int scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GU_NEAREST : GU_LINEAR; /* Swizzling is useless with small textures. */ - if (TextureShouldSwizzle(psp_texture, texture)) - { + if (TextureShouldSwizzle(psp_texture, texture)) { TextureSwizzle(psp_texture, NULL); } @@ -661,7 +667,7 @@ PSP_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F VertV *verts = (VertV *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertV), 4, &cmd->data.draw.first); int i; - if (!verts) { + if (verts == NULL) { return -1; } @@ -691,7 +697,7 @@ PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t if (texture == NULL) { VertCV *verts; verts = (VertCV *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertCV), 4, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -724,7 +730,7 @@ PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; VertTCV *verts; verts = (VertTCV *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertTCV), 4, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -770,7 +776,7 @@ PSP_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FR VertV *verts = (VertV *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (VertV), 4, &cmd->data.draw.first); int i; - if (!verts) { + if (verts == NULL) { return -1; } @@ -805,10 +811,9 @@ PSP_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * tex const float u1 = srcrect->x + srcrect->w; const float v1 = srcrect->y + srcrect->h; - if((MathAbs(u1) - MathAbs(u0)) < 64.0f) - { + if ((MathAbs(u1) - MathAbs(u0)) < 64.0f) { verts = (VertTV *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (VertTV), 4, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -827,9 +832,7 @@ PSP_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * tex verts->y = y + height; verts->z = 0; verts++; - } - else - { + } else { float start, end; float curU = u0; float curX = x; @@ -839,18 +842,19 @@ PSP_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * tex size_t i; float ustep = (u1 - u0)/width * slice; - if(ustep < 0.0f) + if (ustep < 0.0f) { ustep = -ustep; + } cmd->data.draw.count = count; verts = (VertTV *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (VertTV), 4, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } - for(i = 0, start = 0, end = width; i < count; i++, start += slice) + for (i = 0, start = 0, end = width; i < count; i++, start += slice) { const float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice; const float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep; @@ -899,7 +903,7 @@ PSP_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * t float u1 = srcrect->x + srcrect->w; float v1 = srcrect->y + srcrect->h; - if (!verts) { + if (verts == NULL) { return -1; } @@ -985,16 +989,16 @@ StartDrawing(SDL_Renderer * renderer) PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; // Check if we need to start GU displaylist - if(!data->displayListAvail) { + if (!data->displayListAvail) { sceGuStart(GU_DIRECT, DisplayList); data->displayListAvail = SDL_TRUE; //ResetBlendState(&data->blendState); } // Check if we need a draw buffer change - if(renderer->target != data->boundTarget) { + if (renderer->target != data->boundTarget) { SDL_Texture* texture = renderer->target; - if(texture) { + if (texture) { PSP_TextureData* psp_texture = (PSP_TextureData*) texture->driverdata; // Set target, registering LRU TextureBindAsTarget(data, psp_texture); @@ -1043,16 +1047,16 @@ PSP_SetBlendState(PSP_RenderData* data, PSP_BlendState* state) } } - if(state->color != current->color) { + if (state->color != current->color) { sceGuColor(state->color); } - if(state->shadeModel != current->shadeModel) { + if (state->shadeModel != current->shadeModel) { sceGuShadeModel(state->shadeModel); } - if(state->texture != current->texture) { - if(state->texture != NULL) { + if (state->texture != current->texture) { + if (state->texture != NULL) { TextureActivate(state->texture); sceGuEnable(GU_TEXTURE_2D); } else { @@ -1077,7 +1081,7 @@ PSP_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti rendering backends report a reasonable maximum, so the higher level can flush if we appear to be exceeding that. */ gpumem = (Uint8 *) sceGuGetMemory(vertsize); - if (!gpumem) { + if (gpumem == NULL) { return SDL_SetError("Couldn't obtain a %d-byte vertex buffer!", (int) vertsize); } SDL_memcpy(gpumem, vertices, vertsize); @@ -1098,7 +1102,7 @@ PSP_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti case SDL_RENDERCMD_SETCLIPRECT: { const SDL_Rect *rect = &cmd->data.cliprect.rect; - if(cmd->data.cliprect.enabled){ + if (cmd->data.cliprect.enabled) { sceGuEnable(GU_SCISSOR_TEST); sceGuScissor(rect->x, rect->y, rect->w, rect->h); } else { @@ -1263,8 +1267,9 @@ PSP_RenderPresent(SDL_Renderer * renderer) sceGuFinish(); sceGuSync(0,0); - if ((data->vsync) && (data->vblank_not_reached)) + if ((data->vsync) && (data->vblank_not_reached)) { sceDisplayWaitVblankStart(); + } data->vblank_not_reached = SDL_TRUE; data->backbuffer = data->frontbuffer; @@ -1279,11 +1284,13 @@ PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; - if (renderdata == NULL) + if (renderdata == NULL) { return; + } - if(psp_texture == NULL) + if (psp_texture == NULL) { return; + } LRUTargetRemove(renderdata, psp_texture); TextureStorageFree(psp_texture->data); @@ -1296,8 +1303,9 @@ PSP_DestroyRenderer(SDL_Renderer * renderer) { PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; if (data) { - if (!data->initialized) + if (!data->initialized) { return; + } StartDrawing(renderer); @@ -1334,13 +1342,13 @@ PSP_CreateRenderer(SDL_Window * window, Uint32 flags) void* doublebuffer = NULL; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); return NULL; } data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { PSP_DestroyRenderer(renderer); SDL_OutOfMemory(); return NULL; diff --git a/src/render/software/SDL_blendfillrect.c b/src/render/software/SDL_blendfillrect.c index 569c15058b..d068232435 100644 --- a/src/render/software/SDL_blendfillrect.c +++ b/src/render/software/SDL_blendfillrect.c @@ -219,7 +219,7 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, { SDL_Rect clipped; - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_BlendFillRect(): dst"); } @@ -290,7 +290,7 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; int status = 0; - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_BlendFillRects(): dst"); } @@ -334,7 +334,7 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, break; } - if (!func) { + if (func == NULL) { if (!dst->format->Amask) { func = SDL_BlendFillRect_RGB; } else { diff --git a/src/render/software/SDL_blendline.c b/src/render/software/SDL_blendline.c index 4921bf1010..f7631c2926 100644 --- a/src/render/software/SDL_blendline.c +++ b/src/render/software/SDL_blendline.c @@ -808,12 +808,12 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, { BlendLineFunc func; - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_BlendLine(): dst"); } func = SDL_CalculateBlendLineFunc(dst->format); - if (!func) { + if (func == NULL) { return SDL_SetError("SDL_BlendLine(): Unsupported surface format"); } @@ -837,12 +837,12 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_bool draw_end; BlendLineFunc func; - if (!dst) { + if (dst == NULL) { return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); } func = SDL_CalculateBlendLineFunc(dst->format); - if (!func) { + if (func == NULL) { return SDL_SetError("SDL_BlendLines(): Unsupported surface format"); } diff --git a/src/render/software/SDL_blendpoint.c b/src/render/software/SDL_blendpoint.c index 613169b7ba..ffbf86677d 100644 --- a/src/render/software/SDL_blendpoint.c +++ b/src/render/software/SDL_blendpoint.c @@ -217,7 +217,7 @@ int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_BlendPoint(): dst"); } @@ -286,7 +286,7 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; int status = 0; - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_BlendPoints(): dst"); } @@ -332,7 +332,7 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, break; } - if (!func) { + if (func == NULL) { if (!dst->format->Amask) { func = SDL_BlendPoint_RGB; } else { diff --git a/src/render/software/SDL_drawline.c b/src/render/software/SDL_drawline.c index e309f16195..76f4b600b1 100644 --- a/src/render/software/SDL_drawline.c +++ b/src/render/software/SDL_drawline.c @@ -143,12 +143,12 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) { DrawLineFunc func; - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_DrawLine(): dst"); } func = SDL_CalculateDrawLineFunc(dst->format); - if (!func) { + if (func == NULL) { return SDL_SetError("SDL_DrawLine(): Unsupported surface format"); } @@ -172,12 +172,12 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_bool draw_end; DrawLineFunc func; - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_DrawLines(): dst"); } func = SDL_CalculateDrawLineFunc(dst->format); - if (!func) { + if (func == NULL) { return SDL_SetError("SDL_DrawLines(): Unsupported surface format"); } diff --git a/src/render/software/SDL_drawpoint.c b/src/render/software/SDL_drawpoint.c index b99838ac62..5c16075439 100644 --- a/src/render/software/SDL_drawpoint.c +++ b/src/render/software/SDL_drawpoint.c @@ -29,7 +29,7 @@ int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) { - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_DrawPoint(): dst"); } @@ -70,7 +70,7 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, int i; int x, y; - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_DrawPoints(): dst"); } diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 34b1c88f50..975447afc7 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -141,8 +141,9 @@ SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, int row; size_t length; - if(SDL_MUSTLOCK(surface)) + if (SDL_MUSTLOCK(surface)) { SDL_LockSurface(surface); + } src = (Uint8 *) pixels; dst = (Uint8 *) surface->pixels + rect->y * surface->pitch + @@ -153,8 +154,9 @@ SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, src += pitch; dst += surface->pitch; } - if(SDL_MUSTLOCK(surface)) + if (SDL_MUSTLOCK(surface)) { SDL_UnlockSurface(surface); + } return 0; } @@ -206,7 +208,7 @@ SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FP SDL_Point *verts = (SDL_Point *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Point), 0, &cmd->data.draw.first); int i; - if (!verts) { + if (verts == NULL) { return -1; } @@ -226,7 +228,7 @@ SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRe SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Rect), 0, &cmd->data.draw.first); int i; - if (!verts) { + if (verts == NULL) { return -1; } @@ -248,7 +250,7 @@ SW_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * text { SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (SDL_Rect), 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -283,7 +285,7 @@ SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * te { CopyExData *verts = (CopyExData *) SDL_AllocateRenderVertices(renderer, sizeof (CopyExData), 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -339,7 +341,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex int blitRequired = SDL_FALSE; int isOpaque = SDL_FALSE; - if (!surface) { + if (surface == NULL) { return -1; } @@ -558,7 +560,7 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te int sz = texture ? sizeof (GeometryCopyData) : sizeof (GeometryFillData); verts = (void *) SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first); - if (!verts) { + if (verts == NULL) { return -1; } @@ -683,7 +685,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic SDL_Surface *surface = SW_ActivateRenderer(renderer); SW_DrawStateCache drawstate; - if (!surface) { + if (surface == NULL) { return -1; } @@ -959,7 +961,7 @@ SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 src_format; void *src_pixels; - if (!surface) { + if (surface == NULL) { return -1; } @@ -987,7 +989,7 @@ SW_RenderPresent(SDL_Renderer * renderer) { SDL_Window *window = renderer->window; - if (!window) { + if (window == NULL) { return -1; } return SDL_UpdateWindowSurface(window); @@ -1110,19 +1112,19 @@ SW_CreateRendererForSurface(SDL_Surface * surface) SDL_Renderer *renderer; SW_RenderData *data; - if (!surface) { + if (surface == NULL) { SDL_InvalidParamError("surface"); return NULL; } renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); return NULL; } data = (SW_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { SW_DestroyRenderer(renderer); SDL_OutOfMemory(); return NULL; @@ -1170,7 +1172,7 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags) /* Set the vsync hint based on our flags, if it's not already set */ hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC); - if (!hint || !*hint) { + if (hint == NULL || !*hint) { no_hint_set = SDL_TRUE; } else { no_hint_set = SDL_FALSE; @@ -1187,7 +1189,7 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags) SDL_SetHint(SDL_HINT_RENDER_VSYNC, ""); } - if (!surface) { + if (surface == NULL) { return NULL; } return SW_CreateRendererForSurface(surface); diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c index 96c2628870..258e5dba5a 100644 --- a/src/render/software/SDL_rotate.c +++ b/src/render/software/SDL_rotate.c @@ -151,10 +151,13 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP { /* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */ int angle90 = (int)(angle/90); - if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */ + if (angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */ angle90 %= 4; - if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ - if(angle90 & 1) { + if (angle90 < 0) { + angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ + } + + if (angle90 & 1) { rect_dest->w = height; rect_dest->h = width; *cangle = 0; @@ -283,8 +286,12 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, for (x = 0; x < dst->w; x++) { int dx = (sdx >> 16); int dy = (sdy >> 16); - if (flipx) dx = sw - dx; - if (flipy) dy = sh - dy; + if (flipx) { + dx = sw - dx; + } + if (flipy) { + dy = sh - dy; + } if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) { int ex, ey; int t1, t2; @@ -340,8 +347,12 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int dx = (sdx >> 16); int dy = (sdy >> 16); if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) { - if(flipx) dx = sw - dx; - if(flipy) dy = sh - dy; + if (flipx) { + dx = sw - dx; + } + if (flipy) { + dy = sh - dy; + } *pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx); } sdx += icos; @@ -410,8 +421,12 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int int dx = (sdx >> 16); int dy = (sdy >> 16); if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) { - if (flipx) dx = sw - dx; - if (flipy) dy = sh- dy; + if (flipx) { + dx = sw - dx; + } + if (flipy) { + dy = sh - dy; + } *pc = *((tColorY *)src->pixels + src->pitch * dy + dx); } sdx += icos; @@ -462,8 +477,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int double sangleinv, cangleinv; /* Sanity check */ - if (src == NULL) + if (src == NULL) { return NULL; + } if (SDL_HasColorKey(src)) { if (SDL_GetColorKey(src, &colorkey) == 0) { @@ -472,8 +488,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int } /* This function requires a 32-bit surface or 8-bit surface with a colorkey */ is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable; - if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask))) + if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask))) { return NULL; + } /* Calculate target factors from sine/cosine and zoom */ sangleinv = sangle*65536.0; @@ -500,8 +517,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int } /* Check target */ - if (rz_dst == NULL) + if (rz_dst == NULL) { return NULL; + } /* Adjust for guard rows */ rz_dst->h = rect_dest->h; @@ -541,14 +559,17 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int angle90 = (int)(angle/90); if (angle90 == angle/90) { angle90 %= 4; - if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ + if (angle90 < 0) { + angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ + } + } else { angle90 = -1; } if (is8bit) { /* Call the 8-bit transformation routine to do the rotation */ - if(angle90 >= 0) { + if (angle90 >= 0) { transformSurfaceY90(src, rz_dst, angle90, flipx, flipy); } else { transformSurfaceY(src, rz_dst, (int)sangleinv, (int)cangleinv, diff --git a/src/render/software/SDL_triangle.c b/src/render/software/SDL_triangle.c index 4f9b8838a5..b2bd163e15 100644 --- a/src/render/software/SDL_triangle.c +++ b/src/render/software/SDL_triangle.c @@ -519,14 +519,26 @@ int SDL_SW_BlitTriangle( maxx = srcrect.x + srcrect.w; maxy = srcrect.y + srcrect.h; if (srcrect.w > 0) { - if (s0->x == maxx) s0->x--; - if (s1->x == maxx) s1->x--; - if (s2->x == maxx) s2->x--; + if (s0->x == maxx) { + s0->x--; + } + if (s1->x == maxx) { + s1->x--; + } + if (s2->x == maxx) { + s2->x--; + } } if (srcrect.h > 0) { - if (s0->y == maxy) s0->y--; - if (s1->y == maxy) s1->y--; - if (s2->y == maxy) s2->y--; + if (s0->y == maxy) { + s0->y--; + } + if (s1->y == maxy) { + s1->y--; + } + if (s2->y == maxy) { + s2->y--; + } } } diff --git a/src/render/vitagxm/SDL_render_vita_gxm.c b/src/render/vitagxm/SDL_render_vita_gxm.c index 3c4b33a050..dea46391b8 100644 --- a/src/render/vitagxm/SDL_render_vita_gxm.c +++ b/src/render/vitagxm/SDL_render_vita_gxm.c @@ -226,13 +226,13 @@ VITA_GXM_CreateRenderer(SDL_Window *window, Uint32 flags) VITA_GXM_RenderData *data; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { + if (renderer == NULL) { SDL_OutOfMemory(); return NULL; } data = (VITA_GXM_RenderData *) SDL_calloc(1, sizeof(VITA_GXM_RenderData)); - if (!data) { + if (data == NULL) { SDL_free(renderer); SDL_OutOfMemory(); return NULL; @@ -280,8 +280,7 @@ VITA_GXM_CreateRenderer(SDL_Window *window, Uint32 flags) sceSysmoduleLoadModule( SCE_SYSMODULE_RAZOR_CAPTURE ); #endif - if (gxm_init(renderer) != 0) - { + if (gxm_init(renderer) != 0) { SDL_free(data); SDL_free(renderer); return NULL; @@ -308,7 +307,7 @@ VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata; VITA_GXM_TextureData* vita_texture = (VITA_GXM_TextureData*) SDL_calloc(1, sizeof(VITA_GXM_TextureData)); - if (!vita_texture) { + if (vita_texture == NULL) { return SDL_OutOfMemory(); } @@ -647,8 +646,7 @@ VITA_GXM_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) static void VITA_GXM_SetBlendMode(VITA_GXM_RenderData *data, int blendMode) { - if (blendMode != data->currentBlendMode) - { + if (blendMode != data->currentBlendMode) { fragment_programs *in = &data->blendFragmentPrograms.blend_mode_blend; switch (blendMode) @@ -709,8 +707,7 @@ VITA_GXM_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const cmd->data.draw.first = (size_t)vertex; cmd->data.draw.count = count; - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { vertex[i].x = points[i].x; vertex[i].y = points[i].y; vertex[i].color = color; @@ -733,8 +730,7 @@ VITA_GXM_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const S cmd->data.draw.first = (size_t)vertex; cmd->data.draw.count = (count-1) * 2; - for (int i = 0; i < count - 1; i++) - { + for (int i = 0; i < count - 1; i++) { vertex[i*2].x = points[i].x; vertex[i*2].y = points[i].y; vertex[i*2].color = color; @@ -768,7 +764,7 @@ VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Textu data, count * sizeof(texture_vertex)); - if (!vertices) { + if (vertices == NULL) { return -1; } @@ -808,7 +804,7 @@ VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Textu data, count * sizeof(color_vertex)); - if (!vertices) { + if (vertices == NULL) { return -1; } @@ -1146,7 +1142,7 @@ VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect, } temp_pixels = SDL_malloc(buflen); - if (!temp_pixels) { + if (temp_pixels == NULL) { return SDL_OutOfMemory(); } @@ -1234,14 +1230,17 @@ VITA_GXM_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata; VITA_GXM_TextureData *vita_texture = (VITA_GXM_TextureData *) texture->driverdata; - if (data == NULL) + if (data == NULL) { return; + } - if(vita_texture == NULL) + if (vita_texture == NULL) { return; + } - if(vita_texture->tex == NULL) + if (vita_texture->tex == NULL) { return; + } sceGxmFinish(data->gxm_context); @@ -1257,8 +1256,9 @@ VITA_GXM_DestroyRenderer(SDL_Renderer *renderer) { VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata; if (data) { - if (!data->initialized) + if (!data->initialized) { return; + } gxm_finish(renderer); diff --git a/src/render/vitagxm/SDL_render_vita_gxm_memory.c b/src/render/vitagxm/SDL_render_vita_gxm_memory.c index 85d682ad73..dee8d600b3 100644 --- a/src/render/vitagxm/SDL_render_vita_gxm_memory.c +++ b/src/render/vitagxm/SDL_render_vita_gxm_memory.c @@ -38,14 +38,17 @@ vita_mem_alloc(unsigned int type, unsigned int size, unsigned int alignment, uns *uid = sceKernelAllocMemBlock("gpu_mem", type, size, NULL); - if (*uid < 0) + if (*uid < 0) { return NULL; + } - if (sceKernelGetMemBlockBase(*uid, &mem) < 0) + if (sceKernelGetMemBlockBase(*uid, &mem) < 0) { return NULL; + } - if (sceGxmMapMemory(mem, size, attribs) < 0) + if (sceGxmMapMemory(mem, size, attribs) < 0) { return NULL; + } return mem; } @@ -54,8 +57,9 @@ void vita_mem_free(SceUID uid) { void *mem = NULL; - if (sceKernelGetMemBlockBase(uid, &mem) < 0) + if (sceKernelGetMemBlockBase(uid, &mem) < 0) { return; + } sceGxmUnmapMemory(mem); sceKernelFreeMemBlock(uid); } @@ -82,8 +86,7 @@ vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size) } ret = sceKernelGetMemBlockBase(data->texturePoolUID, &mem); - if ( ret < 0) - { + if ( ret < 0) { return NULL; } data->texturePool = sceClibMspaceCreate(mem, poolsize); @@ -92,8 +95,7 @@ vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size) return NULL; } ret = sceGxmMapMemory(mem, poolsize, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE); - if (ret < 0) - { + if (ret < 0) { return NULL; } } @@ -103,8 +105,7 @@ vita_gpu_mem_alloc(VITA_GXM_RenderData *data, unsigned int size) void vita_gpu_mem_free(VITA_GXM_RenderData *data, void* ptr) { - if (data->texturePool != NULL) - { + if (data->texturePool != NULL) { sceClibMspaceFree(data->texturePool, ptr); } } @@ -113,12 +114,12 @@ void vita_gpu_mem_destroy(VITA_GXM_RenderData *data) { void *mem = NULL; - if (data->texturePool != NULL) - { + if (data->texturePool != NULL) { sceClibMspaceDestroy(data->texturePool); data->texturePool = NULL; - if (sceKernelGetMemBlockBase(data->texturePoolUID, &mem) < 0) + if (sceKernelGetMemBlockBase(data->texturePoolUID, &mem) < 0) { return; + } sceGxmUnmapMemory(mem); sceKernelFreeMemBlock(data->texturePoolUID); } @@ -132,10 +133,12 @@ vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_of size = ALIGN(size, 4096); *uid = sceKernelAllocMemBlock("vertex_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL); - if (sceKernelGetMemBlockBase(*uid, &mem) < 0) + if (sceKernelGetMemBlockBase(*uid, &mem) < 0) { return NULL; - if (sceGxmMapVertexUsseMemory(mem, size, usse_offset) < 0) + } + if (sceGxmMapVertexUsseMemory(mem, size, usse_offset) < 0) { return NULL; + } return mem; } @@ -144,8 +147,9 @@ void vita_mem_vertex_usse_free(SceUID uid) { void *mem = NULL; - if (sceKernelGetMemBlockBase(uid, &mem) < 0) + if (sceKernelGetMemBlockBase(uid, &mem) < 0) { return; + } sceGxmUnmapVertexUsseMemory(mem); sceKernelFreeMemBlock(uid); } @@ -158,10 +162,12 @@ vita_mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_ size = ALIGN(size, 4096); *uid = sceKernelAllocMemBlock("fragment_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL); - if (sceKernelGetMemBlockBase(*uid, &mem) < 0) + if (sceKernelGetMemBlockBase(*uid, &mem) < 0) { return NULL; - if (sceGxmMapFragmentUsseMemory(mem, size, usse_offset) < 0) + } + if (sceGxmMapFragmentUsseMemory(mem, size, usse_offset) < 0) { return NULL; + } return mem; } @@ -170,8 +176,9 @@ void vita_mem_fragment_usse_free(SceUID uid) { void *mem = NULL; - if (sceKernelGetMemBlockBase(uid, &mem) < 0) + if (sceKernelGetMemBlockBase(uid, &mem) < 0) { return; + } sceGxmUnmapFragmentUsseMemory(mem); sceKernelFreeMemBlock(uid); } diff --git a/src/render/vitagxm/SDL_render_vita_gxm_tools.c b/src/render/vitagxm/SDL_render_vita_gxm_tools.c index 9f3f91420a..8cb59ceb02 100644 --- a/src/render/vitagxm/SDL_render_vita_gxm_tools.c +++ b/src/render/vitagxm/SDL_render_vita_gxm_tools.c @@ -258,7 +258,7 @@ set_stencil_mask(VITA_GXM_RenderData *data, float x, float y, float w, float h) void set_clip_rectangle(VITA_GXM_RenderData *data, int x_min, int y_min, int x_max, int y_max) { - if(data->drawing) { + if (data->drawing) { // clear the stencil buffer to 0 sceGxmSetFrontStencilFunc( data->gxm_context, @@ -748,8 +748,7 @@ gxm_init(SDL_Renderer *renderer) &data->linearIndicesUid ); - for (i = 0; i <= UINT16_MAX; ++i) - { + for (i = 0; i <= UINT16_MAX; ++i) { data->linearIndices[i] = i; } @@ -927,8 +926,7 @@ void gxm_finish(SDL_Renderer *renderer) // clean up display queue vita_mem_free(data->depthBufferUid); - for (size_t i = 0; i < VITA_GXM_BUFFERS; i++) - { + for (size_t i = 0; i < VITA_GXM_BUFFERS; i++) { // clear the buffer then deallocate SDL_memset(data->displayBufferData[i], 0, VITA_GXM_SCREEN_HEIGHT * VITA_GXM_SCREEN_STRIDE * 4); vita_mem_free(data->displayBufferUid[i]); @@ -1048,8 +1046,9 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc tex_size += (((aligned_w + 1) / 2) * ((h + 1) / 2)) * 2; } - if (!texture) + if (texture == NULL) { return NULL; + } *return_w = w; *return_h = h; @@ -1062,7 +1061,7 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc ); /* Try SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE in case we're out of VRAM */ - if (!texture_data) { + if (texture_data == NULL) { SDL_LogWarn(SDL_LOG_CATEGORY_RENDER, "CDRAM texture allocation failed\n"); texture_data = vita_mem_alloc( SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, @@ -1076,7 +1075,7 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc texture->cdram = 1; } - if (!texture_data) { + if (texture_data == NULL) { SDL_free(texture); return NULL; } @@ -1209,8 +1208,7 @@ void gxm_minimal_term_for_common_dialog(void) void gxm_init_for_common_dialog(void) { - for (int i = 0; i < VITA_GXM_BUFFERS; i += 1) - { + for (int i = 0; i < VITA_GXM_BUFFERS; i += 1) { buffer_for_common_dialog[i].displayData.wait_vblank = SDL_TRUE; buffer_for_common_dialog[i].displayData.address = vita_mem_alloc( SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, @@ -1258,8 +1256,7 @@ void gxm_swap_for_common_dialog(void) void gxm_term_for_common_dialog(void) { sceGxmDisplayQueueFinish(); - for (int i = 0; i < VITA_GXM_BUFFERS; i += 1) - { + for (int i = 0; i < VITA_GXM_BUFFERS; i += 1) { vita_mem_free(buffer_for_common_dialog[i].uid); sceGxmSyncObjectDestroy(buffer_for_common_dialog[i].sync); } diff --git a/src/sensor/SDL_sensor.c b/src/sensor/SDL_sensor.c index 5c501fffb7..fcd70aa249 100644 --- a/src/sensor/SDL_sensor.c +++ b/src/sensor/SDL_sensor.c @@ -76,7 +76,7 @@ SDL_SensorInit(void) int i, status; /* Create the sensor list lock */ - if (!SDL_sensor_lock) { + if (SDL_sensor_lock == NULL) { SDL_sensor_lock = SDL_CreateMutex(); } diff --git a/src/sensor/android/SDL_androidsensor.c b/src/sensor/android/SDL_androidsensor.c index ddc6b304c8..ea4b9e973c 100644 --- a/src/sensor/android/SDL_androidsensor.c +++ b/src/sensor/android/SDL_androidsensor.c @@ -52,14 +52,14 @@ SDL_ANDROID_SensorInit(void) ASensorList sensors; SDL_sensor_manager = ASensorManager_getInstance(); - if (!SDL_sensor_manager) { + if (SDL_sensor_manager == NULL) { return SDL_SetError("Couldn't create sensor manager"); } SDL_sensor_looper = ALooper_forThread(); - if (!SDL_sensor_looper) { + if (SDL_sensor_looper == NULL) { SDL_sensor_looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); - if (!SDL_sensor_looper) { + if (SDL_sensor_looper == NULL) { return SDL_SetError("Couldn't create sensor event loop"); } } @@ -68,7 +68,7 @@ SDL_ANDROID_SensorInit(void) sensors_count = ASensorManager_getSensorList(SDL_sensor_manager, &sensors); if (sensors_count > 0) { SDL_sensors = (SDL_AndroidSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors)); - if (!SDL_sensors) { + if (SDL_sensors == NULL) { return SDL_OutOfMemory(); } diff --git a/src/sensor/vita/SDL_vitasensor.c b/src/sensor/vita/SDL_vitasensor.c index 9fcc85fc1a..047008ac37 100644 --- a/src/sensor/vita/SDL_vitasensor.c +++ b/src/sensor/vita/SDL_vitasensor.c @@ -52,7 +52,7 @@ SDL_VITA_SensorInit(void) SDL_sensors_count = 2; SDL_sensors = (SDL_VitaSensor *)SDL_calloc(SDL_sensors_count, sizeof(*SDL_sensors)); - if (!SDL_sensors) { + if (SDL_sensors == NULL) { return SDL_OutOfMemory(); } @@ -142,15 +142,12 @@ SDL_VITA_SensorUpdate(SDL_Sensor *sensor) SDL_memset(motionState, 0, sizeof(motionState)); err = sceMotionGetSensorState(motionState, SCE_MOTION_MAX_NUM_STATES); - if (err != 0) - { + if (err != 0) { return; } - for (int i = 0; i < SCE_MOTION_MAX_NUM_STATES; i++) - { - if (sensor->hwdata->counter < motionState[i].counter) - { + for (int i = 0; i < SCE_MOTION_MAX_NUM_STATES; i++) { + if (sensor->hwdata->counter < motionState[i].counter) { unsigned int timestamp = motionState[i].timestamp; sensor->hwdata->counter = motionState[i].counter; diff --git a/src/sensor/windows/SDL_windowssensor.c b/src/sensor/windows/SDL_windowssensor.c index 4e0ea508c3..0fc75f0df0 100644 --- a/src/sensor/windows/SDL_windowssensor.c +++ b/src/sensor/windows/SDL_windowssensor.c @@ -62,7 +62,7 @@ static int DisconnectSensor(ISensor *sensor); static HRESULT STDMETHODCALLTYPE ISensorManagerEventsVtbl_QueryInterface(ISensorManagerEvents * This, REFIID riid, void **ppvObject) { - if (!ppvObject) { + if (ppvObject == NULL) { return E_INVALIDARG; } @@ -102,7 +102,7 @@ static ISensorManagerEvents sensor_manager_events = { static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_QueryInterface(ISensorEvents * This, REFIID riid, void **ppvObject) { - if (!ppvObject) { + if (ppvObject == NULL) { return E_INVALIDARG; } @@ -281,7 +281,7 @@ static int ConnectSensor(ISensor *sensor) if (bstr_name != NULL) { SysFreeString(bstr_name); } - if (!name) { + if (name == NULL) { return SDL_OutOfMemory(); } diff --git a/src/stdlib/SDL_crc16.c b/src/stdlib/SDL_crc16.c index 8f6fb48c00..3d52c076dc 100644 --- a/src/stdlib/SDL_crc16.c +++ b/src/stdlib/SDL_crc16.c @@ -47,7 +47,7 @@ Uint16 SDL_crc16(Uint16 crc, const void *data, size_t len) { /* As an optimization we can precalculate a 256 entry table for each byte */ size_t i; - for(i = 0; i < len; ++i) { + for (i = 0; i < len; ++i) { crc = crc16_for_byte((Uint8)crc ^ ((const Uint8*)data)[i]) ^ crc >> 8; } return crc; diff --git a/src/stdlib/SDL_crc32.c b/src/stdlib/SDL_crc32.c index 48717f4442..9dd011987b 100644 --- a/src/stdlib/SDL_crc32.c +++ b/src/stdlib/SDL_crc32.c @@ -45,7 +45,7 @@ Uint32 SDL_crc32(Uint32 crc, const void *data, size_t len) { /* As an optimization we can precalculate a 256 entry table for each byte */ size_t i; - for(i = 0; i < len; ++i) { + for (i = 0; i < len; ++i) { crc = crc32_for_byte((Uint8)crc ^ ((const Uint8*)data)[i]) ^ crc >> 8; } return crc; diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index 4047cee3a5..748639dec0 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -47,8 +47,8 @@ int SDL_setenv(const char *name, const char *value, int overwrite) { /* Input validation */ - if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) { - return (-1); + if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) { + return -1; } return setenv(name, value, overwrite); @@ -58,8 +58,8 @@ int SDL_setenv(const char *name, const char *value, int overwrite) { /* Input validation */ - if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) { - return (-1); + if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) { + return -1; } if (!overwrite) { @@ -81,8 +81,8 @@ SDL_setenv(const char *name, const char *value, int overwrite) char *new_variable; /* Input validation */ - if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) { - return (-1); + if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) { + return -1; } if (getenv(name) != NULL) { @@ -96,8 +96,8 @@ SDL_setenv(const char *name, const char *value, int overwrite) /* This leaks. Sorry. Get a better OS so we don't have to do this. */ len = SDL_strlen(name) + SDL_strlen(value) + 2; new_variable = (char *) SDL_malloc(len); - if (!new_variable) { - return (-1); + if (new_variable == NULL) { + return -1; } SDL_snprintf(new_variable, len, "%s=%s", name, value); @@ -114,8 +114,8 @@ SDL_setenv(const char *name, const char *value, int overwrite) char *new_variable; /* Input validation */ - if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) { - return (-1); + if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) { + return -1; } /* See if it already exists */ @@ -126,8 +126,8 @@ SDL_setenv(const char *name, const char *value, int overwrite) /* Allocate memory for the variable */ len = SDL_strlen(name) + SDL_strlen(value) + 2; new_variable = (char *) SDL_malloc(len); - if (!new_variable) { - return (-1); + if (new_variable == NULL) { + return -1; } SDL_snprintf(new_variable, len, "%s=%s", name, value); @@ -165,7 +165,7 @@ SDL_setenv(const char *name, const char *value, int overwrite) SDL_free(new_variable); } } - return (added ? 0 : -1); + return added ? 0 : -1; } #endif @@ -180,7 +180,7 @@ SDL_getenv(const char *name) #endif /* Input validation */ - if (!name || *name == '\0') { + if (name == NULL || *name == '\0') { return NULL; } @@ -193,7 +193,7 @@ SDL_getenv(const char *name) size_t bufferlen; /* Input validation */ - if (!name || *name == '\0') { + if (name == NULL || *name == '\0') { return NULL; } @@ -221,14 +221,14 @@ SDL_getenv(const char *name) char *value; /* Input validation */ - if (!name || *name == '\0') { + if (name == NULL || *name == '\0') { return NULL; } value = (char *) 0; if (SDL_env) { len = SDL_strlen(name); - for (i = 0; SDL_env[i] && !value; ++i) { + for (i = 0; SDL_env[i] && value == NULL; ++i) { if ((SDL_strncmp(SDL_env[i], name, len) == 0) && (SDL_env[i][len] == '=')) { value = &SDL_env[i][len + 1]; @@ -307,7 +307,7 @@ main(int argc, char *argv[]) } else { printf("failed\n"); } - return (0); + return 0; } #endif /* TEST_MAIN */ diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c index 487b08cce4..3d362130cb 100644 --- a/src/stdlib/SDL_iconv.c +++ b/src/stdlib/SDL_iconv.c @@ -168,16 +168,16 @@ getlocale(char *buffer, size_t bufsize) char *ptr; lang = SDL_getenv("LC_ALL"); - if (!lang) { + if (lang == NULL) { lang = SDL_getenv("LC_CTYPE"); } - if (!lang) { + if (lang == NULL) { lang = SDL_getenv("LC_MESSAGES"); } - if (!lang) { + if (lang == NULL) { lang = SDL_getenv("LANG"); } - if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) { + if (lang == NULL || !*lang || SDL_strcmp(lang, "C") == 0) { lang = "ASCII"; } @@ -205,10 +205,10 @@ SDL_iconv_open(const char *tocode, const char *fromcode) char fromcode_buffer[64]; char tocode_buffer[64]; - if (!fromcode || !*fromcode) { + if (fromcode == NULL || !*fromcode) { fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer)); } - if (!tocode || !*tocode) { + if (tocode == NULL || !*tocode) { tocode = getlocale(tocode_buffer, sizeof(tocode_buffer)); } for (i = 0; i < SDL_arraysize(encodings); ++i) { @@ -248,11 +248,11 @@ SDL_iconv(SDL_iconv_t cd, Uint32 ch = 0; size_t total; - if (!inbuf || !*inbuf) { + if (inbuf == NULL || !*inbuf) { /* Reset the context */ return 0; } - if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) { + if (outbuf == NULL || !*outbuf || outbytesleft == NULL || !*outbytesleft) { return SDL_ICONV_E2BIG; } src = *inbuf; @@ -818,10 +818,10 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, cd = SDL_iconv_open(tocode, fromcode); if (cd == (SDL_iconv_t) - 1) { /* See if we can recover here (fixes iconv on Solaris 11) */ - if (!tocode || !*tocode) { + if (tocode == NULL || !*tocode) { tocode = "UTF-8"; } - if (!fromcode || !*fromcode) { + if (fromcode == NULL || !*fromcode) { fromcode = "UTF-8"; } cd = SDL_iconv_open(tocode, fromcode); @@ -832,7 +832,7 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, stringsize = inbytesleft > 4 ? inbytesleft : 4; string = (char *) SDL_malloc(stringsize); - if (!string) { + if (string == NULL) { SDL_iconv_close(cd); return NULL; } @@ -849,7 +849,7 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, char *oldstring = string; stringsize *= 2; string = (char *) SDL_realloc(string, stringsize); - if (!string) { + if (string == NULL) { SDL_free(oldstring); SDL_iconv_close(cd); return NULL; diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 8776c849b8..a589ecc116 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -93,7 +93,7 @@ SDL_ScanLong(const char *text, int count, int radix, long *valuep) *valuep = value; } } - return (text - textstart); + return text - textstart; } #endif @@ -133,7 +133,7 @@ SDL_ScanUnsignedLong(const char *text, int count, int radix, unsigned long *valu if (valuep && text > textstart) { *valuep = value; } - return (text - textstart); + return text - textstart; } #endif @@ -165,7 +165,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) if (valuep && text > textstart) { *valuep = value; } - return (text - textstart); + return text - textstart; } #endif @@ -210,7 +210,7 @@ SDL_ScanLongLong(const char *text, int count, int radix, Sint64 * valuep) *valuep = value; } } - return (text - textstart); + return text - textstart; } #endif @@ -250,7 +250,7 @@ SDL_ScanUnsignedLongLong(const char *text, int count, int radix, Uint64 * valuep if (valuep && text > textstart) { *valuep = value; } - return (text - textstart); + return text - textstart; } #endif @@ -286,7 +286,7 @@ SDL_ScanFloat(const char *text, double *valuep) *valuep = value; } } - return (text - textstart); + return text - textstart; } #endif @@ -335,7 +335,7 @@ SDL_memcmp(const void *s1, const void *s2, size_t len) char *s2p = (char *) s2; while (len--) { if (*s1p != *s2p) { - return (*s1p - *s2p); + return *s1p - *s2p; } ++s1p; ++s2p; @@ -418,7 +418,7 @@ wchar_t * SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle) { #if defined(HAVE_WCSSTR) - return SDL_const_cast(wchar_t*,wcsstr(haystack, needle)); + return SDL_const_cast(wchar_t *, wcsstr(haystack, needle)); #else size_t length = SDL_wcslen(needle); while (*haystack) { @@ -438,8 +438,9 @@ SDL_wcscmp(const wchar_t *str1, const wchar_t *str2) return wcscmp(str1, str2); #else while (*str1 && *str2) { - if (*str1 != *str2) + if (*str1 != *str2) { break; + } ++str1; ++str2; } @@ -454,8 +455,9 @@ SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen) return wcsncmp(str1, str2, maxlen); #else while (*str1 && *str2 && maxlen) { - if (*str1 != *str2) + if (*str1 != *str2) { break; + } ++str1; ++str2; --maxlen; @@ -463,7 +465,7 @@ SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen) if (!maxlen) { return 0; } - return (int) (*str1 - *str2); + return (int)(*str1 - *str2); #endif /* HAVE_WCSNCMP */ } @@ -487,8 +489,9 @@ SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2) a = SDL_toupper((unsigned char) *str1); b = SDL_toupper((unsigned char) *str2); } - if (a != b) + if (a != b) { break; + } ++str1; ++str2; } @@ -501,7 +504,7 @@ SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2) a = SDL_toupper((unsigned char) *str1); b = SDL_toupper((unsigned char) *str2); } - return (int) ((unsigned int) a - (unsigned int) b); + return (int)((unsigned int)a - (unsigned int)b); #endif /* HAVE__WCSICMP */ } @@ -524,8 +527,9 @@ SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen) a = SDL_toupper((unsigned char) *str1); b = SDL_toupper((unsigned char) *str2); } - if (a != b) + if (a != b) { break; + } ++str1; ++str2; --maxlen; @@ -542,7 +546,7 @@ SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen) a = SDL_toupper((unsigned char) *str1); b = SDL_toupper((unsigned char) *str2); } - return (int) ((unsigned int) a - (unsigned int) b); + return (int)((unsigned int)a - (unsigned int)b); } #endif /* HAVE__WCSNICMP */ } @@ -580,8 +584,9 @@ SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_ c = (unsigned char)src[i]; trailing_bytes = UTF8_TrailingBytes(c); if (trailing_bytes) { - if (bytes - i != trailing_bytes + 1) + if (bytes - i != trailing_bytes + 1) { bytes = i; + } break; } @@ -707,18 +712,18 @@ char * SDL_strchr(const char *string, int c) { #ifdef HAVE_STRCHR - return SDL_const_cast(char*,strchr(string, c)); + return SDL_const_cast(char *, strchr(string, c)); #elif defined(HAVE_INDEX) - return SDL_const_cast(char*,index(string, c)); + return SDL_const_cast(char *, index(string, c)); #else while (*string) { if (*string == c) { - return (char *) string; + return (char *)string; } ++string; } if (c == '\0') { - return (char *) string; + return (char *)string; } return NULL; #endif /* HAVE_STRCHR */ @@ -728,14 +733,14 @@ char * SDL_strrchr(const char *string, int c) { #ifdef HAVE_STRRCHR - return SDL_const_cast(char*,strrchr(string, c)); + return SDL_const_cast(char *, strrchr(string, c)); #elif defined(HAVE_RINDEX) - return SDL_const_cast(char*,rindex(string, c)); + return SDL_const_cast(char *, rindex(string, c)); #else const char *bufp = string + SDL_strlen(string); while (bufp >= string) { if (*bufp == c) { - return (char *) bufp; + return (char *)bufp; } --bufp; } @@ -747,12 +752,12 @@ char * SDL_strstr(const char *haystack, const char *needle) { #if defined(HAVE_STRSTR) - return SDL_const_cast(char*,strstr(haystack, needle)); + return SDL_const_cast(char *, strstr(haystack, needle)); #else size_t length = SDL_strlen(needle); while (*haystack) { if (SDL_strncmp(haystack, needle, length) == 0) { - return (char *) haystack; + return (char *)haystack; } ++haystack; } @@ -764,12 +769,12 @@ char * SDL_strcasestr(const char *haystack, const char *needle) { #if defined(HAVE_STRCASESTR) - return SDL_const_cast(char*,strcasestr(haystack, needle)); + return SDL_const_cast(char *, strcasestr(haystack, needle)); #else size_t length = SDL_strlen(needle); while (*haystack) { if (SDL_strncasecmp(haystack, needle, length) == 0) { - return (char *) haystack; + return (char *)haystack; } ++haystack; } @@ -1038,10 +1043,11 @@ SDL_strcmp(const char *str1, const char *str2) #else int result; - while(1) { + while (1) { result = (int)((unsigned char) *str1 - (unsigned char) *str2); - if (result != 0 || (*str1 == '\0'/* && *str2 == '\0'*/)) + if (result != 0 || (*str1 == '\0'/* && *str2 == '\0'*/)) { break; + } ++str1; ++str2; } @@ -1059,8 +1065,9 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen) while (maxlen) { result = (int) (unsigned char) *str1 - (unsigned char) *str2; - if (result != 0 || *str1 == '\0'/* && *str2 == '\0'*/) + if (result != 0 || *str1 == '\0'/* && *str2 == '\0'*/) { break; + } ++str1; ++str2; --maxlen; @@ -1086,8 +1093,9 @@ SDL_strcasecmp(const char *str1, const char *str2) a = SDL_toupper((unsigned char) *str1); b = SDL_toupper((unsigned char) *str2); result = a - b; - if (result != 0 || a == 0 /*&& b == 0*/) + if (result != 0 || a == 0 /*&& b == 0*/) { break; + } ++str1; ++str2; } @@ -1109,14 +1117,16 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) a = SDL_tolower((unsigned char) *str1); b = SDL_tolower((unsigned char) *str2); result = a - b; - if (result != 0 || a == 0 /*&& b == 0*/) + if (result != 0 || a == 0 /*&& b == 0*/) { break; + } ++str1; ++str2; --maxlen; } - if (maxlen == 0) + if (maxlen == 0) { result = 0; + } return result; #endif /* HAVE_STRNCASECMP */ } @@ -1144,7 +1154,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap) { int retval = 0; - if (!text || !*text) { + if (text == NULL || !*text) { return -1; } @@ -1455,10 +1465,16 @@ SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap) { int retval; - if (!fmt) fmt = ""; + if (!fmt) { + fmt = ""; + } retval = _vsnprintf(text, maxlen, fmt, ap); - if (maxlen > 0) text[maxlen-1] = '\0'; - if (retval < 0) retval = (int) maxlen; + if (maxlen > 0) { + text[maxlen - 1] = '\0'; + } + if (retval < 0) { + retval = (int)maxlen; + } return retval; } #elif defined(HAVE_VSNPRINTF) @@ -1508,8 +1524,9 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str size_t width = info->width - sz; size_t filllen; - if (info->precision >= 0 && (size_t)info->precision < sz) + if (info->precision >= 0 && (size_t)info->precision < sz) { width += sz - (size_t)info->precision; + } filllen = SDL_min(width, maxlen); SDL_memset(text, fill, filllen); @@ -1545,8 +1562,9 @@ SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) {/* left-pad num with zeroes. */ size_t sz, pad, have_sign; - if (!info) + if (info == NULL) { return; + } have_sign = 0; if (*num == '-' || *num == '+') { @@ -1732,8 +1750,7 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, if (*fmt >= '0' && *fmt <= '9') { info.width = SDL_strtol(fmt, (char **)&fmt, 0); - } - else if (*fmt == '*') { + } else if (*fmt == '*') { ++fmt; info.width = va_arg(ap, int); } @@ -1933,8 +1950,9 @@ SDL_vasprintf(char **strp, const char *fmt, va_list ap) *strp = NULL; p = (char *)SDL_malloc(size); - if (p == NULL) + if (p == NULL) { return -1; + } while (1) { /* Try to print in the allocated space */ @@ -1943,8 +1961,9 @@ SDL_vasprintf(char **strp, const char *fmt, va_list ap) va_end(aq); /* Check error code */ - if (retval < 0) + if (retval < 0) { return retval; + } /* If that worked, return the string */ if (retval < size) { diff --git a/src/test/SDL_test_assert.c b/src/test/SDL_test_assert.c index ec0be9b30f..0b7cc3e6b3 100644 --- a/src/test/SDL_test_assert.c +++ b/src/test/SDL_test_assert.c @@ -71,13 +71,10 @@ int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char va_end(list); /* Log pass or fail message */ - if (assertCondition == ASSERT_FAIL) - { + if (assertCondition == ASSERT_FAIL) { SDLTest_AssertsFailed++; SDLTest_LogError(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Failed"); - } - else - { + } else { SDLTest_AssertsPassed++; SDLTest_Log(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Passed"); } @@ -120,12 +117,9 @@ void SDLTest_ResetAssertSummary() void SDLTest_LogAssertSummary() { int totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed; - if (SDLTest_AssertsFailed == 0) - { + if (SDLTest_AssertsFailed == 0) { SDLTest_Log(SDLTEST_ASSERT_SUMMARY_FORMAT, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed); - } - else - { + } else { SDLTest_LogError(SDLTEST_ASSERT_SUMMARY_FORMAT, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed); } } diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 54ba5d8212..c2ef00254a 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -69,7 +69,7 @@ SDLTest_CommonCreateState(char **argv, Uint32 flags) } state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state)); - if (!state) { + if (state == NULL) { SDL_OutOfMemory(); return NULL; } @@ -112,6 +112,16 @@ SDLTest_CommonCreateState(char **argv, Uint32 flags) return state; } +#define SEARCHARG(dim) \ + while (*dim && *dim != ',') { \ + ++dim; \ + } \ + if (!*dim) { \ + return -1; \ + } \ + *dim++ = '\0'; + + int SDLTest_CommonArg(SDLTest_CommonState * state, int index) { @@ -305,20 +315,11 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index) } x = argv[index]; y = argv[index]; - #define SEARCHARG(dim) \ - while (*dim && *dim != ',') { \ - ++dim; \ - } \ - if (!*dim) { \ - return -1; \ - } \ - *dim++ = '\0'; SEARCHARG(y) w = y; SEARCHARG(w) h = w; SEARCHARG(h) - #undef SEARCHARG state->confine.x = SDL_atoi(x); state->confine.y = SDL_atoi(y); state->confine.w = SDL_atoi(w); @@ -592,7 +593,7 @@ static const char * BuildCommonUsageString(char **pstr, const char **strlist, const int numitems, const char **strlist2, const int numitems2) { char *str = *pstr; - if (!str) { + if (str == NULL) { size_t len = SDL_strlen("[--trackmem]") + 2; int i; for (i = 0; i < numitems; i++) { @@ -604,7 +605,7 @@ BuildCommonUsageString(char **pstr, const char **strlist, const int numitems, co } } str = (char *) SDL_calloc(1, len); - if (!str) { + if (str == NULL) { return ""; /* oh well. */ } SDL_strlcat(str, "[--trackmem] ", len); @@ -1005,7 +1006,7 @@ SDLTest_LoadIcon(const char *file) icon = SDL_LoadBMP(file); if (icon == NULL) { SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError()); - return (NULL); + return NULL; } if (icon->format->palette) { @@ -1013,7 +1014,7 @@ SDLTest_LoadIcon(const char *file) SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels)); } - return (icon); + return icon; } static SDL_HitTestResult SDLCALL @@ -1165,8 +1166,9 @@ SDLTest_CommonInit(SDLTest_CommonState * state) SDL_Log(" Red Mask = 0x%.8" SDL_PRIx32 "\n", Rmask); SDL_Log(" Green Mask = 0x%.8" SDL_PRIx32 "\n", Gmask); SDL_Log(" Blue Mask = 0x%.8" SDL_PRIx32 "\n", Bmask); - if (Amask) + if (Amask) { SDL_Log(" Alpha Mask = 0x%.8" SDL_PRIx32 "\n", Amask); + } } /* Print available fullscreen video modes */ @@ -1189,9 +1191,9 @@ SDLTest_CommonInit(SDLTest_CommonState * state) Gmask); SDL_Log(" Blue Mask = 0x%.8" SDL_PRIx32 "\n", Bmask); - if (Amask) - SDL_Log(" Alpha Mask = 0x%.8" SDL_PRIx32 "\n", - Amask); + if (Amask) { + SDL_Log(" Alpha Mask = 0x%.8" SDL_PRIx32 "\n", Amask); + } } } } @@ -1759,7 +1761,7 @@ SDLTest_ScreenShot(SDL_Renderer *renderer) SDL_Rect viewport; SDL_Surface *surface; - if (!renderer) { + if (renderer == NULL) { return; } @@ -1771,7 +1773,7 @@ SDLTest_ScreenShot(SDL_Renderer *renderer) 0x000000FF, 0x0000FF00, 0x00FF0000, #endif 0x00000000); - if (!surface) { + if (surface == NULL) { SDL_Log("Couldn't create surface: %s\n", SDL_GetError()); return; } @@ -1796,7 +1798,7 @@ FullscreenTo(int index, int windowId) Uint32 flags; struct SDL_Rect rect = { 0, 0, 0, 0 }; SDL_Window *window = SDL_GetWindowFromID(windowId); - if (!window) { + if (window == NULL) { return; } @@ -1936,10 +1938,18 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done) int x, y; SDL_GetWindowPosition(window, &x, &y); - if (event->key.keysym.sym == SDLK_UP) y -= delta; - if (event->key.keysym.sym == SDLK_DOWN) y += delta; - if (event->key.keysym.sym == SDLK_LEFT) x -= delta; - if (event->key.keysym.sym == SDLK_RIGHT) x += delta; + if (event->key.keysym.sym == SDLK_UP) { + y -= delta; + } + if (event->key.keysym.sym == SDLK_DOWN) { + y += delta; + } + if (event->key.keysym.sym == SDLK_LEFT) { + x -= delta; + } + if (event->key.keysym.sym == SDLK_RIGHT) { + x += delta; + } SDL_Log("Setting position to (%d, %d)\n", x, y); SDL_SetWindowPosition(window, x, y); diff --git a/src/test/SDL_test_font.c b/src/test/SDL_test_font.c index db20d343d6..6884f827c7 100644 --- a/src/test/SDL_test_font.c +++ b/src/test/SDL_test_font.c @@ -3189,7 +3189,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c) charWidth, charHeight, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); if (character == NULL) { - return (-1); + return -1; } charpos = SDLTest_FontData + ci * charSize; @@ -3222,7 +3222,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c) * Check pointer */ if (cache->charTextureCache[ci] == NULL) { - return (-1); + return -1; } } @@ -3239,7 +3239,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c) */ result |= SDL_RenderCopy(renderer, cache->charTextureCache[ci], &srect, &drect); - return (result); + return result; } /* Gets a unicode value from a UTF-8 encoded string @@ -3350,14 +3350,14 @@ int SDLTest_DrawString(SDL_Renderer * renderer, int x, int y, const char *s) len -= advance; } - return (result); + return result; } SDLTest_TextWindow *SDLTest_TextWindowCreate(int x, int y, int w, int h) { SDLTest_TextWindow *textwin = (SDLTest_TextWindow *)SDL_malloc(sizeof(*textwin)); - if ( !textwin ) { + if (textwin == NULL) { return NULL; } @@ -3451,8 +3451,7 @@ void SDLTest_TextWindowClear(SDLTest_TextWindow *textwin) { int i; - for ( i = 0; i < textwin->numlines; ++i ) - { + for ( i = 0; i < textwin->numlines; ++i ) { if ( textwin->lines[i] ) { SDL_free(textwin->lines[i]); textwin->lines[i] = NULL; diff --git a/src/test/SDL_test_fuzzer.c b/src/test/SDL_test_fuzzer.c index 310df4c7e1..8cfdf7bbec 100644 --- a/src/test/SDL_test_fuzzer.c +++ b/src/test/SDL_test_fuzzer.c @@ -151,11 +151,11 @@ SDLTest_RandomIntegerInRange(Sint32 pMin, Sint32 pMax) Sint64 temp; Sint64 number; - if(pMin > pMax) { + if (pMin > pMax) { temp = min; min = max; max = temp; - } else if(pMin == pMax) { + } else if (pMin == pMax) { return (Sint32)min; } @@ -477,7 +477,7 @@ SDLTest_RandomAsciiStringWithMaximumLength(int maxLength) { int size; - if(maxLength < 1) { + if (maxLength < 1) { SDL_InvalidParamError("maxLength"); return NULL; } @@ -494,7 +494,7 @@ SDLTest_RandomAsciiStringOfSize(int size) int counter; - if(size < 1) { + if (size < 1) { SDL_InvalidParamError("size"); return NULL; } @@ -504,7 +504,7 @@ SDLTest_RandomAsciiStringOfSize(int size) return NULL; } - for(counter = 0; counter < size; ++counter) { + for (counter = 0; counter < size; ++counter) { string[counter] = (char)SDLTest_RandomIntegerInRange(32, 126); } diff --git a/src/test/SDL_test_harness.c b/src/test/SDL_test_harness.c index cb5dd31bc6..6f69106fd0 100644 --- a/src/test/SDL_test_harness.c +++ b/src/test/SDL_test_harness.c @@ -228,14 +228,12 @@ SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseRef int testResult = 0; int fuzzerCount; - if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL) - { + if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL) { SDLTest_LogError("Setup failure: testSuite or testCase references NULL"); return TEST_RESULT_SETUP_FAILURE; } - if (!testCase->enabled && forceTestRun == SDL_FALSE) - { + if (!testCase->enabled && forceTestRun == SDL_FALSE) { SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Skipped (Disabled)"); return TEST_RESULT_SKIPPED; } @@ -320,7 +318,7 @@ static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites) /* Loop over all suites */ suiteCounter = 0; - while(&testSuites[suiteCounter]) { + while (&testSuites[suiteCounter]) { testSuite=&testSuites[suiteCounter]; suiteCounter++; SDLTest_Log("Test Suite %i - %s\n", suiteCounter, @@ -328,8 +326,7 @@ static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites) /* Loop over all test cases */ testCounter = 0; - while(testSuite->testCases[testCounter]) - { + while (testSuite->testCases[testCounter]) { testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter]; testCounter++; SDLTest_Log(" Test Case %i - %s: %s", testCounter, @@ -430,8 +427,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user testSuite = testSuites[suiteCounter]; suiteCounter++; testCounter = 0; - while (testSuite->testCases[testCounter]) - { + while (testSuite->testCases[testCounter]) { testCounter++; totalNumberOfTests++; } @@ -504,7 +500,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user /* Loop over all suites */ suiteCounter = 0; - while(testSuites[suiteCounter]) { + while (testSuites[suiteCounter]) { testSuite = testSuites[suiteCounter]; currentSuiteName = (testSuite->name ? testSuite->name : SDLTEST_INVALID_NAME_FORMAT); suiteCounter++; @@ -533,8 +529,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user /* Loop over all test cases */ testCounter = 0; - while(testSuite->testCases[testCounter]) - { + while (testSuite->testCases[testCounter]) { testCase = testSuite->testCases[testCounter]; currentTestName = (testCase->name ? testCase->name : SDLTEST_INVALID_NAME_FORMAT); testCounter++; @@ -569,8 +564,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user /* Loop over all iterations */ iterationCounter = 0; - while(iterationCounter < testIterations) - { + while (iterationCounter < testIterations) { iterationCounter++; if (userExecKey != 0) { @@ -597,7 +591,9 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user /* Take time - test end */ testEndSeconds = GetClock(); runtime = testEndSeconds - testStartSeconds; - if (runtime < 0.0f) runtime = 0.0f; + if (runtime < 0.0f) { + runtime = 0.0f; + } if (testIterations > 1) { /* Log test runtime */ @@ -632,20 +628,19 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user /* Take time - suite end */ suiteEndSeconds = GetClock(); runtime = suiteEndSeconds - suiteStartSeconds; - if (runtime < 0.0f) runtime = 0.0f; + if (runtime < 0.0f) { + runtime = 0.0f; + } /* Log suite runtime */ SDLTest_Log("Total Suite runtime: %.1f sec", runtime); /* Log summary and final Suite result */ countSum = testPassedCount + testFailedCount + testSkippedCount; - if (testFailedCount == 0) - { + if (testFailedCount == 0) { SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount); SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Passed"); - } - else - { + } else { SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount); SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Failed"); } @@ -656,21 +651,20 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user /* Take time - run end */ runEndSeconds = GetClock(); runtime = runEndSeconds - runStartSeconds; - if (runtime < 0.0f) runtime = 0.0f; + if (runtime < 0.0f) { + runtime = 0.0f; + } /* Log total runtime */ SDLTest_Log("Total Run runtime: %.1f sec", runtime); /* Log summary and final run result */ countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount; - if (totalTestFailedCount == 0) - { + if (totalTestFailedCount == 0) { runResult = 0; SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount); SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Passed"); - } - else - { + } else { runResult = 1; SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount); SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Failed"); diff --git a/src/test/SDL_test_md5.c b/src/test/SDL_test_md5.c index 0654059b81..18948408e8 100644 --- a/src/test/SDL_test_md5.c +++ b/src/test/SDL_test_md5.c @@ -106,7 +106,9 @@ static unsigned char MD5PADDING[64] = { void SDLTest_Md5Init(SDLTest_Md5Context * mdContext) { - if (mdContext==NULL) return; + if (mdContext == NULL) { + return; + } mdContext->i[0] = mdContext->i[1] = (MD5UINT4) 0; @@ -132,8 +134,12 @@ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf, int mdi; unsigned int i, ii; - if (mdContext == NULL) return; - if (inBuf == NULL || inLen < 1) return; + if (mdContext == NULL) { + return; + } + if (inBuf == NULL || inLen < 1) { + return; + } /* * compute number of bytes mod 64 @@ -143,8 +149,9 @@ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf, /* * update number of bits */ - if ((mdContext->i[0] + ((MD5UINT4) inLen << 3)) < mdContext->i[0]) + if ((mdContext->i[0] + ((MD5UINT4)inLen << 3)) < mdContext->i[0]) { mdContext->i[1]++; + } mdContext->i[0] += ((MD5UINT4) inLen << 3); mdContext->i[1] += ((MD5UINT4) inLen >> 29); @@ -158,11 +165,9 @@ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf, * transform if necessary */ if (mdi == 0x40) { - for (i = 0, ii = 0; i < 16; i++, ii += 4) - in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) | - (((MD5UINT4) mdContext->in[ii + 2]) << 16) | - (((MD5UINT4) mdContext->in[ii + 1]) << 8) | - ((MD5UINT4) mdContext->in[ii]); + for (i = 0, ii = 0; i < 16; i++, ii += 4) { + in[i] = (((MD5UINT4)mdContext->in[ii + 3]) << 24) | (((MD5UINT4)mdContext->in[ii + 2]) << 16) | (((MD5UINT4)mdContext->in[ii + 1]) << 8) | ((MD5UINT4)mdContext->in[ii]); + } SDLTest_Md5Transform(mdContext->buf, in); mdi = 0; } @@ -181,7 +186,9 @@ void SDLTest_Md5Final(SDLTest_Md5Context * mdContext) unsigned int i, ii; unsigned int padLen; - if (mdContext == NULL) return; + if (mdContext == NULL) { + return; + } /* * save number of bits @@ -203,11 +210,9 @@ void SDLTest_Md5Final(SDLTest_Md5Context * mdContext) /* * append length in bits and transform */ - for (i = 0, ii = 0; i < 14; i++, ii += 4) - in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) | - (((MD5UINT4) mdContext->in[ii + 2]) << 16) | - (((MD5UINT4) mdContext->in[ii + 1]) << 8) | - ((MD5UINT4) mdContext->in[ii]); + for (i = 0, ii = 0; i < 14; i++, ii += 4) { + in[i] = (((MD5UINT4)mdContext->in[ii + 3]) << 24) | (((MD5UINT4)mdContext->in[ii + 2]) << 16) | (((MD5UINT4)mdContext->in[ii + 1]) << 8) | ((MD5UINT4)mdContext->in[ii]); + } SDLTest_Md5Transform(mdContext->buf, in); /* diff --git a/src/test/SDL_test_memory.c b/src/test/SDL_test_memory.c index 6ecb76d4c4..e9f8d35bdd 100644 --- a/src/test/SDL_test_memory.c +++ b/src/test/SDL_test_memory.c @@ -79,7 +79,7 @@ static void SDL_TrackAllocation(void *mem, size_t size) return; } entry = (SDL_tracked_allocation *)SDL_malloc_orig(sizeof(*entry)); - if (!entry) { + if (entry == NULL) { return; } entry->mem = mem; @@ -166,7 +166,7 @@ static void * SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size) { void *mem; - SDL_assert(!ptr || SDL_IsAllocationTracked(ptr)); + SDL_assert(ptr == NULL || SDL_IsAllocationTracked(ptr)); mem = SDL_realloc_orig(ptr, size); if (mem && mem != ptr) { if (ptr) { @@ -179,7 +179,7 @@ static void * SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size) static void SDLCALL SDLTest_TrackedFree(void *ptr) { - if (!ptr) { + if (ptr == NULL) { return; } diff --git a/src/test/SDL_test_random.c b/src/test/SDL_test_random.c index 5d43c8438b..87c5726c85 100644 --- a/src/test/SDL_test_random.c +++ b/src/test/SDL_test_random.c @@ -36,7 +36,9 @@ void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, unsigned int ci) { - if (rndContext==NULL) return; + if (rndContext == NULL) { + return; + } /* * Choose a value for 'a' from this list @@ -62,7 +64,9 @@ void SDLTest_RandomInitTime(SDLTest_RandomContext * rndContext) { int a, b; - if (rndContext==NULL) return; + if (rndContext == NULL) { + return; + } srand((unsigned int)time(NULL)); a=rand(); @@ -77,7 +81,9 @@ unsigned int SDLTest_Random(SDLTest_RandomContext * rndContext) { unsigned int xh, xl; - if (rndContext==NULL) return -1; + if (rndContext == NULL) { + return -1; + } xh = rndContext->x >> 16; xl = rndContext->x & 65535; @@ -85,9 +91,10 @@ unsigned int SDLTest_Random(SDLTest_RandomContext * rndContext) rndContext->c = xh * rndContext->ah + ((xh * rndContext->al) >> 16) + ((xl * rndContext->ah) >> 16); - if (xl * rndContext->al >= (~rndContext->c + 1)) + if (xl * rndContext->al >= (~rndContext->c + 1)) { rndContext->c++; - return (rndContext->x); + } + return rndContext->x; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index b695fa4d5d..de59186b57 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -40,7 +40,7 @@ SDL_TLSGet(SDL_TLSID id) SDL_TLSData *storage; storage = SDL_SYS_GetTLSData(); - if (!storage || id == 0 || id > storage->limit) { + if (storage == NULL || id == 0 || id > storage->limit) { return NULL; } return storage->array[id-1].data; @@ -56,13 +56,13 @@ SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void *)) } storage = SDL_SYS_GetTLSData(); - if (!storage || (id > storage->limit)) { + if (storage == NULL || (id > storage->limit)) { unsigned int i, oldlimit, newlimit; oldlimit = storage ? storage->limit : 0; newlimit = (id + TLS_ALLOC_CHUNKSIZE); storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage)+(newlimit-1)*sizeof(storage->array[0])); - if (!storage) { + if (storage == NULL) { return SDL_OutOfMemory(); } storage->limit = newlimit; @@ -125,14 +125,14 @@ SDL_Generic_GetTLSData(void) SDL_TLSData *storage = NULL; #if !SDL_THREADS_DISABLED - if (!SDL_generic_TLS_mutex) { + if (SDL_generic_TLS_mutex == NULL) { static SDL_SpinLock tls_lock; SDL_AtomicLock(&tls_lock); - if (!SDL_generic_TLS_mutex) { + if (SDL_generic_TLS_mutex == NULL) { SDL_mutex *mutex = SDL_CreateMutex(); SDL_MemoryBarrierRelease(); SDL_generic_TLS_mutex = mutex; - if (!SDL_generic_TLS_mutex) { + if (SDL_generic_TLS_mutex == NULL) { SDL_AtomicUnlock(&tls_lock); return NULL; } @@ -181,7 +181,7 @@ SDL_Generic_SetTLSData(SDL_TLSData *storage) } prev = entry; } - if (!entry) { + if (entry == NULL) { entry = (SDL_TLSEntry *)SDL_malloc(sizeof(*entry)); if (entry) { entry->thread = thread; @@ -192,7 +192,7 @@ SDL_Generic_SetTLSData(SDL_TLSData *storage) } SDL_UnlockMutex(SDL_generic_TLS_mutex); - if (!entry) { + if (entry == NULL) { return SDL_OutOfMemory(); } return 0; @@ -260,7 +260,7 @@ SDL_GetErrBuf(void) if (errbuf == ALLOCATION_IN_PROGRESS) { return SDL_GetStaticErrBuf(); } - if (!errbuf) { + if (errbuf == NULL) { /* Get the original memory functions for this allocation because the lifetime * of the error buffer may span calls to SDL_SetMemoryFunctions() by the app */ @@ -271,7 +271,7 @@ SDL_GetErrBuf(void) /* Mark that we're in the middle of allocating our buffer */ SDL_TLSSet(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL); errbuf = (SDL_error *)realloc_func(NULL, sizeof(*errbuf)); - if (!errbuf) { + if (errbuf == NULL) { SDL_TLSSet(tls_errbuf, NULL, NULL); return SDL_GetStaticErrBuf(); } @@ -472,7 +472,7 @@ SDL_WaitThread(SDL_Thread * thread, int *status) void SDL_DetachThread(SDL_Thread * thread) { - if (!thread) { + if (thread == NULL) { return; } diff --git a/src/thread/generic/SDL_syscond.c b/src/thread/generic/SDL_syscond.c index 91c4552214..d10c207740 100644 --- a/src/thread/generic/SDL_syscond.c +++ b/src/thread/generic/SDL_syscond.c @@ -97,7 +97,7 @@ int SDL_CondSignal_generic(SDL_cond * _cond) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -122,7 +122,7 @@ int SDL_CondBroadcast_generic(SDL_cond * _cond) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -179,7 +179,7 @@ SDL_CondWaitTimeout_generic(SDL_cond * _cond, SDL_mutex * mutex, Uint32 ms) SDL_cond_generic *cond = (SDL_cond_generic *)_cond; int retval; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } diff --git a/src/thread/generic/SDL_syssem.c b/src/thread/generic/SDL_syssem.c index 049e485cd4..50ebd0e74c 100644 --- a/src/thread/generic/SDL_syssem.c +++ b/src/thread/generic/SDL_syssem.c @@ -85,7 +85,7 @@ SDL_CreateSemaphore(Uint32 initial_value) SDL_sem *sem; sem = (SDL_sem *) SDL_malloc(sizeof(*sem)); - if (!sem) { + if (sem == NULL) { SDL_OutOfMemory(); return NULL; } @@ -129,7 +129,7 @@ SDL_SemTryWait(SDL_sem * sem) { int retval; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -149,7 +149,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { int retval; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -197,7 +197,7 @@ SDL_SemValue(SDL_sem * sem) int SDL_SemPost(SDL_sem * sem) { - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } diff --git a/src/thread/generic/SDL_systhread.c b/src/thread/generic/SDL_systhread.c index 78be410a5f..befbd07e5d 100644 --- a/src/thread/generic/SDL_systhread.c +++ b/src/thread/generic/SDL_systhread.c @@ -46,13 +46,13 @@ SDL_SYS_SetupThread(const char *name) SDL_threadID SDL_ThreadID(void) { - return (0); + return 0; } int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { - return (0); + return 0; } void diff --git a/src/thread/n3ds/SDL_syscond.c b/src/thread/n3ds/SDL_syscond.c index eb56eea0e2..e825d6af07 100644 --- a/src/thread/n3ds/SDL_syscond.c +++ b/src/thread/n3ds/SDL_syscond.c @@ -57,7 +57,7 @@ SDL_DestroyCond(SDL_cond *cond) int SDL_CondSignal(SDL_cond *cond) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -69,7 +69,7 @@ SDL_CondSignal(SDL_cond *cond) int SDL_CondBroadcast(SDL_cond *cond) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -103,10 +103,10 @@ SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) { Result res; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } - if (!mutex) { + if (mutex == NULL) { return SDL_InvalidParamError("mutex"); } diff --git a/src/thread/n3ds/SDL_syssem.c b/src/thread/n3ds/SDL_syssem.c index d90ec57ce0..4bee6563a6 100644 --- a/src/thread/n3ds/SDL_syssem.c +++ b/src/thread/n3ds/SDL_syssem.c @@ -43,7 +43,7 @@ SDL_CreateSemaphore(Uint32 initial_value) } sem = (SDL_sem *) SDL_malloc(sizeof(*sem)); - if (!sem) { + if (sem == NULL) { SDL_OutOfMemory(); return NULL; } @@ -67,7 +67,7 @@ SDL_DestroySemaphore(SDL_sem *sem) int SDL_SemTryWait(SDL_sem *sem) { - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -79,7 +79,7 @@ SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) { int retval; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -112,7 +112,7 @@ SDL_SemWait(SDL_sem *sem) Uint32 SDL_SemValue(SDL_sem *sem) { - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } return sem->semaphore.current_count; @@ -121,7 +121,7 @@ SDL_SemValue(SDL_sem *sem) int SDL_SemPost(SDL_sem *sem) { - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } LightSemaphore_Release(&sem->semaphore, 1); diff --git a/src/thread/ngage/SDL_sysmutex.cpp b/src/thread/ngage/SDL_sysmutex.cpp index e2ce86376e..3f0dd0d180 100644 --- a/src/thread/ngage/SDL_sysmutex.cpp +++ b/src/thread/ngage/SDL_sysmutex.cpp @@ -35,7 +35,7 @@ extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, static TInt NewMutex(const TDesC& aName, TAny* aPtr1, TAny*) { - return ((RMutex*)aPtr1)->CreateGlobal(aName); + return ((RMutex *)aPtr1)->CreateGlobal(aName); } /* Create a mutex */ @@ -45,21 +45,19 @@ SDL_CreateMutex(void) RMutex rmutex; TInt status = CreateUnique(NewMutex, &rmutex, NULL); - if(status != KErrNone) - { + if (status != KErrNone) { SDL_SetError("Couldn't create mutex."); } SDL_mutex* mutex = new /*(ELeave)*/ SDL_mutex; mutex->handle = rmutex.Handle(); - return(mutex); + return mutex; } /* Free the mutex */ void SDL_DestroyMutex(SDL_mutex * mutex) { - if (mutex) - { + if (mutex) { RMutex rmutex; rmutex.SetHandle(mutex->handle); rmutex.Signal(); @@ -88,8 +86,7 @@ SDL_TryLockMutex(SDL_mutex * mutex) int SDL_LockMutex(SDL_mutex * mutex) { - if (mutex == NULL) - { + if (mutex == NULL) { return SDL_InvalidParamError("mutex"); } @@ -97,15 +94,14 @@ SDL_LockMutex(SDL_mutex * mutex) rmutex.SetHandle(mutex->handle); rmutex.Wait(); - return(0); + return 0; } /* Unlock the mutex */ int SDL_UnlockMutex(SDL_mutex * mutex) { - if ( mutex == NULL ) - { + if (mutex == NULL) { return SDL_InvalidParamError("mutex"); } @@ -113,7 +109,7 @@ SDL_UnlockMutex(SDL_mutex * mutex) rmutex.SetHandle(mutex->handle); rmutex.Signal(); - return(0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/ngage/SDL_syssem.cpp b/src/thread/ngage/SDL_syssem.cpp index 07612e58be..01fe8bd90a 100644 --- a/src/thread/ngage/SDL_syssem.cpp +++ b/src/thread/ngage/SDL_syssem.cpp @@ -58,18 +58,13 @@ static TBool RunThread(TAny* aInfo) static TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) { - return ((RThread*)(aPtr1))->Create - (aName, - RunThread, - KDefaultStackSize, - NULL, - aPtr2); + return ((RThread *)(aPtr1))->Create(aName, RunThread, KDefaultStackSize, NULL, aPtr2); } static TInt NewSema(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) { TInt value = *((TInt*) aPtr2); - return ((RSemaphore*)aPtr1)->CreateGlobal(aName, value); + return ((RSemaphore *)aPtr1)->CreateGlobal(aName, value); } static void WaitAll(SDL_sem *sem) @@ -77,8 +72,7 @@ static void WaitAll(SDL_sem *sem) RSemaphore sema; sema.SetHandle(sem->handle); sema.Wait(); - while(sem->count < 0) - { + while(sem->count < 0) { sema.Wait(); } } @@ -88,21 +82,19 @@ SDL_CreateSemaphore(Uint32 initial_value) { RSemaphore s; TInt status = CreateUnique(NewSema, &s, &initial_value); - if(status != KErrNone) - { + if (status != KErrNone) { SDL_SetError("Couldn't create semaphore"); } SDL_semaphore* sem = new /*(ELeave)*/ SDL_semaphore; sem->handle = s.Handle(); sem->count = initial_value; - return(sem); + return sem; } void SDL_DestroySemaphore(SDL_sem * sem) { - if (sem) - { + if (sem) { RSemaphore sema; sema.SetHandle(sem->handle); sema.Signal(sema.Count()); @@ -115,13 +107,11 @@ SDL_DestroySemaphore(SDL_sem * sem) int SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { - if (! sem) - { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } - if (timeout == SDL_MUTEX_MAXWAIT) - { + if (timeout == SDL_MUTEX_MAXWAIT) { WaitAll(sem); return SDL_MUTEX_MAXWAIT; } @@ -130,16 +120,14 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) TInfo* info = new (ELeave)TInfo(timeout, sem->handle); TInt status = CreateUnique(NewThread, &thread, info); - if(status != KErrNone) - { + if (status != KErrNone) { return status; } thread.Resume(); WaitAll(sem); - if(thread.ExitType() == EExitPending) - { + if (thread.ExitType() == EExitPending) { thread.Kill(SDL_MUTEX_TIMEOUT); } @@ -150,13 +138,11 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) int SDL_SemTryWait(SDL_sem *sem) { - if (! sem) - { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } - if(sem->count > 0) - { + if (sem->count > 0) { sem->count--; } return SDL_MUTEX_TIMEOUT; @@ -171,8 +157,7 @@ SDL_SemWait(SDL_sem * sem) Uint32 SDL_SemValue(SDL_sem * sem) { - if (! sem) - { + if (sem == NULL) { SDL_InvalidParamError("sem"); return 0; } @@ -182,8 +167,7 @@ SDL_SemValue(SDL_sem * sem) int SDL_SemPost(SDL_sem * sem) { - if (! sem) - { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } sem->count++; diff --git a/src/thread/ngage/SDL_systhread.cpp b/src/thread/ngage/SDL_systhread.cpp index 9d4eecd0a4..e711cb6661 100644 --- a/src/thread/ngage/SDL_systhread.cpp +++ b/src/thread/ngage/SDL_systhread.cpp @@ -38,18 +38,13 @@ static int RunThread(TAny* data) { SDL_RunThread((SDL_Thread*)data); - return(0); + return 0; } static TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) { - return ((RThread*)(aPtr1))->Create - (aName, - RunThread, - KDefaultStackSize, - NULL, - aPtr2); + return ((RThread *)(aPtr1))->Create(aName, RunThread, KDefaultStackSize, NULL, aPtr2); } int @@ -73,17 +68,16 @@ SDL_SYS_CreateThread(SDL_Thread *thread) RThread rthread; TInt status = CreateUnique(NewThread, &rthread, thread); - if (status != KErrNone) - { + if (status != KErrNone) { delete(((RThread*)(thread->handle))); thread->handle = NULL; SDL_SetError("Not enough resources to create thread"); - return(-1); + return -1; } rthread.Resume(); thread->handle = rthread.Handle(); - return(0); + return 0; } void @@ -103,7 +97,7 @@ SDL_ThreadID(void) int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { - return (0); + return 0; } void @@ -111,8 +105,7 @@ SDL_SYS_WaitThread(SDL_Thread * thread) { RThread t; t.Open(thread->threadid); - if(t.ExitReason() == EExitPending) - { + if (t.ExitReason() == EExitPending) { TRequestStatus status; t.Logon(status); User::WaitForRequest(status); diff --git a/src/thread/ps2/SDL_syssem.c b/src/thread/ps2/SDL_syssem.c index a25fb74fa6..37b7f73953 100644 --- a/src/thread/ps2/SDL_syssem.c +++ b/src/thread/ps2/SDL_syssem.c @@ -103,8 +103,9 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) ret = WaitSema(sem->semid); StopTimerAlarm(&alarm); - if (ret < 0) + if (ret < 0) { return SDL_MUTEX_TIMEDOUT; + } return 0; //Wait condition satisfied. } diff --git a/src/thread/psp/SDL_syscond.c b/src/thread/psp/SDL_syscond.c index d89184a358..05db8bed1d 100644 --- a/src/thread/psp/SDL_syscond.c +++ b/src/thread/psp/SDL_syscond.c @@ -57,7 +57,7 @@ SDL_CreateCond(void) } else { SDL_OutOfMemory(); } - return (cond); + return cond; } /* Destroy a condition variable */ @@ -82,7 +82,7 @@ SDL_DestroyCond(SDL_cond * cond) int SDL_CondSignal(SDL_cond * cond) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -106,7 +106,7 @@ SDL_CondSignal(SDL_cond * cond) int SDL_CondBroadcast(SDL_cond * cond) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -162,7 +162,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { int retval; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } diff --git a/src/thread/pthread/SDL_syscond.c b/src/thread/pthread/SDL_syscond.c index fdc338b0bf..5aae6fbd0a 100644 --- a/src/thread/pthread/SDL_syscond.c +++ b/src/thread/pthread/SDL_syscond.c @@ -47,7 +47,7 @@ SDL_CreateCond(void) cond = NULL; } } - return (cond); + return cond; } /* Destroy a condition variable */ @@ -66,7 +66,7 @@ SDL_CondSignal(SDL_cond * cond) { int retval; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -83,7 +83,7 @@ SDL_CondBroadcast(SDL_cond * cond) { int retval; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -103,7 +103,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) #endif struct timespec abstime; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -146,7 +146,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) int SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) { return SDL_SetError("pthread_cond_wait() failed"); diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index 1f936d42f0..a83babe739 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -63,7 +63,7 @@ SDL_CreateMutex(void) } else { SDL_OutOfMemory(); } - return (mutex); + return mutex; } void diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index c189b21b77..c7f78ab0df 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -70,7 +70,7 @@ SDL_SemTryWait(SDL_sem * sem) { int retval; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } retval = SDL_MUTEX_TIMEDOUT; @@ -85,7 +85,7 @@ SDL_SemWait(SDL_sem * sem) { int retval; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -112,7 +112,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) Uint32 end; #endif - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -196,7 +196,7 @@ SDL_SemPost(SDL_sem * sem) { int retval; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index f4f2e70ccf..5fe6ef30e4 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -176,7 +176,7 @@ SDL_SYS_SetupThread(const char *name) SDL_threadID SDL_ThreadID(void) { - return ((SDL_threadID) pthread_self()); + return (SDL_threadID)pthread_self(); } int diff --git a/src/thread/stdcpp/SDL_syscond.cpp b/src/thread/stdcpp/SDL_syscond.cpp index c41ef5360d..d49198a646 100644 --- a/src/thread/stdcpp/SDL_syscond.cpp +++ b/src/thread/stdcpp/SDL_syscond.cpp @@ -68,7 +68,7 @@ extern "C" int SDL_CondSignal(SDL_cond * cond) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -81,7 +81,7 @@ extern "C" int SDL_CondBroadcast(SDL_cond * cond) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -131,7 +131,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) cpp_lock.release(); return 0; } else { - auto wait_result = cond->cpp_cond.wait_for( + auto wait_result = cond->cpp_cond.wait_for ( cpp_lock, std::chrono::duration(ms) ); diff --git a/src/thread/stdcpp/SDL_systhread.cpp b/src/thread/stdcpp/SDL_systhread.cpp index 89865f632f..26a0a05e44 100644 --- a/src/thread/stdcpp/SDL_systhread.cpp +++ b/src/thread/stdcpp/SDL_systhread.cpp @@ -97,16 +97,13 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) if (priority == SDL_THREAD_PRIORITY_LOW) { value = THREAD_PRIORITY_LOWEST; - } - else if (priority == SDL_THREAD_PRIORITY_HIGH) { + } else if (priority == SDL_THREAD_PRIORITY_HIGH) { value = THREAD_PRIORITY_HIGHEST; - } - else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) { + } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) { // FIXME: WinRT does not support TIME_CRITICAL! -flibit SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "TIME_CRITICAL unsupported, falling back to HIGHEST"); value = THREAD_PRIORITY_HIGHEST; - } - else { + } else { value = THREAD_PRIORITY_NORMAL; } if (!SetThreadPriority(GetCurrentThread(), value)) { diff --git a/src/thread/vita/SDL_syscond.c b/src/thread/vita/SDL_syscond.c index 25f6774377..b37195477a 100644 --- a/src/thread/vita/SDL_syscond.c +++ b/src/thread/vita/SDL_syscond.c @@ -57,7 +57,7 @@ SDL_CreateCond(void) } else { SDL_OutOfMemory(); } - return (cond); + return cond; } /* Destroy a condition variable */ @@ -82,7 +82,7 @@ SDL_DestroyCond(SDL_cond * cond) int SDL_CondSignal(SDL_cond * cond) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -106,7 +106,7 @@ SDL_CondSignal(SDL_cond * cond) int SDL_CondBroadcast(SDL_cond * cond) { - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -162,7 +162,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { int retval; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } diff --git a/src/thread/windows/SDL_syscond_cv.c b/src/thread/windows/SDL_syscond_cv.c index 152cdd2c55..0bac17d551 100644 --- a/src/thread/windows/SDL_syscond_cv.c +++ b/src/thread/windows/SDL_syscond_cv.c @@ -86,7 +86,7 @@ SDL_CreateCond_cv(void) /* Relies on CONDITION_VARIABLE_INIT == 0. */ cond = (SDL_cond_cv *) SDL_calloc(1, sizeof(*cond)); - if (!cond) { + if (cond == NULL) { SDL_OutOfMemory(); } @@ -106,7 +106,7 @@ static int SDL_CondSignal_cv(SDL_cond * _cond) { SDL_cond_cv *cond = (SDL_cond_cv *)_cond; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -119,7 +119,7 @@ static int SDL_CondBroadcast_cv(SDL_cond * _cond) { SDL_cond_cv *cond = (SDL_cond_cv *)_cond; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } @@ -135,10 +135,10 @@ SDL_CondWaitTimeout_cv(SDL_cond * _cond, SDL_mutex * _mutex, Uint32 ms) DWORD timeout; int ret; - if (!cond) { + if (cond == NULL) { return SDL_InvalidParamError("cond"); } - if (!_mutex) { + if (_mutex == NULL) { return SDL_InvalidParamError("mutex"); } @@ -232,7 +232,7 @@ SDL_CreateCond(void) if (SDL_mutex_impl_active.Type == SDL_MUTEX_INVALID) { /* The mutex implementation isn't decided yet, trigger it */ SDL_mutex *mutex = SDL_CreateMutex(); - if (!mutex) { + if (mutex == NULL) { return NULL; } SDL_DestroyMutex(mutex); diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index 44218b185d..27c5a47bff 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -64,7 +64,7 @@ SDL_CreateMutex_srw(void) /* Relies on SRWLOCK_INIT == 0. */ mutex = (SDL_mutex_srw *) SDL_calloc(1, sizeof(*mutex)); - if (!mutex) { + if (mutex == NULL) { SDL_OutOfMemory(); } diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 4b01fe437e..590c394b0d 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -118,7 +118,7 @@ SDL_SemTryWait_atom(SDL_sem * _sem) SDL_sem_atom *sem = (SDL_sem_atom *)_sem; LONG count; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -140,7 +140,7 @@ SDL_SemWait_atom(SDL_sem * _sem) SDL_sem_atom *sem = (SDL_sem_atom *)_sem; LONG count; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -172,7 +172,7 @@ SDL_SemWaitTimeout_atom(SDL_sem * _sem, Uint32 timeout) return SDL_SemWait_atom(_sem); } - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -215,7 +215,7 @@ SDL_SemValue_atom(SDL_sem * _sem) { SDL_sem_atom *sem = (SDL_sem_atom *)_sem; - if (!sem) { + if (sem == NULL) { SDL_InvalidParamError("sem"); return 0; } @@ -228,7 +228,7 @@ SDL_SemPost_atom(SDL_sem * _sem) { SDL_sem_atom *sem = (SDL_sem_atom *)_sem; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -309,7 +309,7 @@ SDL_SemWaitTimeout_kern(SDL_sem * _sem, Uint32 timeout) int retval; DWORD dwMilliseconds; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } @@ -350,7 +350,7 @@ static Uint32 SDL_SemValue_kern(SDL_sem * _sem) { SDL_sem_kern *sem = (SDL_sem_kern *)_sem; - if (!sem) { + if (sem == NULL) { SDL_InvalidParamError("sem"); return 0; } @@ -361,7 +361,7 @@ static int SDL_SemPost_kern(SDL_sem * _sem) { SDL_sem_kern *sem = (SDL_sem_kern *)_sem; - if (!sem) { + if (sem == NULL) { return SDL_InvalidParamError("sem"); } /* Increase the counter in the first place, because @@ -418,7 +418,7 @@ SDL_CreateSemaphore(Uint32 initial_value) pWaitOnAddress = (pfnWaitOnAddress) GetProcAddress(synch120, "WaitOnAddress"); pWakeByAddressSingle = (pfnWakeByAddressSingle) GetProcAddress(synch120, "WakeByAddressSingle"); - if(pWaitOnAddress && pWakeByAddressSingle) { + if (pWaitOnAddress && pWakeByAddressSingle) { impl = &SDL_sem_impl_atom; } } diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c index 859be4bd18..2179ae41fa 100644 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -76,7 +76,7 @@ RunThreadViaCreateThread(LPVOID data) static unsigned __stdcall RunThreadViaBeginThreadEx(void *data) { - return (unsigned) RunThread(data); + return (unsigned)RunThread(data); } #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD @@ -187,7 +187,7 @@ SDL_SYS_SetupThread(const char *name) SDL_threadID SDL_ThreadID(void) { - return ((SDL_threadID) GetCurrentThreadId()); + return (SDL_threadID)GetCurrentThreadId(); } int diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 7e2bcbebe7..5ef034dfc7 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -171,7 +171,7 @@ SDL_TimerThread(void *_data) current->scheduled = tick + interval; SDL_AddTimerInternal(data, current); } else { - if (!freelist_head) { + if (freelist_head == NULL) { freelist_head = current; } if (freelist_tail) { @@ -299,7 +299,7 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param) SDL_RemoveTimer(timer->timerID); } else { timer = (SDL_Timer *)SDL_malloc(sizeof(*timer)); - if (!timer) { + if (timer == NULL) { SDL_OutOfMemory(); return 0; } @@ -312,7 +312,7 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param) SDL_AtomicSet(&timer->canceled, 0); entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry)); - if (!entry) { + if (entry == NULL) { SDL_free(timer); SDL_OutOfMemory(); return 0; @@ -429,7 +429,7 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param) SDL_TimerMap *entry; entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry)); - if (!entry) { + if (entry == NULL) { SDL_OutOfMemory(); return 0; } diff --git a/src/timer/ngage/SDL_systimer.cpp b/src/timer/ngage/SDL_systimer.cpp index 43d89f4f22..d365c8354b 100644 --- a/src/timer/ngage/SDL_systimer.cpp +++ b/src/timer/ngage/SDL_systimer.cpp @@ -37,8 +37,7 @@ extern "C" { void SDL_TicksInit(void) { - if (ticks_started) - { + if (ticks_started) { return; } ticks_started = SDL_TRUE; @@ -61,8 +60,7 @@ SDL_TicksQuit(void) Uint64 SDL_GetTicks64(void) { - if (! ticks_started) - { + if (! ticks_started) { SDL_TicksInit(); } diff --git a/src/timer/psp/SDL_systimer.c b/src/timer/psp/SDL_systimer.c index c8effda37f..2602d0d206 100644 --- a/src/timer/psp/SDL_systimer.c +++ b/src/timer/psp/SDL_systimer.c @@ -76,8 +76,9 @@ SDL_GetPerformanceFrequency(void) void SDL_Delay(Uint32 ms) { const Uint32 max_delay = 0xffffffffUL / 1000; - if(ms > max_delay) + if (ms > max_delay) { ms = max_delay; + } sceKernelDelayThreadCB(ms * 1000); } diff --git a/src/timer/unix/SDL_systimer.c b/src/timer/unix/SDL_systimer.c index 82aa5f14bd..df14631ce8 100644 --- a/src/timer/unix/SDL_systimer.c +++ b/src/timer/unix/SDL_systimer.c @@ -115,7 +115,7 @@ SDL_GetTicks64(void) return (Uint64)(((Sint64)(now.tv_sec - start_ts.tv_sec) * 1000) + ((now.tv_nsec - start_ts.tv_nsec) / 1000000)); #elif defined(__APPLE__) const uint64_t now = mach_absolute_time(); - return ((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000); + return (((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000; #else SDL_assert(SDL_FALSE); return 0; @@ -157,7 +157,7 @@ SDL_GetPerformanceCounter(void) ticks *= 1000000; ticks += now.tv_usec; } - return (ticks); + return ticks; } Uint64 diff --git a/src/timer/vita/SDL_systimer.c b/src/timer/vita/SDL_systimer.c index ae900d9af7..f3bd231d82 100644 --- a/src/timer/vita/SDL_systimer.c +++ b/src/timer/vita/SDL_systimer.c @@ -76,8 +76,9 @@ SDL_GetPerformanceFrequency(void) void SDL_Delay(Uint32 ms) { const Uint32 max_delay = 0xffffffffUL / 1000; - if(ms > max_delay) + if (ms > max_delay) { ms = max_delay; + } sceKernelDelayThreadCB(ms * 1000); } diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index 4e8e428419..06cb818287 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -138,7 +138,7 @@ Uint16 *src = (Uint16 *)(from); \ Uint16 *dst = (Uint16 *)(to); \ Uint32 ALPHA = alpha >> 3; \ - for(i = 0; i < (int)(length); i++) { \ + for (i = 0; i < (int)(length); i++) { \ Uint32 s = *src++; \ Uint32 d = *dst; \ s = (s | s << 16) & 0x07e0f81f; \ @@ -147,7 +147,7 @@ d &= 0x07e0f81f; \ *dst++ = (Uint16)(d | d >> 16); \ } \ - } while(0) + } while (0) #define ALPHA_BLIT16_555(to, from, length, bpp, alpha) \ do { \ @@ -155,7 +155,7 @@ Uint16 *src = (Uint16 *)(from); \ Uint16 *dst = (Uint16 *)(to); \ Uint32 ALPHA = alpha >> 3; \ - for(i = 0; i < (int)(length); i++) { \ + for (i = 0; i < (int)(length); i++) { \ Uint32 s = *src++; \ Uint32 d = *dst; \ s = (s | s << 16) & 0x03e07c1f; \ @@ -164,7 +164,7 @@ d &= 0x03e07c1f; \ *dst++ = (Uint16)(d | d >> 16); \ } \ - } while(0) + } while (0) /* * The general slow catch-all function, for remaining depths and formats @@ -224,7 +224,7 @@ src += bpp; \ dst += bpp; \ } \ - } while(0) + } while (0) /* * Special case: 50% alpha (alpha=128) @@ -239,13 +239,13 @@ int i; \ Uint32 *src = (Uint32 *)(from); \ Uint32 *dst = (Uint32 *)(to); \ - for(i = 0; i < (int)(length); i++) { \ + for (i = 0; i < (int)(length); i++) { \ Uint32 s = *src++; \ Uint32 d = *dst; \ *dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \ + (s & d & 0x00010101); \ } \ - } while(0) + } while (0) /* * For 16bpp, we can actually blend two pixels in parallel, if we take @@ -259,7 +259,7 @@ Uint32 d = *dst; \ *dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \ (s & d & (~mask & 0xffff))); \ - } while(0) + } while (0) /* basic 16bpp blender. mask is the pixels to keep when adding. */ #define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask) \ @@ -289,7 +289,7 @@ if (n) \ BLEND16_50(dst, src, mask); /* last odd pixel */ \ } \ - } while(0) + } while (0) #define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \ ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7deU) @@ -323,8 +323,9 @@ } else { \ blitter(2, Uint8, ALPHA_BLIT16_565); \ } \ - } else \ + } else { \ goto general16; \ + } \ break; \ \ case 0x7fff: \ @@ -337,8 +338,9 @@ blitter(2, Uint8, ALPHA_BLIT16_555); \ } \ break; \ - } else \ + } else { \ goto general16; \ + } \ break; \ \ default: \ @@ -360,12 +362,13 @@ } else { \ blitter(4, Uint16, ALPHA_BLIT32_888); \ } \ - } else \ + } else { \ blitter(4, Uint16, ALPHA_BLIT_ANY); \ + } \ break; \ } \ } \ - } while(0) + } while (0) /* * Set a pixel value using the given format, except that the alpha value is @@ -383,12 +386,6 @@ * This takes care of the case when the surface is clipped on the left and/or * right. Top clipping has already been taken care of. */ -static void -RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst, - Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha) -{ - SDL_PixelFormat *fmt = surf_dst->format; - #define RLECLIPBLIT(bpp, Type, do_blit) \ do { \ int linecount = srcrect->h; \ @@ -422,24 +419,31 @@ RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst, nocopy ## bpp ## do_blit: \ srcbuf += run * bpp; \ ofs += run; \ - } else if (!ofs) \ + } else if (!ofs) { \ break; \ + } \ \ if (ofs == w) { \ ofs = 0; \ dstbuf += surf_dst->pitch; \ - if (!--linecount) \ + if (!--linecount) { \ break; \ + } \ } \ } \ - } while(0) + } while (0) + + +static void +RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst, + Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha) +{ + SDL_PixelFormat *fmt = surf_dst->format; CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt); - -#undef RLECLIPBLIT - } +#undef RLECLIPBLIT /* blit a colorkeyed RLE surface */ static int SDLCALL @@ -455,7 +459,7 @@ SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, /* Lock the destination if necessary */ if (SDL_MUSTLOCK(surf_dst)) { if (SDL_LockSurface(surf_dst) < 0) { - return (-1); + return -1; } } @@ -473,19 +477,19 @@ SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, if (vskip) { #define RLESKIP(bpp, Type) \ - for(;;) { \ + for (;;) { \ int run; \ ofs += *(Type *)srcbuf; \ run = ((Type *)srcbuf)[1]; \ srcbuf += sizeof(Type) * 2; \ - if(run) { \ + if (run) { \ srcbuf += run * bpp; \ ofs += run; \ - } else if(!ofs) \ + } else if (!ofs) \ goto done; \ - if(ofs == w) { \ + if (ofs == w) { \ ofs = 0; \ - if(!--vskip) \ + if (!--vskip) \ break; \ } \ } @@ -521,25 +525,25 @@ SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, do { \ int linecount = srcrect->h; \ int ofs = 0; \ - for(;;) { \ + for (;;) { \ unsigned run; \ ofs += *(Type *)srcbuf; \ run = ((Type *)srcbuf)[1]; \ srcbuf += 2 * sizeof(Type); \ - if(run) { \ + if (run) { \ do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \ srcbuf += run * bpp; \ ofs += run; \ - } else if(!ofs) \ + } else if (!ofs) \ break; \ - if(ofs == w) { \ + if (ofs == w) { \ ofs = 0; \ dstbuf += surf_dst->pitch; \ - if(!--linecount) \ + if (!--linecount) \ break; \ } \ } \ - } while(0) + } while (0) CHOOSE_BLIT(RLEBLIT, alpha, fmt); @@ -551,7 +555,7 @@ SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, if (SDL_MUSTLOCK(surf_dst)) { SDL_UnlockSurface(surf_dst); } - return (0); + return 0; } #undef OPAQUE_BLIT @@ -577,7 +581,7 @@ SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, d &= 0xff00; \ d = (d + ((s - d) * alpha >> 8)) & 0xff00; \ dst = d1 | d | 0xff000000; \ - } while(0) + } while (0) /* * For 16bpp pixels, we have stored the 5 most significant alpha bits in @@ -593,7 +597,7 @@ SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, d += (s - d) * alpha >> 5; \ d &= 0x07e0f81f; \ dst = (Uint16)(d | d >> 16); \ - } while(0) + } while (0) #define BLIT_TRANSL_555(src, dst) \ do { \ @@ -605,7 +609,7 @@ SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, d += (s - d) * alpha >> 5; \ d &= 0x03e07c1f; \ dst = (Uint16)(d | d >> 16); \ - } while(0) + } while (0) /* used to save the destination format in the encoding. Designed to be macro-compatible with SDL_PixelFormat but without the unneeded fields */ @@ -652,27 +656,27 @@ RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst, ofs += ((Ctype *)srcbuf)[0]; \ run = ((Ctype *)srcbuf)[1]; \ srcbuf += 2 * sizeof(Ctype); \ - if(run) { \ + if (run) { \ /* clip to left and right borders */ \ int cofs = ofs; \ int crun = run; \ - if(left - cofs > 0) { \ + if (left - cofs > 0) { \ crun -= left - cofs; \ cofs = left; \ } \ - if(crun > right - cofs) \ + if (crun > right - cofs) \ crun = right - cofs; \ - if(crun > 0) \ + if (crun > 0) \ PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \ srcbuf + (cofs - ofs) * sizeof(Ptype), \ (unsigned)crun, sizeof(Ptype)); \ srcbuf += run * sizeof(Ptype); \ ofs += run; \ - } else if(!ofs) \ + } else if (!ofs) \ return; \ - } while(ofs < w); \ + } while (ofs < w); \ /* skip padding if necessary */ \ - if(sizeof(Ptype) == 2) \ + if (sizeof(Ptype) == 2) \ srcbuf += (uintptr_t)srcbuf & 2; \ /* blit translucent pixels on the same line */ \ ofs = 0; \ @@ -681,30 +685,30 @@ RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst, ofs += ((Uint16 *)srcbuf)[0]; \ run = ((Uint16 *)srcbuf)[1]; \ srcbuf += 4; \ - if(run) { \ + if (run) { \ /* clip to left and right borders */ \ int cofs = ofs; \ int crun = run; \ - if(left - cofs > 0) { \ + if (left - cofs > 0) { \ crun -= left - cofs; \ cofs = left; \ } \ - if(crun > right - cofs) \ + if (crun > right - cofs) \ crun = right - cofs; \ - if(crun > 0) { \ + if (crun > 0) { \ Ptype *dst = (Ptype *)dstbuf + cofs; \ Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \ int i; \ - for(i = 0; i < crun; i++) \ + for (i = 0; i < crun; i++) \ do_blend(src[i], dst[i]); \ } \ srcbuf += run * 4; \ ofs += run; \ } \ - } while(ofs < w); \ + } while (ofs < w); \ dstbuf += surf_dst->pitch; \ - } while(--linecount); \ - } while(0) + } while (--linecount); \ + } while (0) switch (df->BytesPerPixel) { case 2: @@ -818,16 +822,16 @@ SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, ofs += ((Ctype *)srcbuf)[0]; \ run = ((Ctype *)srcbuf)[1]; \ srcbuf += 2 * sizeof(Ctype); \ - if(run) { \ + if (run) { \ PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \ run, sizeof(Ptype)); \ srcbuf += run * sizeof(Ptype); \ ofs += run; \ - } else if(!ofs) \ + } else if (!ofs) \ goto done; \ - } while(ofs < w); \ + } while (ofs < w); \ /* skip padding if necessary */ \ - if(sizeof(Ptype) == 2) \ + if (sizeof(Ptype) == 2) \ srcbuf += (uintptr_t)srcbuf & 2; \ /* blit translucent pixels on the same line */ \ ofs = 0; \ @@ -836,10 +840,10 @@ SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, ofs += ((Uint16 *)srcbuf)[0]; \ run = ((Uint16 *)srcbuf)[1]; \ srcbuf += 4; \ - if(run) { \ + if (run) { \ Ptype *dst = (Ptype *)dstbuf + ofs; \ unsigned i; \ - for(i = 0; i < run; i++) { \ + for (i = 0; i < run; i++) { \ Uint32 src = *(Uint32 *)srcbuf; \ do_blend(src, *dst); \ srcbuf += 4; \ @@ -847,10 +851,10 @@ SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, } \ ofs += run; \ } \ - } while(ofs < w); \ + } while (ofs < w); \ dstbuf += surf_dst->pitch; \ - } while(--linecount); \ - } while(0) + } while (--linecount); \ + } while (0) switch (df->BytesPerPixel) { case 2: @@ -1035,11 +1039,13 @@ RLEAlphaSurface(SDL_Surface * surface) SDL_PixelFormat *, SDL_PixelFormat *); dest = surface->map->dst; - if (!dest) + if (dest == NULL) { return -1; + } df = dest->format; - if (surface->format->BitsPerPixel != 32) - return -1; /* only 32bpp source supported */ + if (surface->format->BitsPerPixel != 32) { + return -1; /* only 32bpp source supported */ + } /* find out whether the destination is one we support, and determine the max size of the encoded result */ @@ -1089,7 +1095,7 @@ RLEAlphaSurface(SDL_Surface * surface) maxsize += sizeof(RLEDestFormat); rlebuf = (Uint8 *) SDL_malloc(maxsize); - if (!rlebuf) { + if (rlebuf == NULL) { return SDL_OutOfMemory(); } { @@ -1121,7 +1127,7 @@ RLEAlphaSurface(SDL_Surface * surface) /* opaque counts are 8 or 16 bits, depending on target depth */ #define ADD_OPAQUE_COUNTS(n, m) \ - if(df->BytesPerPixel == 4) { \ + if (df->BytesPerPixel == 4) { \ ((Uint16 *)dst)[0] = n; \ ((Uint16 *)dst)[1] = m; \ dst += 4; \ @@ -1149,8 +1155,9 @@ RLEAlphaSurface(SDL_Surface * surface) while (x < w && ISOPAQUE(src[x], sf)) x++; skip = runstart - skipstart; - if (skip == w) + if (skip == w) { blankline = 1; + } run = x - runstart; while (skip > max_opaque_run) { ADD_OPAQUE_COUNTS(max_opaque_run, 0); @@ -1202,8 +1209,9 @@ RLEAlphaSurface(SDL_Surface * surface) runstart += len; run -= len; } - if (!blankline) + if (!blankline) { lastline = dst; + } } while (x < w); src += surface->pitch >> 2; @@ -1229,8 +1237,9 @@ RLEAlphaSurface(SDL_Surface * surface) /* reallocate the buffer to release unused memory */ { Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf); - if (!p) + if (p == NULL) { p = rlebuf; + } surface->map->data = p; } @@ -1246,7 +1255,7 @@ getpix_8(const Uint8 * srcbuf) static Uint32 getpix_16(const Uint8 * srcbuf) { - return *(const Uint16 *) srcbuf; + return *(const Uint16 *)srcbuf; } static Uint32 @@ -1262,7 +1271,7 @@ getpix_24(const Uint8 * srcbuf) static Uint32 getpix_32(const Uint8 * srcbuf) { - return *(const Uint32 *) srcbuf; + return *(const Uint32 *)srcbuf; } typedef Uint32(*getpix_func) (const Uint8 *); @@ -1324,7 +1333,7 @@ RLEColorkeySurface(SDL_Surface * surface) h = surface->h; #define ADD_COUNTS(n, m) \ - if(bpp == 4) { \ + if (bpp == 4) { \ ((Uint16 *)dst)[0] = n; \ ((Uint16 *)dst)[1] = m; \ dst += 4; \ @@ -1349,8 +1358,9 @@ RLEColorkeySurface(SDL_Surface * surface) while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey) x++; skip = runstart - skipstart; - if (skip == w) + if (skip == w) { blankline = 1; + } run = x - runstart; /* encode segment */ @@ -1372,8 +1382,9 @@ RLEColorkeySurface(SDL_Surface * surface) runstart += len; run -= len; } - if (!blankline) + if (!blankline) { lastline = dst; + } } while (x < w); srcbuf += surface->pitch; @@ -1398,8 +1409,9 @@ RLEColorkeySurface(SDL_Surface * surface) { /* If SDL_realloc returns NULL, the original block is left intact */ Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf); - if (!p) + if (p == NULL) { p = rlebuf; + } surface->map->data = p; } @@ -1465,7 +1477,7 @@ SDL_RLESurface(SDL_Surface * surface) /* The surface is now accelerated */ surface->flags |= SDL_RLEACCEL; - return (0); + return 0; } /* @@ -1497,7 +1509,7 @@ UnRLEAlpha(SDL_Surface * surface) surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch); if (!surface->pixels) { - return (SDL_FALSE); + return SDL_FALSE; } surface->flags |= SDL_SIMD_ALIGNED; /* fill background with transparent pixels */ @@ -1528,8 +1540,9 @@ UnRLEAlpha(SDL_Surface * surface) } while (ofs < w); /* skip padding if needed */ - if (bpp == 2) - srcbuf += (uintptr_t) srcbuf & 2; + if (bpp == 2) { + srcbuf += (uintptr_t)srcbuf & 2; + } /* copy translucent pixels */ ofs = 0; @@ -1547,7 +1560,7 @@ UnRLEAlpha(SDL_Surface * surface) } end_function: - return (SDL_TRUE); + return SDL_TRUE; } void diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c index c9f8aed197..09fbb48206 100644 --- a/src/video/SDL_blit.c +++ b/src/video/SDL_blit.c @@ -95,7 +95,7 @@ SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect, SDL_UnlockSurface(src); } /* Blit is done! */ - return (okay ? 0 : -1); + return okay ? 0 : -1; } #if SDL_HAVE_BLIT_AUTO diff --git a/src/video/SDL_blit_A.c b/src/video/SDL_blit_A.c index ef8cfcebe9..2589657952 100644 --- a/src/video/SDL_blit_A.c +++ b/src/video/SDL_blit_A.c @@ -1189,8 +1189,8 @@ BlitARGBto565PixelAlpha(SDL_BlitInfo * info) compositioning used (>>8 instead of /255) doesn't handle it correctly. Also special-case alpha=0 for speed? Benchmark this! */ - if(alpha) { - if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { + if (alpha) { + if (alpha == (SDL_ALPHA_OPAQUE >> 3)) { *dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f)); } else { Uint32 d = *dstp; @@ -1236,8 +1236,8 @@ BlitARGBto555PixelAlpha(SDL_BlitInfo * info) compositioning used (>>8 instead of /255) doesn't handle it correctly. Also special-case alpha=0 for speed? Benchmark this! */ - if(alpha) { - if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { + if (alpha) { + if (alpha == (SDL_ALPHA_OPAQUE >> 3)) { *dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f)); } else { Uint32 d = *dstp; @@ -1326,7 +1326,7 @@ BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info) DUFFS_LOOP4( { RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel); - if(sA && Pixel != ckey) { + if (sA && Pixel != ckey) { RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); @@ -1369,7 +1369,7 @@ BlitNtoNPixelAlpha(SDL_BlitInfo * info) DUFFS_LOOP4( { DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); - if(sA) { + if (sA) { DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); @@ -1411,12 +1411,14 @@ SDL_CalculateBlitA(SDL_Surface * surface) || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { #if SDL_ARM_NEON_BLITTERS - if (SDL_HasNEON()) + if (SDL_HasNEON()) { return BlitARGBto565PixelAlphaARMNEON; + } #endif #if SDL_ARM_SIMD_BLITTERS - if (SDL_HasARMSIMD()) + if (SDL_HasARMSIMD()) { return BlitARGBto565PixelAlphaARMSIMD; + } #endif } #endif @@ -1424,10 +1426,11 @@ SDL_CalculateBlitA(SDL_Surface * surface) && sf->Gmask == 0xff00 && ((sf->Rmask == 0xff && df->Rmask == 0x1f) || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { - if (df->Gmask == 0x7e0) + if (df->Gmask == 0x7e0) { return BlitARGBto565PixelAlpha; - else if (df->Gmask == 0x3e0) + } else if (df->Gmask == 0x3e0) { return BlitARGBto555PixelAlpha; + } } return BlitNtoNPixelAlpha; @@ -1441,23 +1444,27 @@ SDL_CalculateBlitA(SDL_Surface * surface) && sf->Bshift % 8 == 0 && sf->Ashift % 8 == 0 && sf->Aloss == 0) { #ifdef __3dNOW__ - if (SDL_Has3DNow()) + if (SDL_Has3DNow()) { return BlitRGBtoRGBPixelAlphaMMX3DNOW; + } #endif #ifdef __MMX__ - if (SDL_HasMMX()) + if (SDL_HasMMX()) { return BlitRGBtoRGBPixelAlphaMMX; + } #endif } #endif /* __MMX__ || __3dNOW__ */ if (sf->Amask == 0xff000000) { #if SDL_ARM_NEON_BLITTERS - if (SDL_HasNEON()) + if (SDL_HasNEON()) { return BlitRGBtoRGBPixelAlphaARMNEON; + } #endif #if SDL_ARM_SIMD_BLITTERS - if (SDL_HasARMSIMD()) + if (SDL_HasARMSIMD()) { return BlitRGBtoRGBPixelAlphaARMSIMD; + } #endif return BlitRGBtoRGBPixelAlpha; } @@ -1513,10 +1520,9 @@ SDL_CalculateBlitA(SDL_Surface * surface) && sf->Gmask == df->Gmask && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { #ifdef __MMX__ - if (sf->Rshift % 8 == 0 - && sf->Gshift % 8 == 0 - && sf->Bshift % 8 == 0 && SDL_HasMMX()) + if (sf->Rshift % 8 == 0 && sf->Gshift % 8 == 0 && sf->Bshift % 8 == 0 && SDL_HasMMX()) { return BlitRGBtoRGBSurfaceAlphaMMX; + } #endif if ((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) { return BlitRGBtoRGBSurfaceAlpha; diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index f88cf22b3e..639118b718 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -60,8 +60,9 @@ GetL3CacheSize(void) int err = sysctlbyname(key, &result, &typeSize, NULL, 0); - if (0 != err) + if (0 != err) { return 0; + } return result; } @@ -759,7 +760,7 @@ ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info) while ((UNALIGNED_PTR(dst)) && (width)) { bits = *(src++); RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - if(!srcfmt->Amask) + if (!srcfmt->Amask) a = info->a; *(dst++) = MAKE8888(dstfmt, r, g, b, a); width--; @@ -792,7 +793,7 @@ ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info) while (extrawidth) { bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - if(!srcfmt->Amask) + if (!srcfmt->Amask) a = info->a; *(dst++) = MAKE8888(dstfmt, r, g, b, a); extrawidth--; @@ -850,7 +851,7 @@ ConvertAltivec32to32_prefetch(SDL_BlitInfo * info) DST_CHAN_DEST); bits = *(src++); RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - if(!srcfmt->Amask) + if (!srcfmt->Amask) a = info->a; *(dst++) = MAKE8888(dstfmt, r, g, b, a); width--; @@ -887,7 +888,7 @@ ConvertAltivec32to32_prefetch(SDL_BlitInfo * info) while (extrawidth) { bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - if(!srcfmt->Amask) + if (!srcfmt->Amask) a = info->a; *(dst++) = MAKE8888(dstfmt, r, g, b, a); extrawidth--; @@ -2304,10 +2305,18 @@ get_permutation(SDL_PixelFormat *srcfmt, SDL_PixelFormat *dstfmt, #if SDL_BYTEORDER == SDL_LIL_ENDIAN #else if (srcbpp == 3 && dstbpp == 4) { - if (p0 != 1) p0--; - if (p1 != 1) p1--; - if (p2 != 1) p2--; - if (p3 != 1) p3--; + if (p0 != 1) { + p0--; + } + if (p1 != 1) { + p1--; + } + if (p2 != 1) { + p2--; + } + if (p3 != 1) { + p3--; + } } else if (srcbpp == 4 && dstbpp == 3) { p0 = p1; p1 = p2; @@ -3374,7 +3383,7 @@ SDL_CalculateBlitN(SDL_Surface * surface) /* We don't support destinations less than 8-bits */ if (dstfmt->BitsPerPixel < 8) { - return (NULL); + return NULL; } switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { @@ -3397,8 +3406,9 @@ SDL_CalculateBlitN(SDL_Surface * surface) } else { /* Now the meat, choose the blitter we want */ Uint32 a_need = NO_ALPHA; - if (dstfmt->Amask) + if (dstfmt->Amask) { a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA; + } table = normal_blit[srcfmt->BytesPerPixel - 1]; for (which = 0; table[which].dstbpp; ++which) { if (MASKOK(srcfmt->Rmask, table[which].srcR) && @@ -3410,8 +3420,9 @@ SDL_CalculateBlitN(SDL_Surface * surface) dstfmt->BytesPerPixel == table[which].dstbpp && (a_need & table[which].alpha) == a_need && ((table[which].blit_features & GetBlitFeatures()) == - table[which].blit_features)) + table[which].blit_features)) { break; + } } blitfun = table[which].blitfunc; @@ -3441,7 +3452,7 @@ SDL_CalculateBlitN(SDL_Surface * surface) } } } - return (blitfun); + return blitfun; case SDL_COPY_COLORKEY: /* colorkey blit: Here we don't have too many options, mostly diff --git a/src/video/SDL_blit_auto.c b/src/video/SDL_blit_auto.c index d9613320a1..cda5c394e7 100644 --- a/src/video/SDL_blit_auto.c +++ b/src/video/SDL_blit_auto.c @@ -81,9 +81,15 @@ static void SDL_Blit_RGB888_RGB888_Blend(SDL_BlitInfo *info) dstB = srcB; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -142,9 +148,15 @@ static void SDL_Blit_RGB888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -283,9 +295,15 @@ static void SDL_Blit_RGB888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -293,9 +311,15 @@ static void SDL_Blit_RGB888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -362,9 +386,15 @@ static void SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -372,9 +402,15 @@ static void SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -445,9 +481,15 @@ static void SDL_Blit_RGB888_BGR888_Blend(SDL_BlitInfo *info) dstB = srcB; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -506,9 +548,15 @@ static void SDL_Blit_RGB888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -647,9 +695,15 @@ static void SDL_Blit_RGB888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -657,9 +711,15 @@ static void SDL_Blit_RGB888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -726,9 +786,15 @@ static void SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -736,9 +802,15 @@ static void SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -809,9 +881,15 @@ static void SDL_Blit_RGB888_ARGB8888_Blend(SDL_BlitInfo *info) dstA = 0xFF; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -872,9 +950,15 @@ static void SDL_Blit_RGB888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstA = 0xFF; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1019,9 +1103,15 @@ static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1029,10 +1119,18 @@ static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -1100,9 +1198,15 @@ static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1110,10 +1214,18 @@ static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -1184,9 +1296,15 @@ static void SDL_Blit_BGR888_RGB888_Blend(SDL_BlitInfo *info) dstB = srcB; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1245,9 +1363,15 @@ static void SDL_Blit_BGR888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1386,9 +1510,15 @@ static void SDL_Blit_BGR888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1396,9 +1526,15 @@ static void SDL_Blit_BGR888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -1465,9 +1601,15 @@ static void SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1475,9 +1617,15 @@ static void SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -1543,9 +1691,15 @@ static void SDL_Blit_BGR888_BGR888_Blend(SDL_BlitInfo *info) dstB = srcB; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1604,9 +1758,15 @@ static void SDL_Blit_BGR888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1745,9 +1905,15 @@ static void SDL_Blit_BGR888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1755,9 +1921,15 @@ static void SDL_Blit_BGR888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -1824,9 +1996,15 @@ static void SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1834,9 +2012,15 @@ static void SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -1909,9 +2093,15 @@ static void SDL_Blit_BGR888_ARGB8888_Blend(SDL_BlitInfo *info) dstA = 0xFF; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -1972,9 +2162,15 @@ static void SDL_Blit_BGR888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstA = 0xFF; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2119,9 +2315,15 @@ static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2129,10 +2331,18 @@ static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -2200,9 +2410,15 @@ static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2210,10 +2426,18 @@ static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -2290,9 +2514,15 @@ static void SDL_Blit_ARGB8888_RGB888_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2300,9 +2530,15 @@ static void SDL_Blit_ARGB8888_RGB888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -2359,9 +2595,15 @@ static void SDL_Blit_ARGB8888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2369,9 +2611,15 @@ static void SDL_Blit_ARGB8888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -2502,9 +2750,15 @@ static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2512,9 +2766,15 @@ static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -2583,9 +2843,15 @@ static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2593,9 +2859,15 @@ static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -2674,9 +2946,15 @@ static void SDL_Blit_ARGB8888_BGR888_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2684,9 +2962,15 @@ static void SDL_Blit_ARGB8888_BGR888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -2743,9 +3027,15 @@ static void SDL_Blit_ARGB8888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2753,9 +3043,15 @@ static void SDL_Blit_ARGB8888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -2886,9 +3182,15 @@ static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2896,9 +3198,15 @@ static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -2967,9 +3275,15 @@ static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -2977,9 +3291,15 @@ static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -3054,9 +3374,15 @@ static void SDL_Blit_ARGB8888_ARGB8888_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3064,10 +3390,18 @@ static void SDL_Blit_ARGB8888_ARGB8888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -3125,9 +3459,15 @@ static void SDL_Blit_ARGB8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3135,10 +3475,18 @@ static void SDL_Blit_ARGB8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -3278,9 +3626,15 @@ static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3288,10 +3642,18 @@ static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -3361,9 +3723,15 @@ static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3371,10 +3739,18 @@ static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -3451,9 +3827,15 @@ static void SDL_Blit_RGBA8888_RGB888_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3461,9 +3843,15 @@ static void SDL_Blit_RGBA8888_RGB888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -3520,9 +3908,15 @@ static void SDL_Blit_RGBA8888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3530,9 +3924,15 @@ static void SDL_Blit_RGBA8888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -3663,9 +4063,15 @@ static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3673,9 +4079,15 @@ static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -3744,9 +4156,15 @@ static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3754,9 +4172,15 @@ static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -3835,9 +4259,15 @@ static void SDL_Blit_RGBA8888_BGR888_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3845,9 +4275,15 @@ static void SDL_Blit_RGBA8888_BGR888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -3904,9 +4340,15 @@ static void SDL_Blit_RGBA8888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -3914,9 +4356,15 @@ static void SDL_Blit_RGBA8888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -4047,9 +4495,15 @@ static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4057,9 +4511,15 @@ static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -4128,9 +4588,15 @@ static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4138,9 +4604,15 @@ static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -4218,9 +4690,15 @@ static void SDL_Blit_RGBA8888_ARGB8888_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4228,10 +4706,18 @@ static void SDL_Blit_RGBA8888_ARGB8888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -4289,9 +4775,15 @@ static void SDL_Blit_RGBA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4299,10 +4791,18 @@ static void SDL_Blit_RGBA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -4442,9 +4942,15 @@ static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4452,10 +4958,18 @@ static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -4525,9 +5039,15 @@ static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4535,10 +5055,18 @@ static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -4617,9 +5145,15 @@ static void SDL_Blit_ABGR8888_RGB888_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4627,9 +5161,15 @@ static void SDL_Blit_ABGR8888_RGB888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -4686,9 +5226,15 @@ static void SDL_Blit_ABGR8888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4696,9 +5242,15 @@ static void SDL_Blit_ABGR8888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -4829,9 +5381,15 @@ static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4839,9 +5397,15 @@ static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -4910,9 +5474,15 @@ static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -4920,9 +5490,15 @@ static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -4999,9 +5575,15 @@ static void SDL_Blit_ABGR8888_BGR888_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5009,9 +5591,15 @@ static void SDL_Blit_ABGR8888_BGR888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -5068,9 +5656,15 @@ static void SDL_Blit_ABGR8888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5078,9 +5672,15 @@ static void SDL_Blit_ABGR8888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -5211,9 +5811,15 @@ static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5221,9 +5827,15 @@ static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -5292,9 +5904,15 @@ static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5302,9 +5920,15 @@ static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -5384,9 +6008,15 @@ static void SDL_Blit_ABGR8888_ARGB8888_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5394,10 +6024,18 @@ static void SDL_Blit_ABGR8888_ARGB8888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -5455,9 +6093,15 @@ static void SDL_Blit_ABGR8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5465,10 +6109,18 @@ static void SDL_Blit_ABGR8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -5608,9 +6260,15 @@ static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5618,10 +6276,18 @@ static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -5691,9 +6357,15 @@ static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5701,10 +6373,18 @@ static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -5783,9 +6463,15 @@ static void SDL_Blit_BGRA8888_RGB888_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5793,9 +6479,15 @@ static void SDL_Blit_BGRA8888_RGB888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -5852,9 +6544,15 @@ static void SDL_Blit_BGRA8888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -5862,9 +6560,15 @@ static void SDL_Blit_BGRA8888_RGB888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -5995,9 +6699,15 @@ static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6005,9 +6715,15 @@ static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -6076,9 +6792,15 @@ static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6086,9 +6808,15 @@ static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstR << 16) | (dstG << 8) | dstB; @@ -6165,9 +6893,15 @@ static void SDL_Blit_BGRA8888_BGR888_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6175,9 +6909,15 @@ static void SDL_Blit_BGRA8888_BGR888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -6234,9 +6974,15 @@ static void SDL_Blit_BGRA8888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6244,9 +6990,15 @@ static void SDL_Blit_BGRA8888_BGR888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -6377,9 +7129,15 @@ static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6387,9 +7145,15 @@ static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -6458,9 +7222,15 @@ static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = srcB + ((255 - srcA) * dstB) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6468,9 +7238,15 @@ static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } break; } dstpixel = (dstB << 16) | (dstG << 8) | dstR; @@ -6550,9 +7326,15 @@ static void SDL_Blit_BGRA8888_ARGB8888_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6560,10 +7342,18 @@ static void SDL_Blit_BGRA8888_ARGB8888_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -6621,9 +7411,15 @@ static void SDL_Blit_BGRA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6631,10 +7427,18 @@ static void SDL_Blit_BGRA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -6774,9 +7578,15 @@ static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6784,10 +7594,18 @@ static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; @@ -6857,9 +7675,15 @@ static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstA = srcA + ((255 - srcA) * dstA) / 255; break; case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; + dstR = srcR + dstR; if (dstR > 255) { + dstR = 255; + } + dstG = srcG + dstG; if (dstG > 255) { + dstG = 255; + } + dstB = srcB + dstB; if (dstB > 255) { + dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -6867,10 +7691,18 @@ static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) dstB = (srcB * dstB) / 255; break; case SDL_COPY_MUL: - dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255; - dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255; - dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255; - dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255; + dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) { + dstR = 255; + } + dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) { + dstG = 255; + } + dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) { + dstB = 255; + } + dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) { + dstA = 255; + } break; } dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB; diff --git a/src/video/SDL_blit_copy.c b/src/video/SDL_blit_copy.c index 1aa5febdb0..cd92f70118 100644 --- a/src/video/SDL_blit_copy.c +++ b/src/video/SDL_blit_copy.c @@ -46,8 +46,9 @@ SDL_memcpySSE(Uint8 * dst, const Uint8 * src, int len) dst += 64; } - if (len & 63) + if (len & 63) { SDL_memcpy(dst, src, len & 63); + } } #endif /* __SSE__ */ @@ -64,7 +65,7 @@ SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len) __m64* d64 = (__m64*)dst; __m64* s64 = (__m64*)src; - for(i= len / 64; i--;) { + for (i= len / 64; i--;) { d64[0] = s64[0]; d64[1] = s64[1]; d64[2] = s64[2]; @@ -78,8 +79,7 @@ SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len) s64 += 8; } - if (remain) - { + if (remain) { const int skip = len - remain; SDL_memcpy(dst + skip, src + skip, remain); } diff --git a/src/video/SDL_blit_slow.c b/src/video/SDL_blit_slow.c index a7a977dc67..934886aab2 100644 --- a/src/video/SDL_blit_slow.c +++ b/src/video/SDL_blit_slow.c @@ -147,14 +147,17 @@ SDL_Blit_Slow(SDL_BlitInfo * info) break; case SDL_COPY_ADD: dstR = srcR + dstR; - if (dstR > 255) + if (dstR > 255) { dstR = 255; + } dstG = srcG + dstG; - if (dstG > 255) + if (dstG > 255) { dstG = 255; + } dstB = srcB + dstB; - if (dstB > 255) + if (dstB > 255) { dstB = 255; + } break; case SDL_COPY_MOD: dstR = (srcR * dstR) / 255; @@ -163,17 +166,21 @@ SDL_Blit_Slow(SDL_BlitInfo * info) break; case SDL_COPY_MUL: dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; - if (dstR > 255) + if (dstR > 255) { dstR = 255; + } dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; - if (dstG > 255) + if (dstG > 255) { dstG = 255; + } dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; - if (dstB > 255) + if (dstB > 255) { dstB = 255; + } dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; - if (dstA > 255) + if (dstA > 255) { dstA = 255; + } break; } if (FORMAT_HAS_ALPHA(dstfmt_val)) { diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index 22bbce723f..9b8c123fca 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -64,17 +64,21 @@ static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8 Uint8 ch; Uint8 needsPad; -#define COPY_PIXEL(x) spot = &bits[ofs++]; if(spot >= start && spot < end) *spot = (x) +#define COPY_PIXEL(x) spot = &bits[ofs++]; if (spot >= start && spot < end) *spot = (x) for (;;) { - if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE; + if (!SDL_RWread(src, &ch, 1, 1)) { + return SDL_TRUE; + } /* | encoded mode starts with a run length, and then a byte | with two colour indexes to alternate between for the run */ if (ch) { Uint8 pixel; - if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE; + if (!SDL_RWread(src, &pixel, 1, 1)) { + return SDL_TRUE; + } if (isRle8) { /* 256-color bitmap, compressed */ do { COPY_PIXEL(pixel); @@ -84,9 +88,13 @@ static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8 Uint8 pixel1 = pixel & 0x0F; for (;;) { COPY_PIXEL(pixel0); /* even count, high nibble */ - if (!--ch) break; + if (!--ch) { + break; + } COPY_PIXEL(pixel1); /* odd count, low nibble */ - if (!--ch) break; + if (!--ch) { + break; + } } } } else { @@ -95,7 +103,9 @@ static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8 | a cursor move, or some absolute data. | zero tag may be absolute mode or an escape */ - if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE; + if (!SDL_RWread(src, &ch, 1, 1)) { + return SDL_TRUE; + } switch (ch) { case 0: /* end of line */ ofs = 0; @@ -104,9 +114,13 @@ static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8 case 1: /* end of bitmap */ return SDL_FALSE; /* success! */ case 2: /* delta */ - if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE; + if (!SDL_RWread(src, &ch, 1, 1)) { + return SDL_TRUE; + } ofs += ch; - if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE; + if (!SDL_RWread(src, &ch, 1, 1)) { + return SDL_TRUE; + } bits -= (ch * pitch); break; default: /* no compression */ @@ -114,22 +128,32 @@ static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8 needsPad = (ch & 1); do { Uint8 pixel; - if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE; + if (!SDL_RWread(src, &pixel, 1, 1)) { + return SDL_TRUE; + } COPY_PIXEL(pixel); } while (--ch); } else { needsPad = (((ch+1)>>1) & 1); /* (ch+1)>>1: bytes size */ for (;;) { Uint8 pixel; - if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE; + if (!SDL_RWread(src, &pixel, 1, 1)) { + return SDL_TRUE; + } COPY_PIXEL(pixel >> 4); - if (!--ch) break; + if (!--ch) { + break; + } COPY_PIXEL(pixel & 0x0F); - if (!--ch) break; + if (!--ch) { + break; + } } } /* pad at even boundary */ - if (needsPad && !SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE; + if (needsPad && !SDL_RWread(src, &ch, 1, 1)) { + return SDL_TRUE; + } break; } } @@ -460,7 +484,9 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) } if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) { was_error = readRlePixels(surface, src, biCompression == BI_RLE8); - if (was_error) SDL_Error(SDL_EFREAD); + if (was_error) { + SDL_Error(SDL_EFREAD); + } goto done; } top = (Uint8 *)surface->pixels; @@ -535,15 +561,17 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) case 15: case 16:{ Uint16 *pix = (Uint16 *) bits; - for (i = 0; i < surface->w; i++) + for (i = 0; i < surface->w; i++) { pix[i] = SDL_Swap16(pix[i]); + } break; } case 32:{ Uint32 *pix = (Uint32 *) bits; - for (i = 0; i < surface->w; i++) + for (i = 0; i < surface->w; i++) { pix[i] = SDL_Swap32(pix[i]); + } break; } } @@ -577,7 +605,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) if (freesrc && src) { SDL_RWclose(src); } - return (surface); + return surface; } int @@ -662,7 +690,7 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst) SDL_InitFormat(&format, SDL_PIXELFORMAT_BGR24); } surface = SDL_ConvertSurface(saveme, &format, 0); - if (!surface) { + if (surface == NULL) { SDL_SetError("Couldn't convert image to %d bpp", format.BitsPerPixel); } @@ -817,7 +845,7 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst) if (freedst && dst) { SDL_RWclose(dst); } - return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1); + return (SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_clipboard.c b/src/video/SDL_clipboard.c index effc3dc956..8334bcad43 100644 --- a/src/video/SDL_clipboard.c +++ b/src/video/SDL_clipboard.c @@ -28,11 +28,11 @@ SDL_SetClipboardText(const char *text) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { + if (_this == NULL) { return SDL_SetError("Video subsystem must be initialized to set clipboard text"); } - if (!text) { + if (text == NULL) { text = ""; } if (_this->SetClipboardText) { @@ -49,11 +49,11 @@ SDL_SetPrimarySelectionText(const char *text) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { + if (_this == NULL) { return SDL_SetError("Video subsystem must be initialized to set primary selection text"); } - if (!text) { + if (text == NULL) { text = ""; } if (_this->SetPrimarySelectionText) { @@ -70,7 +70,7 @@ SDL_GetClipboardText(void) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { + if (_this == NULL) { SDL_SetError("Video subsystem must be initialized to get clipboard text"); return SDL_strdup(""); } @@ -79,7 +79,7 @@ SDL_GetClipboardText(void) return _this->GetClipboardText(_this); } else { const char *text = _this->clipboard_text; - if (!text) { + if (text == NULL) { text = ""; } return SDL_strdup(text); @@ -91,7 +91,7 @@ SDL_GetPrimarySelectionText(void) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { + if (_this == NULL) { SDL_SetError("Video subsystem must be initialized to get primary selection text"); return SDL_strdup(""); } @@ -100,7 +100,7 @@ SDL_GetPrimarySelectionText(void) return _this->GetPrimarySelectionText(_this); } else { const char *text = _this->primary_selection_text; - if (!text) { + if (text == NULL) { text = ""; } return SDL_strdup(text); @@ -112,7 +112,7 @@ SDL_HasClipboardText(void) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { + if (_this == NULL) { SDL_SetError("Video subsystem must be initialized to check clipboard text"); return SDL_FALSE; } @@ -133,7 +133,7 @@ SDL_HasPrimarySelectionText(void) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { + if (_this == NULL) { SDL_SetError("Video subsystem must be initialized to check primary selection text"); return SDL_FALSE; } diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index bc5376cdf9..695b010d23 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -249,19 +249,19 @@ SDL_EGL_GetProcAddressInternal(_THIS, const char *proc) const SDL_bool is_egl_15_or_later = eglver >= ((((Uint32) 1) << 16) | 5); /* EGL 1.5 can use eglGetProcAddress() for any symbol. 1.4 and earlier can't use it for core entry points. */ - if (!retval && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) { + if (retval == NULL && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) { retval = _this->egl_data->eglGetProcAddress(proc); } #if !defined(__EMSCRIPTEN__) && !defined(SDL_VIDEO_DRIVER_VITA) /* LoadFunction isn't needed on Emscripten and will call dlsym(), causing other problems. */ /* Try SDL_LoadFunction() first for EGL <= 1.4, or as a fallback for >= 1.5. */ - if (!retval) { + if (retval == NULL) { retval = SDL_LoadFunction(_this->egl_data->opengl_dll_handle, proc); } #endif /* Try eglGetProcAddress if we're on <= 1.4 and still searching... */ - if (!retval && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) { + if (retval == NULL && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) { retval = _this->egl_data->eglGetProcAddress(proc); } } @@ -621,8 +621,7 @@ SDL_EGL_InitializeOffscreen(_THIS, int device) if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) { return SDL_SetError("Could not initialize EGL"); } - } - else { + } else { int i; SDL_bool found = SDL_FALSE; EGLDisplay attempted_egl_display; @@ -828,8 +827,7 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none) } /* first ensure that a found config has a matching format, or the function will fall through. */ - if (_this->egl_data->egl_required_visual_id) - { + if (_this->egl_data->egl_required_visual_id) { for (i = 0; i < found_configs; i++ ) { EGLint format; _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, diff --git a/src/video/SDL_fillrect.c b/src/video/SDL_fillrect.c index c93246948a..0caaafedd9 100644 --- a/src/video/SDL_fillrect.c +++ b/src/video/SDL_fillrect.c @@ -235,12 +235,12 @@ SDL_FillRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h) int SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color) { - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_FillRect(): dst"); } /* If 'rect' == NULL, then fill the whole surface */ - if (!rect) { + if (rect == NULL) { rect = &dst->clip_rect; /* Don't attempt to fill if the surface's clip_rect is empty */ if (SDL_RectEmpty(rect)) { @@ -303,7 +303,7 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, void (*fill_function)(Uint8 * pixels, int pitch, Uint32 color, int w, int h) = NULL; int i; - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("SDL_FillRects(): dst"); } @@ -317,7 +317,7 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, return SDL_SetError("SDL_FillRects(): You must lock the surface"); } - if (!rects) { + if (rects == NULL) { return SDL_InvalidParamError("SDL_FillRects(): rects"); } diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 8119ad4ade..19f8c1a8e6 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -81,11 +81,12 @@ Uint8* SDL_expand_byte[9] = { /* Helper functions */ +#define CASE(X) case X: return #X; const char* SDL_GetPixelFormatName(Uint32 format) { switch (format) { -#define CASE(X) case X: return #X; + CASE(SDL_PIXELFORMAT_INDEX1LSB) CASE(SDL_PIXELFORMAT_INDEX1MSB) CASE(SDL_PIXELFORMAT_INDEX4LSB) @@ -125,11 +126,12 @@ SDL_GetPixelFormatName(Uint32 format) CASE(SDL_PIXELFORMAT_NV12) CASE(SDL_PIXELFORMAT_NV21) CASE(SDL_PIXELFORMAT_EXTERNAL_OES) -#undef CASE + default: return "SDL_PIXELFORMAT_UNKNOWN"; } } +#undef CASE SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, @@ -563,8 +565,9 @@ SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format) format->Rshift = 0; format->Rloss = 8; if (Rmask) { - for (mask = Rmask; !(mask & 0x01); mask >>= 1) + for (mask = Rmask; !(mask & 0x01); mask >>= 1) { ++format->Rshift; + } for (; (mask & 0x01); mask >>= 1) --format->Rloss; } @@ -573,8 +576,9 @@ SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format) format->Gshift = 0; format->Gloss = 8; if (Gmask) { - for (mask = Gmask; !(mask & 0x01); mask >>= 1) + for (mask = Gmask; !(mask & 0x01); mask >>= 1) { ++format->Gshift; + } for (; (mask & 0x01); mask >>= 1) --format->Gloss; } @@ -583,8 +587,9 @@ SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format) format->Bshift = 0; format->Bloss = 8; if (Bmask) { - for (mask = Bmask; !(mask & 0x01); mask >>= 1) + for (mask = Bmask; !(mask & 0x01); mask >>= 1) { ++format->Bshift; + } for (; (mask & 0x01); mask >>= 1) --format->Bloss; } @@ -593,8 +598,9 @@ SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format) format->Ashift = 0; format->Aloss = 8; if (Amask) { - for (mask = Amask; !(mask & 0x01); mask >>= 1) + for (mask = Amask; !(mask & 0x01); mask >>= 1) { ++format->Ashift; + } for (; (mask & 0x01); mask >>= 1) --format->Aloss; } @@ -611,7 +617,7 @@ SDL_FreeFormat(SDL_PixelFormat *format) { SDL_PixelFormat *prev; - if (!format) { + if (format == NULL) { SDL_InvalidParamError("format"); return; } @@ -655,7 +661,7 @@ SDL_AllocPalette(int ncolors) } palette = (SDL_Palette *) SDL_malloc(sizeof(*palette)); - if (!palette) { + if (palette == NULL) { SDL_OutOfMemory(); return NULL; } @@ -677,7 +683,7 @@ SDL_AllocPalette(int ncolors) int SDL_SetPixelFormatPalette(SDL_PixelFormat * format, SDL_Palette *palette) { - if (!format) { + if (format == NULL) { return SDL_InvalidParamError("SDL_SetPixelFormatPalette(): format"); } @@ -709,7 +715,7 @@ SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors, int status = 0; /* Verify the parameters */ - if (!palette) { + if (palette == NULL) { return -1; } if (ncolors > (palette->ncolors - firstcolor)) { @@ -732,7 +738,7 @@ SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors, void SDL_FreePalette(SDL_Palette * palette) { - if (!palette) { + if (palette == NULL) { SDL_InvalidParamError("palette"); return; } @@ -750,8 +756,9 @@ void SDL_DitherColors(SDL_Color * colors, int bpp) { int i; - if (bpp != 8) - return; /* only 8bpp supported right now */ + if (bpp != 8) { + return; /* only 8bpp supported right now */ + } for (i = 0; i < 256; i++) { int r, g, b; @@ -799,7 +806,7 @@ SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a) smallest = distance; } } - return (pixel); + return pixel; } /* Tell whether palette is opaque, and if it has an alpha_channel */ @@ -855,9 +862,7 @@ Uint32 SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b) { if (format->palette == NULL) { - return (r >> format->Rloss) << format->Rshift - | (g >> format->Gloss) << format->Gshift - | (b >> format->Bloss) << format->Bshift | format->Amask; + return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask; } else { return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE); } @@ -869,10 +874,7 @@ SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { if (format->palette == NULL) { - return (r >> format->Rloss) << format->Rshift - | (g >> format->Gloss) << format->Gshift - | (b >> format->Bloss) << format->Bshift - | ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask); + return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask); } else { return SDL_FindColor(format->palette, r, g, b, a); } @@ -943,7 +945,7 @@ Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) (src->colors, dst->colors, src->ncolors * sizeof(SDL_Color)) == 0)) { *identical = 1; - return (NULL); + return NULL; } } *identical = 0; @@ -951,14 +953,14 @@ Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) map = (Uint8 *) SDL_calloc(256, sizeof(Uint8)); if (map == NULL) { SDL_OutOfMemory(); - return (NULL); + return NULL; } for (i = 0; i < src->ncolors; ++i) { map[i] = SDL_FindColor(dst, src->colors[i].r, src->colors[i].g, src->colors[i].b, src->colors[i].a); } - return (map); + return map; } /* Map from Palette to BitField */ @@ -975,7 +977,7 @@ Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, map = (Uint8 *) SDL_calloc(256, bpp); if (map == NULL) { SDL_OutOfMemory(); - return (NULL); + return NULL; } /* We memory copy to the pixel map so the endianness is preserved */ @@ -986,7 +988,7 @@ Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, Uint8 A = (Uint8) ((pal->colors[i].a * Amod) / 255); ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, (Uint32)R, (Uint32)G, (Uint32)B, (Uint32)A); } - return (map); + return map; } /* Map from BitField to Dithered-Palette to Palette */ @@ -1001,7 +1003,7 @@ MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical) dithered.ncolors = 256; SDL_DitherColors(colors, 8); dithered.colors = colors; - return (Map1to1(&dithered, pal, identical)); + return Map1to1(&dithered, pal, identical); } SDL_BlitMap * @@ -1013,7 +1015,7 @@ SDL_AllocBlitMap(void) map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map)); if (map == NULL) { SDL_OutOfMemory(); - return (NULL); + return NULL; } map->info.r = 0xFF; map->info.g = 0xFF; @@ -1021,7 +1023,7 @@ SDL_AllocBlitMap(void) map->info.a = 0xFF; /* It's ready to go */ - return (map); + return map; } @@ -1043,7 +1045,7 @@ SDL_InvalidateAllBlitMap(SDL_Surface *surface) void SDL_InvalidateMap(SDL_BlitMap * map) { - if (!map) { + if (map == NULL) { return; } if (map->dst) { @@ -1084,18 +1086,19 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) Map1to1(srcfmt->palette, dstfmt->palette, &map->identity); if (!map->identity) { if (map->info.table == NULL) { - return (-1); + return -1; } } - if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel) + if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel) { map->identity = 0; + } } else { /* Palette --> BitField */ map->info.table = Map1toN(srcfmt, src->map->info.r, src->map->info.g, src->map->info.b, src->map->info.a, dstfmt); if (map->info.table == NULL) { - return (-1); + return -1; } } } else { @@ -1104,7 +1107,7 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) map->info.table = MapNto1(srcfmt, dstfmt, &map->identity); if (!map->identity) { if (map->info.table == NULL) { - return (-1); + return -1; } } map->identity = 0; /* Don't optimize to copy */ @@ -1136,7 +1139,7 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) } /* Choose your blitters wisely */ - return (SDL_CalculateBlit(src)); + return SDL_CalculateBlit(src); } void diff --git a/src/video/SDL_rect.c b/src/video/SDL_rect.c index fd2c52aac2..d3cc64ff1a 100644 --- a/src/video/SDL_rect.c +++ b/src/video/SDL_rect.c @@ -38,10 +38,10 @@ SDL_GetSpanEnclosingRect(int width, int height, } else if (height < 1) { SDL_InvalidParamError("height"); return SDL_FALSE; - } else if (!rects) { + } else if (rects == NULL) { SDL_InvalidParamError("rects"); return SDL_FALSE; - } else if (!span) { + } else if (span == NULL) { SDL_InvalidParamError("span"); return SDL_FALSE; } else if (numrects < 1) { diff --git a/src/video/SDL_rect_impl.h b/src/video/SDL_rect_impl.h index 26a54484ac..0e2513c355 100644 --- a/src/video/SDL_rect_impl.h +++ b/src/video/SDL_rect_impl.h @@ -26,10 +26,10 @@ SDL_HASINTERSECTION(const RECTTYPE * A, const RECTTYPE * B) { SCALARTYPE Amin, Amax, Bmin, Bmax; - if (!A) { + if (A == NULL) { SDL_InvalidParamError("A"); return SDL_FALSE; - } else if (!B) { + } else if (B == NULL) { SDL_InvalidParamError("B"); return SDL_FALSE; } else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { @@ -72,13 +72,13 @@ SDL_INTERSECTRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result) { SCALARTYPE Amin, Amax, Bmin, Bmax; - if (!A) { + if (A == NULL) { SDL_InvalidParamError("A"); return SDL_FALSE; - } else if (!B) { + } else if (B == NULL) { SDL_InvalidParamError("B"); return SDL_FALSE; - } else if (!result) { + } else if (result == NULL) { SDL_InvalidParamError("result"); return SDL_FALSE; } else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { /* Special cases for empty rects */ @@ -123,13 +123,13 @@ SDL_UNIONRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result) { SCALARTYPE Amin, Amax, Bmin, Bmax; - if (!A) { + if (A == NULL) { SDL_InvalidParamError("A"); return; - } else if (!B) { + } else if (B == NULL) { SDL_InvalidParamError("B"); return; - } else if (!result) { + } else if (result == NULL) { SDL_InvalidParamError("result"); return; } else if (SDL_RECTEMPTY(A)) { /* Special cases for empty Rects */ @@ -183,7 +183,7 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE * points, int count, const RECTTYPE * SCALARTYPE x, y; int i; - if (!points) { + if (points == NULL) { SDL_InvalidParamError("points"); return SDL_FALSE; } else if (count < 1) { @@ -305,19 +305,19 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1, SCALARTYPE recty2; int outcode1, outcode2; - if (!rect) { + if (rect == NULL) { SDL_InvalidParamError("rect"); return SDL_FALSE; - } else if (!X1) { + } else if (X1 == NULL) { SDL_InvalidParamError("X1"); return SDL_FALSE; - } else if (!Y1) { + } else if (Y1 == NULL) { SDL_InvalidParamError("Y1"); return SDL_FALSE; - } else if (!X2) { + } else if (X2 == NULL) { SDL_InvalidParamError("X2"); return SDL_FALSE; - } else if (!Y2) { + } else if (Y2 == NULL) { SDL_InvalidParamError("Y2"); return SDL_FALSE; } else if (SDL_RECTEMPTY(rect)) { diff --git a/src/video/SDL_shape.c b/src/video/SDL_shape.c index 1490451e1f..428d4b4ab3 100644 --- a/src/video/SDL_shape.c +++ b/src/video/SDL_shape.c @@ -28,33 +28,31 @@ SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned { SDL_Window *result = NULL; result = SDL_CreateWindow(title,-1000,-1000,w,h,(flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE) /* & (~SDL_WINDOW_SHOWN) */); - if(result != NULL) { + if (result != NULL) { if (SDL_GetVideoDevice()->shape_driver.CreateShaper == NULL) { SDL_DestroyWindow(result); return NULL; } result->shaper = SDL_GetVideoDevice()->shape_driver.CreateShaper(result); - if(result->shaper != NULL) { + if (result->shaper != NULL) { result->shaper->userx = x; result->shaper->usery = y; result->shaper->mode.mode = ShapeModeDefault; result->shaper->mode.parameters.binarizationCutoff = 1; result->shaper->hasshape = SDL_FALSE; return result; - } - else { + } else { SDL_DestroyWindow(result); return NULL; } - } - else + } else return NULL; } SDL_bool SDL_IsShapedWindow(const SDL_Window *window) { - if(window == NULL) + if (window == NULL) return SDL_FALSE; else return (SDL_bool)(window->shaper != NULL); @@ -73,14 +71,15 @@ SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitm Uint8 *bitmap_scanline; SDL_Color key; - if(SDL_MUSTLOCK(shape)) + if (SDL_MUSTLOCK(shape)) { SDL_LockSurface(shape); + } SDL_memset(bitmap, 0, shape->h * bytes_per_scanline); - for(y = 0;yh;y++) { + for (y = 0;yh;y++) { bitmap_scanline = bitmap + y * bytes_per_scanline; - for(x=0;xw;x++) { + for (x=0;xw;x++) { alpha = 0; pixel_value = 0; pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel); @@ -118,8 +117,9 @@ SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitm } } - if(SDL_MUSTLOCK(shape)) + if (SDL_MUSTLOCK(shape)) { SDL_UnlockSurface(shape); + } } static SDL_ShapeTree* @@ -134,8 +134,8 @@ RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rec SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree)); SDL_Rect next = {0,0,0,0}; - for(y=dimensions.y;ypixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); switch(mask->format->BytesPerPixel) { @@ -168,9 +168,10 @@ RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rec pixel_opaque = ((key.r != r || key.g != g || key.b != b) ? SDL_TRUE : SDL_FALSE); break; } - if(last_opaque == -1) + if (last_opaque == -1) { last_opaque = pixel_opaque; - if(last_opaque != pixel_opaque) { + } + if (last_opaque != pixel_opaque) { const int halfwidth = dimensions.w / 2; const int halfheight = dimensions.h / 2; @@ -219,11 +220,13 @@ SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape) dimensions.w = shape->w; dimensions.h = shape->h; - if(SDL_MUSTLOCK(shape)) + if (SDL_MUSTLOCK(shape)) { SDL_LockSurface(shape); + } result = RecursivelyCalculateShapeTree(mode,shape,dimensions); - if(SDL_MUSTLOCK(shape)) + if (SDL_MUSTLOCK(shape)) { SDL_UnlockSurface(shape); + } return result; } @@ -231,20 +234,19 @@ void SDL_TraverseShapeTree(SDL_ShapeTree *tree,SDL_TraversalFunction function,void* closure) { SDL_assert(tree != NULL); - if(tree->kind == QuadShape) { + if (tree->kind == QuadShape) { SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure); SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure); SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure); SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure); - } - else + } else function(tree,closure); } void SDL_FreeShapeTree(SDL_ShapeTree** shape_tree) { - if((*shape_tree)->kind == QuadShape) { + if ((*shape_tree)->kind == QuadShape) { SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upleft); SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upright); SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downleft); @@ -313,29 +315,28 @@ SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *sh static SDL_bool SDL_WindowHasAShape(SDL_Window *window) { - if (window == NULL || !SDL_IsShapedWindow(window)) + if (window == NULL || !SDL_IsShapedWindow(window)) { return SDL_FALSE; + } return window->shaper->hasshape; } int SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode) { - if(window != NULL && SDL_IsShapedWindow(window)) { - if(shape_mode == NULL) { - if(SDL_WindowHasAShape(window)) + if (window != NULL && SDL_IsShapedWindow(window)) { + if (shape_mode == NULL) { + if (SDL_WindowHasAShape(window)) /* The window given has a shape. */ return 0; else /* The window given is shapeable but lacks a shape. */ return SDL_WINDOW_LACKS_SHAPE; - } - else { + } else { *shape_mode = window->shaper->mode; return 0; } - } - else + } else /* The window given is not a valid shapeable window. */ return SDL_NONSHAPEABLE_WINDOW; } diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 384b6a7aec..fc3a06697c 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -120,7 +120,7 @@ SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) { SDL_Palette *palette = SDL_AllocPalette((1 << surface->format->BitsPerPixel)); - if (!palette) { + if (palette == NULL) { SDL_FreeSurface(surface); return NULL; } @@ -291,7 +291,7 @@ SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette) { - if (!surface) { + if (surface == NULL) { return SDL_InvalidParamError("SDL_SetSurfacePalette(): surface"); } if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) { @@ -307,7 +307,7 @@ SDL_SetSurfaceRLE(SDL_Surface * surface, int flag) { int flags; - if (!surface) { + if (surface == NULL) { return -1; } @@ -326,7 +326,7 @@ SDL_SetSurfaceRLE(SDL_Surface * surface, int flag) SDL_bool SDL_HasSurfaceRLE(SDL_Surface * surface) { - if (!surface) { + if (surface == NULL) { return SDL_FALSE; } @@ -342,7 +342,7 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) { int flags; - if (!surface) { + if (surface == NULL) { return SDL_InvalidParamError("surface"); } @@ -371,7 +371,7 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) SDL_bool SDL_HasColorKey(SDL_Surface * surface) { - if (!surface) { + if (surface == NULL) { return SDL_FALSE; } @@ -385,7 +385,7 @@ SDL_HasColorKey(SDL_Surface * surface) int SDL_GetColorKey(SDL_Surface * surface, Uint32 * key) { - if (!surface) { + if (surface == NULL) { return SDL_InvalidParamError("surface"); } @@ -406,7 +406,7 @@ SDL_ConvertColorkeyToAlpha(SDL_Surface * surface, SDL_bool ignore_alpha) { int x, y, bpp; - if (!surface) { + if (surface == NULL) { return; } @@ -496,7 +496,7 @@ SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b) { int flags; - if (!surface) { + if (surface == NULL) { return -1; } @@ -520,7 +520,7 @@ SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b) int SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b) { - if (!surface) { + if (surface == NULL) { return -1; } @@ -541,7 +541,7 @@ SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha) { int flags; - if (!surface) { + if (surface == NULL) { return -1; } @@ -562,7 +562,7 @@ SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha) int SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha) { - if (!surface) { + if (surface == NULL) { return -1; } @@ -577,7 +577,7 @@ SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode) { int flags, status; - if (!surface) { + if (surface == NULL) { return -1; } @@ -615,11 +615,11 @@ SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode) int SDL_GetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode *blendMode) { - if (!surface) { + if (surface == NULL) { return -1; } - if (!blendMode) { + if (blendMode == NULL) { return 0; } @@ -650,7 +650,7 @@ SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect) SDL_Rect full_rect; /* Don't do anything if there's no surface to act on */ - if (!surface) { + if (surface == NULL) { return SDL_FALSE; } @@ -661,7 +661,7 @@ SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect) full_rect.h = surface->h; /* Set the clipping rectangle */ - if (!rect) { + if (rect == NULL) { surface->clip_rect = full_rect; return SDL_TRUE; } @@ -698,7 +698,7 @@ SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect, (src->format->palette && src->map->src_palette_version != src->format->palette->version)) { if (SDL_MapSurface(src, dst) < 0) { - return (-1); + return -1; } /* just here for debugging */ /* printf */ @@ -706,7 +706,7 @@ SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect, /* src, dst->flags, src->map->info.flags, dst, dst->flags, */ /* dst->map->info.flags, src->map->blit); */ } - return (src->map->blit(src, srcrect, dst, dstrect)); + return src->map->blit(src, srcrect, dst, dstrect); } @@ -718,7 +718,7 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, int srcx, srcy, w, h; /* Make sure the surfaces aren't locked */ - if (!src || !dst) { + if (src == NULL || dst == NULL) { return SDL_InvalidParamError("SDL_UpperBlit(): src/dst"); } if (src->locked || dst->locked) { @@ -745,8 +745,9 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, srcx = 0; } maxw = src->w - srcx; - if (maxw < w) + if (maxw < w) { w = maxw; + } srcy = srcrect->y; h = srcrect->h; @@ -756,8 +757,9 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, srcy = 0; } maxh = src->h - srcy; - if (maxh < h) + if (maxh < h) { h = maxh; + } } else { srcx = srcy = 0; @@ -777,8 +779,9 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, srcx += dx; } dx = dstrect->x + w - clip->x - clip->w; - if (dx > 0) + if (dx > 0) { w -= dx; + } dy = clip->y - dstrect->y; if (dy > 0) { @@ -787,8 +790,9 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, srcy += dy; } dy = dstrect->y + h - clip->y - clip->h; - if (dy > 0) + if (dy > 0) { h -= dy; + } } /* Switch back to a fast blit if we were previously stretching */ @@ -829,14 +833,14 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, int dst_w, dst_h; /* Make sure the surfaces aren't locked */ - if (!src || !dst) { + if (src == NULL || dst == NULL) { return SDL_InvalidParamError("SDL_UpperBlitScaled(): src/dst"); } if (src->locked || dst->locked) { return SDL_SetError("Surfaces must not be locked during blit"); } - if (NULL == srcrect) { + if (srcrect == NULL) { src_w = src->w; src_h = src->h; } else { @@ -844,7 +848,7 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, src_h = srcrect->h; } - if (NULL == dstrect) { + if (dstrect == NULL) { dst_w = dst->w; dst_h = dst->h; } else { @@ -860,7 +864,7 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, scaling_w = (double)dst_w / src_w; scaling_h = (double)dst_h / src_h; - if (NULL == dstrect) { + if (dstrect == NULL) { dst_x0 = 0; dst_y0 = 0; dst_x1 = dst_w; @@ -872,7 +876,7 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, dst_y1 = dst_y0 + dst_h; } - if (NULL == srcrect) { + if (srcrect == NULL) { src_x0 = 0; src_y0 = 0; src_x1 = src_w; @@ -1011,9 +1015,9 @@ SDL_PrivateLowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect, if ( !(src->map->info.flags & complex_copy_flags) && src->format->format == dst->format->format && !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) { - return SDL_SoftStretch( src, srcrect, dst, dstrect ); + return SDL_SoftStretch(src, srcrect, dst, dstrect); } else { - return SDL_LowerBlit( src, srcrect, dst, dstrect ); + return SDL_LowerBlit(src, srcrect, dst, dstrect); } } else { if ( !(src->map->info.flags & complex_copy_flags) && @@ -1117,7 +1121,7 @@ SDL_LockSurface(SDL_Surface * surface) ++surface->locked; /* Ready to go.. */ - return (0); + return 0; } /* @@ -1167,11 +1171,11 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format, Uint8 *palette_saved_alpha = NULL; int palette_saved_alpha_ncolors = 0; - if (!surface) { + if (surface == NULL) { SDL_InvalidParamError("surface"); return NULL; } - if (!format) { + if (format == NULL) { SDL_InvalidParamError("format"); return NULL; } @@ -1180,14 +1184,13 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format, if (format->palette != NULL) { int i; for (i = 0; i < format->palette->ncolors; ++i) { - if ((format->palette->colors[i].r != 0xFF) || - (format->palette->colors[i].g != 0xFF) || - (format->palette->colors[i].b != 0xFF)) + if ((format->palette->colors[i].r != 0xFF) || (format->palette->colors[i].g != 0xFF) || (format->palette->colors[i].b != 0xFF)) { break; + } } if (i == format->palette->ncolors) { SDL_SetError("Empty destination palette"); - return (NULL); + return NULL; } } @@ -1197,7 +1200,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format, format->Gmask, format->Bmask, format->Amask); if (convert == NULL) { - return (NULL); + return NULL; } /* Copy the palette if any */ @@ -1383,7 +1386,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format, } /* We're ready to go! */ - return (convert); + return convert; } SDL_Surface * @@ -1454,13 +1457,13 @@ int SDL_ConvertPixels(int width, int height, void *nonconst_src = (void *) src; int ret; - if (!src) { + if (src == NULL) { return SDL_InvalidParamError("src"); } if (!src_pitch) { return SDL_InvalidParamError("src_pitch"); } - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("dst"); } if (!dst_pitch) { @@ -1536,13 +1539,13 @@ int SDL_PremultiplyAlpha(int width, int height, Uint32 dstpixel; Uint32 dstR, dstG, dstB, dstA; - if (!src) { + if (src == NULL) { return SDL_InvalidParamError("src"); } if (!src_pitch) { return SDL_InvalidParamError("src_pitch"); } - if (!dst) { + if (dst == NULL) { return SDL_InvalidParamError("dst"); } if (!dst_pitch) { diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 1b3e75fb03..9b9f508ed5 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -208,7 +208,7 @@ SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window * window, Uint32 * fo SDL_WindowTextureData *data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA); int i; - if (!data) { + if (data == NULL) { SDL_Renderer *renderer = NULL; const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION); const SDL_bool specific_accelerated_renderer = ( @@ -227,7 +227,7 @@ SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window * window, Uint32 * fo break; } } - if (!renderer || (SDL_GetRendererInfo(renderer, &info) == -1)) { + if (renderer == NULL || (SDL_GetRendererInfo(renderer, &info) == -1)) { if (renderer) { SDL_DestroyRenderer(renderer); } return SDL_SetError("Requested renderer for " SDL_HINT_FRAMEBUFFER_ACCELERATION " is not available"); } @@ -246,7 +246,7 @@ SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window * window, Uint32 * fo } } } - if (!renderer) { + if (renderer == NULL) { return SDL_SetError("No hardware accelerated renderers available"); } } @@ -255,7 +255,7 @@ SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window * window, Uint32 * fo /* Create the data after we successfully create the renderer (bug #1116) */ data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { SDL_DestroyRenderer(renderer); return SDL_OutOfMemory(); } @@ -328,7 +328,7 @@ SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, const SDL_ void *src; data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA); - if (!data || !data->texture) { + if (data == NULL || !data->texture) { return SDL_SetError("No window texture data"); } @@ -356,7 +356,7 @@ SDL_DestroyWindowTexture(SDL_VideoDevice *unused, SDL_Window * window) SDL_WindowTextureData *data; data = SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, NULL); - if (!data) { + if (data == NULL) { return; } if (data->texture) { @@ -458,7 +458,7 @@ SDL_VideoInit(const char *driver_name) } if (driver_name != NULL && *driver_name != 0) { const char *driver_attempt = driver_name; - while(driver_attempt != NULL && *driver_attempt != 0 && video == NULL) { + while (driver_attempt != NULL && *driver_attempt != 0 && video == NULL) { const char* driver_attempt_end = SDL_strchr(driver_attempt, ','); size_t driver_attempt_len = (driver_attempt_end != NULL) ? (driver_attempt_end - driver_attempt) : SDL_strlen(driver_attempt); @@ -562,7 +562,7 @@ pre_driver_error: const char * SDL_GetCurrentVideoDriver() { - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return NULL; } @@ -646,7 +646,7 @@ SDL_DelVideoDisplay(int index) int SDL_GetNumVideoDisplays(void) { - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return 0; } @@ -697,7 +697,7 @@ SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect) CHECK_DISPLAY_INDEX(displayIndex, -1); - if (!rect) { + if (rect == NULL) { return SDL_InvalidParamError("rect"); } @@ -736,7 +736,7 @@ SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect) CHECK_DISPLAY_INDEX(displayIndex, -1); - if (!rect) { + if (rect == NULL) { return SDL_InvalidParamError("rect"); } @@ -807,7 +807,7 @@ SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) modes = SDL_realloc(modes, (display->max_display_modes + 32) * sizeof(*modes)); - if (!modes) { + if (modes == NULL) { return SDL_FALSE; } display->display_modes = modes; @@ -882,8 +882,7 @@ SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode) display = &_this->displays[displayIndex]; if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) { - return SDL_SetError("index must be in the range of 0 - %d", - SDL_GetNumDisplayModesForDisplay(display) - 1); + return SDL_SetError("index must be in the range of 0 - %d", SDL_GetNumDisplayModesForDisplay(display) - 1); } if (mode) { *mode = display->display_modes[index]; @@ -929,7 +928,7 @@ SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, int i; SDL_DisplayMode *current, *match; - if (!mode || !closest) { + if (mode == NULL || closest == NULL) { SDL_InvalidParamError("mode/closest"); return NULL; } @@ -966,7 +965,7 @@ SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, modes may still follow. */ continue; } - if (!match || current->w < match->w || current->h < match->h) { + if (match == NULL || current->w < match->w || current->h < match->h) { match = current; continue; } @@ -1070,8 +1069,7 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * /* Get a good video mode, the closest one possible */ if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) { - return SDL_SetError("No video mode large enough for %dx%d", - display_mode.w, display_mode.h); + return SDL_SetError("No video mode large enough for %dx%d", display_mode.w, display_mode.h); } } else { display_mode = display->desktop_mode; @@ -1277,7 +1275,7 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) CHECK_WINDOW_MAGIC(window, -1); - if (!mode) { + if (mode == NULL) { return SDL_InvalidParamError("mode"); } @@ -1360,8 +1358,9 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen) do nothing, or else we may trigger an ugly double-transition */ if (SDL_strcmp(_this->name, "cocoa") == 0) { /* don't do this for X11, etc */ - if (window->is_destroying && (window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP) + if (window->is_destroying && (window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP) { return 0; + } /* If we're switching between a fullscreen Space and "normal" fullscreen, we need to get back to normal first. */ if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN)) { @@ -1580,9 +1579,8 @@ SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags) static int SDL_ContextNotSupported(const char *name) { - return SDL_SetError("%s support is either not configured in SDL " - "or not available in current SDL video driver " - "(%s) or platform", name, _this->name); + return SDL_SetError("%s support is either not configured in SDL " "or not available in current SDL video driver " "(%s) or platform", name, + _this->name); } static int @@ -1597,7 +1595,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) SDL_Window *window; Uint32 type_flags, graphics_flags; - if (!_this) { + if (_this == NULL) { /* Initialize the video system if needed */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { return NULL; @@ -1674,7 +1672,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) } window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); - if (!window) { + if (window == NULL) { SDL_OutOfMemory(); return NULL; } @@ -1789,7 +1787,7 @@ SDL_CreateWindowFrom(const void *data) SDL_Window *window; Uint32 flags = SDL_WINDOW_FOREIGN; - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return NULL; } @@ -1825,7 +1823,7 @@ SDL_CreateWindowFrom(const void *data) } window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); - if (!window) { + if (window == NULL) { SDL_OutOfMemory(); return NULL; } @@ -1995,7 +1993,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags) SDL_bool SDL_HasWindows(void) { - return (_this && _this->windows != NULL); + return _this && _this->windows != NULL; } Uint32 @@ -2011,7 +2009,7 @@ SDL_GetWindowFromID(Uint32 id) { SDL_Window *window; - if (!_this) { + if (_this == NULL) { return NULL; } for (window = _this->windows; window; window = window->next) { @@ -2060,7 +2058,7 @@ SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon) { CHECK_WINDOW_MAGIC(window,); - if (!icon) { + if (icon == NULL) { return; } @@ -2353,10 +2351,10 @@ SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, { int dummy = 0; - if (!top) { top = &dummy; } - if (!left) { left = &dummy; } - if (!right) { right = &dummy; } - if (!bottom) { bottom = &dummy; } + if (top == NULL) { top = &dummy; } + if (left == NULL) { left = &dummy; } + if (right == NULL) { right = &dummy; } + if (bottom == NULL) { bottom = &dummy; } /* Always initialize, so applications don't have to care */ *top = *left = *bottom = *right = 0; @@ -2905,23 +2903,21 @@ SDL_SetWindowMouseGrab(SDL_Window * window, SDL_bool grabbed) SDL_bool SDL_GetWindowGrab(SDL_Window * window) { - return (SDL_GetWindowKeyboardGrab(window) || SDL_GetWindowMouseGrab(window)); + return SDL_GetWindowKeyboardGrab(window) || SDL_GetWindowMouseGrab(window); } SDL_bool SDL_GetWindowKeyboardGrab(SDL_Window * window) { CHECK_WINDOW_MAGIC(window, SDL_FALSE); - return window == _this->grabbed_window && - ((_this->grabbed_window->flags & SDL_WINDOW_KEYBOARD_GRABBED) != 0); + return window == _this->grabbed_window && ((_this->grabbed_window->flags & SDL_WINDOW_KEYBOARD_GRABBED) != 0); } SDL_bool SDL_GetWindowMouseGrab(SDL_Window * window) { CHECK_WINDOW_MAGIC(window, SDL_FALSE); - return window == _this->grabbed_window && - ((_this->grabbed_window->flags & SDL_WINDOW_MOUSE_GRABBED) != 0); + return window == _this->grabbed_window && ((_this->grabbed_window->flags & SDL_WINDOW_MOUSE_GRABBED) != 0); } SDL_Window * @@ -3095,7 +3091,7 @@ ShouldMinimizeOnFocusLoss(SDL_Window * window) /* Real fullscreen windows should minimize on focus loss so the desktop video mode is restored */ hint = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS); - if (!hint || !*hint || SDL_strcasecmp(hint, "auto") == 0) { + if (hint == NULL || !*hint || SDL_strcasecmp(hint, "auto") == 0) { if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP || DisableDisplayModeSwitching(_this) == SDL_TRUE) { return SDL_FALSE; @@ -3123,7 +3119,7 @@ SDL_GetFocusWindow(void) { SDL_Window *window; - if (!_this) { + if (_this == NULL) { return NULL; } for (window = _this->windows; window; window = window->next) { @@ -3219,7 +3215,7 @@ SDL_DestroyWindow(SDL_Window * window) SDL_bool SDL_IsScreenSaverEnabled() { - if (!_this) { + if (_this == NULL) { return SDL_TRUE; } return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE; @@ -3228,7 +3224,7 @@ SDL_IsScreenSaverEnabled() void SDL_EnableScreenSaver() { - if (!_this) { + if (_this == NULL) { return; } if (!_this->suspend_screensaver) { @@ -3243,7 +3239,7 @@ SDL_EnableScreenSaver() void SDL_DisableScreenSaver() { - if (!_this) { + if (_this == NULL) { return; } if (_this->suspend_screensaver) { @@ -3260,7 +3256,7 @@ SDL_VideoQuit(void) { int i; - if (!_this) { + if (_this == NULL) { return; } @@ -3305,7 +3301,7 @@ SDL_GL_LoadLibrary(const char *path) { int retval; - if (!_this) { + if (_this == NULL) { return SDL_UninitializedVideo(); } if (_this->gl_config.driver_loaded) { @@ -3326,7 +3322,7 @@ SDL_GL_LoadLibrary(const char *path) _this->GL_UnloadLibrary(_this); } } - return (retval); + return retval; } void * @@ -3334,7 +3330,7 @@ SDL_GL_GetProcAddress(const char *proc) { void *func; - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return NULL; } @@ -3379,7 +3375,7 @@ SDL_EGL_GetProcAddress(const char *proc) void SDL_GL_UnloadLibrary(void) { - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return; } @@ -3397,7 +3393,7 @@ SDL_GL_UnloadLibrary(void) static SDL_INLINE SDL_bool isAtLeastGL3(const char *verstr) { - return (verstr && (SDL_atoi(verstr) >= 3)); + return verstr && (SDL_atoi(verstr) >= 3); } #endif @@ -3424,7 +3420,7 @@ SDL_GL_ExtensionSupported(const char *extension) /* Lookup the available extensions */ glGetStringFunc = SDL_GL_GetProcAddress("glGetString"); - if (!glGetStringFunc) { + if (glGetStringFunc == NULL) { return SDL_FALSE; } @@ -3436,7 +3432,7 @@ SDL_GL_ExtensionSupported(const char *extension) glGetStringiFunc = SDL_GL_GetProcAddress("glGetStringi"); glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv"); - if ((!glGetStringiFunc) || (!glGetIntegervFunc)) { + if ((glGetStringiFunc == NULL) || (glGetIntegervFunc == NULL)) { return SDL_FALSE; } @@ -3457,7 +3453,7 @@ SDL_GL_ExtensionSupported(const char *extension) /* Try the old way with glGetString(GL_EXTENSIONS) ... */ extensions = (const char *) glGetStringFunc(GL_EXTENSIONS); - if (!extensions) { + if (extensions == NULL) { return SDL_FALSE; } /* @@ -3469,13 +3465,16 @@ SDL_GL_ExtensionSupported(const char *extension) for (;;) { where = SDL_strstr(start, extension); - if (!where) + if (where == NULL) { break; + } terminator = where + SDL_strlen(extension); - if (where == extensions || *(where - 1) == ' ') - if (*terminator == ' ' || *terminator == '\0') + if (where == extensions || *(where - 1) == ' ') { + if (*terminator == ' ' || *terminator == '\0') { return SDL_TRUE; + } + } start = terminator; } @@ -3531,7 +3530,7 @@ void SDL_EGL_SetEGLAttributeCallbacks(SDL_EGLAttribArrayCallback platformAttribC void SDL_GL_ResetAttributes() { - if (!_this) { + if (_this == NULL) { return; } @@ -3595,7 +3594,7 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 int retval; - if (!_this) { + if (_this == NULL) { return SDL_UninitializedVideo(); } retval = 0; @@ -3737,14 +3736,14 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) GLenum attachmentattrib = 0; #endif - if (!value) { + if (value == NULL) { return SDL_InvalidParamError("value"); } /* Clear value in any case */ *value = 0; - if (!_this) { + if (_this == NULL) { return SDL_UninitializedVideo(); } @@ -3884,8 +3883,7 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) { if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { *value = 1; - } - else { + } else { *value = 0; } return 0; @@ -3927,7 +3925,7 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) #if SDL_VIDEO_OPENGL glGetStringFunc = SDL_GL_GetProcAddress("glGetString"); - if (!glGetStringFunc) { + if (glGetStringFunc == NULL) { return -1; } @@ -3965,7 +3963,7 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) } glGetErrorFunc = SDL_GL_GetProcAddress("glGetError"); - if (!glGetErrorFunc) { + if (glGetErrorFunc == NULL) { return -1; } @@ -4014,7 +4012,7 @@ SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx) { int retval; - if (!_this) { + if (_this == NULL) { return SDL_UninitializedVideo(); } @@ -4049,7 +4047,7 @@ SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx) SDL_Window * SDL_GL_GetCurrentWindow(void) { - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return NULL; } @@ -4059,7 +4057,7 @@ SDL_GL_GetCurrentWindow(void) SDL_GLContext SDL_GL_GetCurrentContext(void) { - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return NULL; } @@ -4140,7 +4138,7 @@ void SDL_GL_GetDrawableSize(SDL_Window * window, int *w, int *h) int SDL_GL_SetSwapInterval(int interval) { - if (!_this) { + if (_this == NULL) { return SDL_UninitializedVideo(); } else if (SDL_GL_GetCurrentContext() == NULL) { return SDL_SetError("No OpenGL context has been made current"); @@ -4154,7 +4152,7 @@ SDL_GL_SetSwapInterval(int interval) int SDL_GL_GetSwapInterval(void) { - if (!_this) { + if (_this == NULL) { return 0; } else if (SDL_GL_GetCurrentContext() == NULL) { return 0; @@ -4190,7 +4188,7 @@ SDL_GL_SwapWindow(SDL_Window * window) void SDL_GL_DeleteContext(SDL_GLContext context) { - if (!_this || !context) { + if (_this == NULL || !context) { return; } @@ -4305,7 +4303,7 @@ SDL_GetWindowWMInfo(SDL_Window *window, struct SDL_SysWMinfo *info, Uint32 versi { CHECK_WINDOW_MAGIC(window, -1); - if (!info) { + if (info == NULL) { return SDL_InvalidParamError("info"); } @@ -4370,7 +4368,7 @@ SDL_IsTextInputShown(void) SDL_bool SDL_IsTextInputActive(void) { - return (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE); + return SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE; } void @@ -4463,10 +4461,10 @@ static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messagebo SDL_SysWMinfo info; SDL_Window *window = messageboxdata->window; - if (!window || SDL_GetWindowWMInfo(window, &info, SDL_SYSWM_CURRENT_VERSION) < 0) { + if (window == NULL || SDL_GetWindowWMInfo(window, &info, SDL_SYSWM_CURRENT_VERSION) < 0) { return SDL_TRUE; } else { - return (info.subsystem == drivertype); + return info.subsystem == drivertype; } } #endif @@ -4481,7 +4479,7 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_Window *current_window; SDL_MessageBoxData mbdata; - if (!messageboxdata) { + if (messageboxdata == NULL) { return SDL_InvalidParamError("messageboxdata"); } else if (messageboxdata->numbuttons < 0) { return SDL_SetError("Invalid number of buttons"); @@ -4496,13 +4494,17 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) show_cursor_prev = SDL_ShowCursor(1); SDL_ResetKeyboard(); - if (!buttonid) { + if (buttonid == NULL) { buttonid = &dummybutton; } SDL_memcpy(&mbdata, messageboxdata, sizeof(*messageboxdata)); - if (!mbdata.title) mbdata.title = ""; - if (!mbdata.message) mbdata.message = ""; + if (!mbdata.title) { + mbdata.title = ""; + } + if (!mbdata.message) { + mbdata.message = ""; + } messageboxdata = &mbdata; SDL_ClearError(); @@ -4609,8 +4611,12 @@ SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, S /* Web browsers don't (currently) have an API for a custom message box that can block, but for the most common case (SDL_ShowSimpleMessageBox), we can use the standard Javascript alert() function. */ - if (!title) title = ""; - if (!message) message = ""; + if (title == NULL) { + title = ""; + } + if (message == NULL) { + message = ""; + } EM_ASM_({ alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1)); }, title, message); @@ -4667,8 +4673,7 @@ SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches) return 0.0f; } - return (float)(SDL_sqrt((double)hpix * (double)hpix + (double)vpix * (double)vpix) / - SDL_sqrt((double)den2)); + return (float)(SDL_sqrt((double)hpix * (double)hpix + (double)vpix * (double)vpix) / SDL_sqrt((double)den2)); } /* @@ -4724,7 +4729,7 @@ void SDL_OnApplicationDidBecomeActive(void) int SDL_Vulkan_LoadLibrary(const char *path) { int retval; - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return -1; } @@ -4747,7 +4752,7 @@ int SDL_Vulkan_LoadLibrary(const char *path) void *SDL_Vulkan_GetVkGetInstanceProcAddr(void) { - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return NULL; } @@ -4760,7 +4765,7 @@ void *SDL_Vulkan_GetVkGetInstanceProcAddr(void) void SDL_Vulkan_UnloadLibrary(void) { - if (!_this) { + if (_this == NULL) { SDL_UninitializedVideo(); return; } @@ -4779,14 +4784,13 @@ SDL_bool SDL_Vulkan_GetInstanceExtensions(SDL_Window *window, unsigned *count, c if (window) { CHECK_WINDOW_MAGIC(window, SDL_FALSE); - if (!(window->flags & SDL_WINDOW_VULKAN)) - { + if (!(window->flags & SDL_WINDOW_VULKAN)) { SDL_SetError(NOT_A_VULKAN_WINDOW); return SDL_FALSE; } } - if (!count) { + if (count == NULL) { SDL_InvalidParamError("count"); return SDL_FALSE; } @@ -4810,7 +4814,7 @@ SDL_bool SDL_Vulkan_CreateSurface(SDL_Window *window, return SDL_FALSE; } - if (!surface) { + if (surface == NULL) { SDL_InvalidParamError("surface"); return SDL_FALSE; } diff --git a/src/video/SDL_vulkan_utils.c b/src/video/SDL_vulkan_utils.c index 4a3170767f..b41e1abe7b 100644 --- a/src/video/SDL_vulkan_utils.c +++ b/src/video/SDL_vulkan_utils.c @@ -148,7 +148,7 @@ VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList( retval = SDL_calloc(count, sizeof(VkExtensionProperties)); } - if (!retval) { + if (retval == NULL) { SDL_OutOfMemory(); return NULL; } @@ -248,7 +248,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, } physicalDevices = SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount); - if (!physicalDevices) { + if (physicalDevices == NULL) { SDL_OutOfMemory(); goto error; } @@ -291,7 +291,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, } displayProperties = SDL_malloc(sizeof(VkDisplayPropertiesKHR) * displayPropertiesCount); - if (!displayProperties) { + if (displayProperties == NULL) { SDL_OutOfMemory(); goto error; } @@ -313,15 +313,14 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, /* Get display mode properties for the chosen display */ result = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, NULL); - if (result != VK_SUCCESS || displayModePropertiesCount == 0) - { + if (result != VK_SUCCESS || displayModePropertiesCount == 0) { SDL_SetError("Error enumerating display modes"); goto error; } SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of display modes: %u", displayModePropertiesCount); displayModeProperties = SDL_malloc(sizeof(VkDisplayModePropertiesKHR) * displayModePropertiesCount); - if (!displayModeProperties) { + if (displayModeProperties == NULL) { SDL_OutOfMemory(); goto error; } @@ -368,7 +367,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of display planes: %u", displayPlanePropertiesCount); displayPlaneProperties = SDL_malloc(sizeof(VkDisplayPlanePropertiesKHR) * displayPlanePropertiesCount); - if (!displayPlaneProperties) { + if (displayPlaneProperties == NULL) { SDL_OutOfMemory(); goto error; } @@ -399,7 +398,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of supported displays for plane %u: %u", i, planeSupportedDisplaysCount); planeSupportedDisplays = SDL_malloc(sizeof(VkDisplayKHR) * planeSupportedDisplaysCount); - if (!planeSupportedDisplays) { + if (planeSupportedDisplays == NULL) { SDL_free(displayPlaneProperties); SDL_OutOfMemory(); goto error; @@ -413,8 +412,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, goto error; } - for (j = 0; j < planeSupportedDisplaysCount && planeSupportedDisplays[j] != display; ++j) - { + for (j = 0; j < planeSupportedDisplaysCount && planeSupportedDisplays[j] != display; ++j) { } SDL_free(planeSupportedDisplays); diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c index 686d94e142..f7eaebbdf8 100644 --- a/src/video/SDL_yuv.c +++ b/src/video/SDL_yuv.c @@ -76,17 +76,12 @@ static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type) static SDL_bool IsPlanar2x2Format(Uint32 format) { - return (format == SDL_PIXELFORMAT_YV12 || - format == SDL_PIXELFORMAT_IYUV || - format == SDL_PIXELFORMAT_NV12 || - format == SDL_PIXELFORMAT_NV21); + return format == SDL_PIXELFORMAT_YV12 || format == SDL_PIXELFORMAT_IYUV || format == SDL_PIXELFORMAT_NV12 || format == SDL_PIXELFORMAT_NV21; } static SDL_bool IsPacked4Format(Uint32 format) { - return (format == SDL_PIXELFORMAT_YUY2 || - format == SDL_PIXELFORMAT_UYVY || - format == SDL_PIXELFORMAT_YVYU); + return format == SDL_PIXELFORMAT_YUY2 || format == SDL_PIXELFORMAT_UYVY || format == SDL_PIXELFORMAT_YVYU; } static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, int yuv_pitch, @@ -627,8 +622,7 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr next_row = (const Uint8*)src; next_row += src_pitch; - if (dst_format == SDL_PIXELFORMAT_YV12 || dst_format == SDL_PIXELFORMAT_IYUV) - { + if (dst_format == SDL_PIXELFORMAT_YV12 || dst_format == SDL_PIXELFORMAT_IYUV) { /* Write UV planes, not interleaved */ uv_skip = (uv_stride - (width + 1)/2); for (j = 0; j < height_half; j++) { @@ -661,9 +655,7 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr plane_u += uv_skip; plane_v += uv_skip; } - } - else if (dst_format == SDL_PIXELFORMAT_NV12) - { + } else if (dst_format == SDL_PIXELFORMAT_NV12) { uv_skip = (uv_stride - ((width + 1)/2)*2); for (j = 0; j < height_half; j++) { for (i = 0; i < width_half; i++) { @@ -692,9 +684,7 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr *plane_interleaved_uv++ = MAKE_V(r, g, b); } } - } - else /* dst_format == SDL_PIXELFORMAT_NV21 */ - { + } else /* dst_format == SDL_PIXELFORMAT_NV21 */ { uv_skip = (uv_stride - ((width + 1)/2)*2); for (j = 0; j < height_half; j++) { for (i = 0; i < width_half; i++) { @@ -742,8 +732,7 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr plane_skip = (dst_pitch - row_size); /* Write YUV plane, packed */ - if (dst_format == SDL_PIXELFORMAT_YUY2) - { + if (dst_format == SDL_PIXELFORMAT_YUY2) { for (j = 0; j < height; j++) { for (i = 0; i < width_half; i++) { READ_TWO_RGB_PIXELS; @@ -764,9 +753,7 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr plane += plane_skip; curr_row += src_pitch; } - } - else if (dst_format == SDL_PIXELFORMAT_UYVY) - { + } else if (dst_format == SDL_PIXELFORMAT_UYVY) { for (j = 0; j < height; j++) { for (i = 0; i < width_half; i++) { READ_TWO_RGB_PIXELS; @@ -787,9 +774,7 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr plane += plane_skip; curr_row += src_pitch; } - } - else if (dst_format == SDL_PIXELFORMAT_YVYU) - { + } else if (dst_format == SDL_PIXELFORMAT_YVYU) { for (j = 0; j < height; j++) { for (i = 0; i < width_half; i++) { READ_TWO_RGB_PIXELS; @@ -960,7 +945,7 @@ SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src, int src_p /* Allocate a temporary row for the swap */ tmp = (Uint8 *)SDL_malloc(UVwidth); - if (!tmp) { + if (tmp == NULL) { return SDL_OutOfMemory(); } for (y = 0; y < UVheight; ++y) { @@ -1021,7 +1006,7 @@ SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const void *src, int if (src == dst) { /* Need to make a copy of the buffer so we don't clobber it while converting */ tmp = (Uint8 *)SDL_malloc(2*UVheight*srcUVPitch); - if (!tmp) { + if (tmp == NULL) { return SDL_OutOfMemory(); } SDL_memcpy(tmp, src, 2*UVheight*srcUVPitch); @@ -1095,7 +1080,7 @@ SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const void *src, in if (src == dst) { /* Need to make a copy of the buffer so we don't clobber it while converting */ tmp = (Uint8 *)SDL_malloc(UVheight*srcUVPitch); - if (!tmp) { + if (tmp == NULL) { return SDL_OutOfMemory(); } SDL_memcpy(tmp, src, UVheight*srcUVPitch); @@ -1267,7 +1252,8 @@ SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height, default: break; } - return SDL_SetError("SDL_ConvertPixels_Planar2x2_to_Planar2x2: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format)); + return SDL_SetError("SDL_ConvertPixels_Planar2x2_to_Planar2x2: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), + SDL_GetPixelFormatName(dst_format)); } #ifdef __SSE2__ @@ -1580,7 +1566,8 @@ SDL_ConvertPixels_Packed4_to_Packed4(int width, int height, default: break; } - return SDL_SetError("SDL_ConvertPixels_Packed4_to_Packed4: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format)); + return SDL_SetError("SDL_ConvertPixels_Packed4_to_Packed4: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), + SDL_GetPixelFormatName(dst_format)); } static int @@ -1883,7 +1870,8 @@ SDL_ConvertPixels_YUV_to_YUV(int width, int height, } else if (IsPacked4Format(src_format) && IsPlanar2x2Format(dst_format)) { return SDL_ConvertPixels_Packed4_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch); } else { - return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format)); + return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), + SDL_GetPixelFormatName(dst_format)); } #else return SDL_SetError("SDL not built with YUV support"); diff --git a/src/video/android/SDL_androidkeyboard.c b/src/video/android/SDL_androidkeyboard.c index 3a05eb445d..07f9672c4c 100644 --- a/src/video/android/SDL_androidkeyboard.c +++ b/src/video/android/SDL_androidkeyboard.c @@ -369,7 +369,7 @@ Android_SetTextInputRect(_THIS, const SDL_Rect *rect) { SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; - if (!rect) { + if (rect == NULL) { SDL_InvalidParamError("rect"); return; } diff --git a/src/video/android/SDL_androidmouse.c b/src/video/android/SDL_androidmouse.c index 36d19f8fe9..386c777d4c 100644 --- a/src/video/android/SDL_androidmouse.c +++ b/src/video/android/SDL_androidmouse.c @@ -91,7 +91,7 @@ Android_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) SDL_Surface *converted; converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0); - if (!converted) { + if (converted == NULL) { return NULL; } custom_cursor = Android_JNI_CreateCustomCursor(converted, hot_x, hot_y); @@ -123,7 +123,7 @@ Android_FreeCursor(SDL_Cursor * cursor) static SDL_Cursor * Android_CreateEmptyCursor() { - if (!empty_cursor) { + if (empty_cursor == NULL) { SDL_Surface *empty_surface = SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_ARGB8888); if (empty_surface) { SDL_memset(empty_surface->pixels, 0, empty_surface->h * empty_surface->pitch); @@ -146,7 +146,7 @@ Android_DestroyEmptyCursor() static int Android_ShowCursor(SDL_Cursor *cursor) { - if (!cursor) { + if (cursor == NULL) { cursor = Android_CreateEmptyCursor(); } if (cursor) { @@ -228,7 +228,7 @@ Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL int changes; Uint8 button; - if (!window) { + if (window == NULL) { return; } diff --git a/src/video/android/SDL_androidtouch.c b/src/video/android/SDL_androidtouch.c index c30eaa99b5..1ec076c149 100644 --- a/src/video/android/SDL_androidtouch.c +++ b/src/video/android/SDL_androidtouch.c @@ -52,7 +52,7 @@ void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_fin SDL_TouchID touchDeviceId = 0; SDL_FingerID fingerId = 0; - if (!window) { + if (window == NULL) { return; } diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index ef652f7f15..ebe1ecf741 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -89,13 +89,13 @@ Android_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); return NULL; } data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - if (!data) { + if (data == NULL) { SDL_OutOfMemory(); SDL_free(device); return NULL; @@ -280,8 +280,7 @@ void Android_SendResize(SDL_Window *window) which can happen after VideoInit(). */ SDL_VideoDevice *device = SDL_GetVideoDevice(); - if (device && device->num_displays > 0) - { + if (device && device->num_displays > 0) { SDL_VideoDisplay *display = &device->displays[0]; display->desktop_mode.format = Android_ScreenFormat; display->desktop_mode.w = Android_DeviceWidth; diff --git a/src/video/android/SDL_androidvulkan.c b/src/video/android/SDL_androidvulkan.c index 4e950d0899..78f64c82cb 100644 --- a/src/video/android/SDL_androidvulkan.c +++ b/src/video/android/SDL_androidvulkan.c @@ -43,51 +43,56 @@ int Android_Vulkan_LoadLibrary(_THIS, const char *path) SDL_bool hasSurfaceExtension = SDL_FALSE; SDL_bool hasAndroidSurfaceExtension = SDL_FALSE; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; - if(_this->vulkan_config.loader_handle) + if (_this->vulkan_config.loader_handle) { return SDL_SetError("Vulkan already loaded"); + } /* Load the Vulkan loader library */ - if(!path) + if (path == NULL) { path = SDL_getenv("SDL_VULKAN_LIBRARY"); - if(!path) + } + if (path == NULL) { path = "libvulkan.so"; + } _this->vulkan_config.loader_handle = SDL_LoadObject(path); - if(!_this->vulkan_config.loader_handle) + if (!_this->vulkan_config.loader_handle) { return -1; + } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); - if(!vkGetInstanceProcAddr) + if (!vkGetInstanceProcAddr) { goto fail; + } _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr; _this->vulkan_config.vkEnumerateInstanceExtensionProperties = (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)( VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties"); - if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) + if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) { goto fail; + } extensions = SDL_Vulkan_CreateInstanceExtensionsList( (PFN_vkEnumerateInstanceExtensionProperties) _this->vulkan_config.vkEnumerateInstanceExtensionProperties, &extensionCount); - if(!extensions) + if (extensions == NULL) { goto fail; - for(i = 0; i < extensionCount; i++) + } + for (i = 0; i < extensionCount; i++) { - if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasSurfaceExtension = SDL_TRUE; - else if(SDL_strcmp(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + } else if (SDL_strcmp(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasAndroidSurfaceExtension = SDL_TRUE; + } } SDL_free(extensions); - if(!hasSurfaceExtension) - { + if (!hasSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension"); goto fail; - } - else if(!hasAndroidSurfaceExtension) - { + } else if (!hasAndroidSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "extension"); goto fail; @@ -102,8 +107,7 @@ fail: void Android_Vulkan_UnloadLibrary(_THIS) { - if(_this->vulkan_config.loader_handle) - { + if (_this->vulkan_config.loader_handle) { SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; } @@ -117,8 +121,7 @@ SDL_bool Android_Vulkan_GetInstanceExtensions(_THIS, static const char *const extensionsForAndroid[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME }; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } @@ -142,14 +145,12 @@ SDL_bool Android_Vulkan_CreateSurface(_THIS, VkAndroidSurfaceCreateInfoKHR createInfo; VkResult result; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } - if(!vkCreateAndroidSurfaceKHR) - { + if (!vkCreateAndroidSurfaceKHR) { SDL_SetError(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); return SDL_FALSE; @@ -161,8 +162,7 @@ SDL_bool Android_Vulkan_CreateSurface(_THIS, createInfo.window = windowData->native_window; result = vkCreateAndroidSurfaceKHR(instance, &createInfo, NULL, surface); - if(result != VK_SUCCESS) - { + if (result != VK_SUCCESS) { SDL_SetError("vkCreateAndroidSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); return SDL_FALSE; diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index d7dea39238..d576d6e8d0 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -67,7 +67,7 @@ Android_CreateWindow(_THIS, SDL_Window * window) SDL_SetKeyboardFocus(window); data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { retval = SDL_OutOfMemory(); goto endfunction; } @@ -136,7 +136,7 @@ Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display } data = (SDL_WindowData *)window->driverdata; - if (!data || !data->native_window) { + if (data == NULL || !data->native_window) { if (data && !data->native_window) { SDL_SetError("Missing native window"); } diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c index dd7cbbd165..16b5db8de6 100644 --- a/src/video/dummy/SDL_nullframebuffer.c +++ b/src/video/dummy/SDL_nullframebuffer.c @@ -40,7 +40,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * forma /* Create a new one */ SDL_GetWindowSize(window, &w, &h); surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format); - if (!surface) { + if (surface == NULL) { return -1; } @@ -58,7 +58,7 @@ int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect SDL_Surface *surface; surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE); - if (!surface) { + if (surface == NULL) { return SDL_SetError("Couldn't find dummy surface for window"); } diff --git a/src/video/dummy/SDL_nullvideo.c b/src/video/dummy/SDL_nullvideo.c index fc0af1553f..219d352460 100644 --- a/src/video/dummy/SDL_nullvideo.c +++ b/src/video/dummy/SDL_nullvideo.c @@ -90,14 +90,14 @@ DUMMY_CreateDevice(void) SDL_VideoDevice *device; if (!DUMMY_Available()) { - return (0); + return 0; } /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); - return (0); + return 0; } device->is_dummy = SDL_TRUE; diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 0fe0bdcbbf..ad9f41e56e 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -772,8 +772,9 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo SDL_FingerID id; float x, y; - if (!touchEvent->touches[i].isChanged) + if (!touchEvent->touches[i].isChanged) { continue; + } id = touchEvent->touches[i].identifier; x = touchEvent->touches[i].targetX / client_w; @@ -857,14 +858,11 @@ Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChang SDL_WindowData *window_data = userData; SDL_VideoDisplay *display; - if(fullscreenChangeEvent->isFullscreen) - { + if (fullscreenChangeEvent->isFullscreen) { window_data->window->flags |= window_data->requested_fullscreen_mode; window_data->requested_fullscreen_mode = 0; - } - else - { + } else { window_data->window->flags &= ~FULLSCREEN_MASK; /* reset fullscreen window if the browser left fullscreen */ @@ -892,15 +890,13 @@ Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *u } } - if(!(window_data->window->flags & FULLSCREEN_MASK)) - { + if (!(window_data->window->flags & FULLSCREEN_MASK)) { /* this will only work if the canvas size is set through css */ - if(window_data->window->flags & SDL_WINDOW_RESIZABLE) - { + if (window_data->window->flags & SDL_WINDOW_RESIZABLE) { double w = window_data->window->w; double h = window_data->window->h; - if(window_data->external_size) { + if (window_data->external_size) { emscripten_get_element_css_size(window_data->canvas_id, &w, &h); } @@ -930,8 +926,7 @@ Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userDat /*this is used during fullscreen changes*/ SDL_WindowData *window_data = userData; - if(window_data->fullscreen_resize) - { + if (window_data->fullscreen_resize) { double css_w, css_h; emscripten_get_element_css_size(window_data->canvas_id, &css_w, &css_h); SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, css_w, css_h); @@ -986,7 +981,9 @@ Emscripten_RegisterEventHandlers(SDL_WindowData *data) /* Keyboard events are awkward */ keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT); - if (!keyElement) keyElement = EMSCRIPTEN_EVENT_TARGET_WINDOW; + if (keyElement == NULL) { + keyElement = EMSCRIPTEN_EVENT_TARGET_WINDOW; + } emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey); emscripten_set_keyup_callback(keyElement, data, 0, Emscripten_HandleKey); @@ -1028,7 +1025,7 @@ Emscripten_UnregisterEventHandlers(SDL_WindowData *data) emscripten_set_pointerlockchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, 0, NULL); target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT); - if (!target) { + if (target == NULL) { target = EMSCRIPTEN_EVENT_TARGET_WINDOW; } diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c index 8c461a9408..138112d22c 100644 --- a/src/video/emscripten/SDL_emscriptenframebuffer.c +++ b/src/video/emscripten/SDL_emscriptenframebuffer.c @@ -46,7 +46,7 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * form SDL_GetWindowSize(window, &w, &h); surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask); - if (!surface) { + if (surface == NULL) { return -1; } @@ -64,7 +64,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec SDL_WindowData *data = (SDL_WindowData *) window->driverdata; surface = data->surface; - if (!surface) { + if (surface == NULL) { return SDL_SetError("Couldn't find framebuffer surface for window"); } diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c index 80c42cb3ed..e674a53b41 100644 --- a/src/video/emscripten/SDL_emscriptenmouse.c +++ b/src/video/emscripten/SDL_emscriptenmouse.c @@ -40,7 +40,7 @@ Emscripten_CreateCursorFromString(const char* cursor_str, SDL_bool is_custom) cursor = SDL_calloc(1, sizeof(SDL_Cursor)); if (cursor) { curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata)); - if (!curdata) { + if (curdata == NULL) { SDL_OutOfMemory(); SDL_free(cursor); return NULL; @@ -49,8 +49,7 @@ Emscripten_CreateCursorFromString(const char* cursor_str, SDL_bool is_custom) curdata->system_cursor = cursor_str; curdata->is_custom = is_custom; cursor->driverdata = curdata; - } - else { + } else { SDL_OutOfMemory(); } @@ -72,7 +71,7 @@ Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y) conv_surf = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ABGR8888, 0); - if (!conv_surf) { + if (conv_surf == NULL) { return NULL; } @@ -185,18 +184,17 @@ Emscripten_ShowCursor(SDL_Cursor* cursor) { Emscripten_CursorData *curdata; if (SDL_GetMouseFocus() != NULL) { - if(cursor && cursor->driverdata) { + if (cursor && cursor->driverdata) { curdata = (Emscripten_CursorData *) cursor->driverdata; - if(curdata->system_cursor) { + if (curdata->system_cursor) { MAIN_THREAD_EM_ASM({ if (Module['canvas']) { Module['canvas'].style['cursor'] = UTF8ToString($0); } }, curdata->system_cursor); } - } - else { + } else { MAIN_THREAD_EM_ASM( if (Module['canvas']) { Module['canvas'].style['cursor'] = 'none'; @@ -220,7 +218,7 @@ Emscripten_SetRelativeMouseMode(SDL_bool enabled) SDL_WindowData *window_data; /* TODO: pointer lock isn't actually enabled yet */ - if(enabled) { + if (enabled) { window = SDL_GetMouseFocus(); if (window == NULL) { return -1; @@ -228,11 +226,11 @@ Emscripten_SetRelativeMouseMode(SDL_bool enabled) window_data = (SDL_WindowData *) window->driverdata; - if(emscripten_request_pointerlock(window_data->canvas_id, 1) >= EMSCRIPTEN_RESULT_SUCCESS) { + if (emscripten_request_pointerlock(window_data->canvas_id, 1) >= EMSCRIPTEN_RESULT_SUCCESS) { return 0; } } else { - if(emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) { + if (emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) { return 0; } } diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index 1ccc485b46..e906918889 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.c +++ b/src/video/emscripten/SDL_emscriptenvideo.c @@ -65,9 +65,9 @@ Emscripten_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); - return (0); + return 0; } /* Firefox sends blur event which would otherwise prevent full screen @@ -310,7 +310,7 @@ Emscripten_DestroyWindow(_THIS, SDL_Window * window) { SDL_WindowData *data; - if(window->driverdata) { + if (window->driverdata) { data = (SDL_WindowData *) window->driverdata; Emscripten_UnregisterEventHandlers(data); @@ -328,19 +328,19 @@ static void Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen) { SDL_WindowData *data; - if(window->driverdata) { + if (window->driverdata) { data = (SDL_WindowData *) window->driverdata; - if(fullscreen) { + if (fullscreen) { EmscriptenFullscreenStrategy strategy; SDL_bool is_desktop_fullscreen = (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP; int res; strategy.scaleMode = is_desktop_fullscreen ? EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH : EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT; - if(!is_desktop_fullscreen) { + if (!is_desktop_fullscreen) { strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE; - } else if(window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { + } else if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF; } else { strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF; @@ -355,12 +355,11 @@ Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * di data->fullscreen_resize = is_desktop_fullscreen; res = emscripten_request_fullscreen_strategy(data->canvas_id, 1, &strategy); - if(res != EMSCRIPTEN_RESULT_SUCCESS && res != EMSCRIPTEN_RESULT_DEFERRED) { + if (res != EMSCRIPTEN_RESULT_SUCCESS && res != EMSCRIPTEN_RESULT_DEFERRED) { /* unset flags, fullscreen failed */ window->flags &= ~(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN); } - } - else + } else emscripten_exit_fullscreen(); } } diff --git a/src/video/haiku/SDL_bclipboard.cc b/src/video/haiku/SDL_bclipboard.cc index 1a3d84a78a..d2d067ffa7 100644 --- a/src/video/haiku/SDL_bclipboard.cc +++ b/src/video/haiku/SDL_bclipboard.cc @@ -36,12 +36,12 @@ extern "C" { int HAIKU_SetClipboardText(_THIS, const char *text) { BMessage *clip = NULL; - if(be_clipboard->Lock()) { + if (be_clipboard->Lock()) { be_clipboard->Clear(); - if((clip = be_clipboard->Data())) { + if ((clip = be_clipboard->Data())) { /* Presumably the string of characters is ascii-format */ ssize_t asciiLength = 0; - for(; text[asciiLength] != 0; ++asciiLength) {} + for (; text[asciiLength] != 0; ++asciiLength) {} clip->AddData("text/plain", B_MIME_TYPE, text, asciiLength); be_clipboard->Commit(); } @@ -55,8 +55,8 @@ char *HAIKU_GetClipboardText(_THIS) { const char *text = NULL; ssize_t length; char *result; - if(be_clipboard->Lock()) { - if((clip = be_clipboard->Data())) { + if (be_clipboard->Lock()) { + if ((clip = be_clipboard->Data())) { /* Presumably the string of characters is ascii-format */ clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text, &length); @@ -64,7 +64,7 @@ char *HAIKU_GetClipboardText(_THIS) { be_clipboard->Unlock(); } - if (!text) { + if (text == NULL) { result = SDL_strdup(""); } else { /* Copy the data and pass on to SDL */ diff --git a/src/video/haiku/SDL_bframebuffer.cc b/src/video/haiku/SDL_bframebuffer.cc index f303177cbf..361f620cdb 100644 --- a/src/video/haiku/SDL_bframebuffer.cc +++ b/src/video/haiku/SDL_bframebuffer.cc @@ -36,11 +36,11 @@ extern "C" { #endif static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { - return ((SDL_BWin*)(window->driverdata)); + return (SDL_BWin *)(window->driverdata); } static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); + return (SDL_BApp *)be_app; } int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window, @@ -48,7 +48,7 @@ int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window, void ** pixels, int *pitch) { SDL_BWin *bwin = _ToBeWin(window); BScreen bscreen; - if(!bscreen.IsValid()) { + if (!bscreen.IsValid()) { return -1; } @@ -65,14 +65,14 @@ int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window, /* Create the new bitmap object */ BBitmap *bitmap = bwin->GetBitmap(); - if(bitmap) { + if (bitmap) { delete bitmap; } bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space, false, /* Views not accepted */ true); /* Contiguous memory required */ - if(bitmap->InitCheck() != B_OK) { + if (bitmap->InitCheck() != B_OK) { delete bitmap; return SDL_SetError("Could not initialize back buffer!"); } @@ -94,8 +94,9 @@ int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window, int HAIKU_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { - if(!window) + if (window == NULL) { return 0; + } SDL_BWin *bwin = _ToBeWin(window); diff --git a/src/video/haiku/SDL_bkeyboard.cc b/src/video/haiku/SDL_bkeyboard.cc index 0369987271..ee43438c5e 100644 --- a/src/video/haiku/SDL_bkeyboard.cc +++ b/src/video/haiku/SDL_bkeyboard.cc @@ -40,11 +40,11 @@ static SDL_Scancode keymap[KEYMAP_SIZE]; static int8 keystate[KEYMAP_SIZE]; void HAIKU_InitOSKeymap(void) { - for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) { + for ( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) { keymap[i] = SDL_SCANCODE_UNKNOWN; } - for( uint i = 0; i < KEYMAP_SIZE; ++i ) { + for ( uint i = 0; i < KEYMAP_SIZE; ++i ) { keystate[i] = SDL_RELEASED; } @@ -158,7 +158,7 @@ void HAIKU_InitOSKeymap(void) { } SDL_Scancode HAIKU_GetScancodeFromBeKey(int32 bkey) { - if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) { + if (bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) { return keymap[bkey]; } else { return SDL_SCANCODE_UNKNOWN; @@ -166,7 +166,7 @@ SDL_Scancode HAIKU_GetScancodeFromBeKey(int32 bkey) { } int8 HAIKU_GetKeyState(int32 bkey) { - if(bkey > 0 && bkey < KEYMAP_SIZE) { + if (bkey > 0 && bkey < KEYMAP_SIZE) { return keystate[bkey]; } else { return SDL_RELEASED; @@ -174,7 +174,7 @@ int8 HAIKU_GetKeyState(int32 bkey) { } void HAIKU_SetKeyState(int32 bkey, int8 state) { - if(bkey > 0 && bkey < KEYMAP_SIZE) { + if (bkey > 0 && bkey < KEYMAP_SIZE) { keystate[bkey] = state; } } diff --git a/src/video/haiku/SDL_bmessagebox.cc b/src/video/haiku/SDL_bmessagebox.cc index ab95e41d2d..38a1ebf564 100644 --- a/src/video/haiku/SDL_bmessagebox.cc +++ b/src/video/haiku/SDL_bmessagebox.cc @@ -130,25 +130,20 @@ class HAIKU_SDL_MessageBox : public BAlert void ParseSdlMessageBoxData(const SDL_MessageBoxData *aMessageBoxData) { - if (aMessageBoxData == NULL) - { + if (aMessageBoxData == NULL) { SetTitle(HAIKU_SDL_DefTitle); SetMessageText(HAIKU_SDL_DefMessage); AddButton(HAIKU_SDL_DefButton); return; } - if (aMessageBoxData->numbuttons <= 0) - { + if (aMessageBoxData->numbuttons <= 0) { AddButton(HAIKU_SDL_DefButton); - } - else - { + } else { AddSdlButtons(aMessageBoxData->buttons, aMessageBoxData->numbuttons); } - if (aMessageBoxData->colorScheme != NULL) - { + if (aMessageBoxData->colorScheme != NULL) { fCustomColorScheme = true; ApplyAndParseColorScheme(aMessageBoxData->colorScheme); } @@ -178,11 +173,9 @@ class HAIKU_SDL_MessageBox : public BAlert const SDL_MessageBoxColor *aTextColor, const SDL_MessageBoxColor *aSelectedColor) { - if (fCustomColorScheme) - { + if (fCustomColorScheme) { int32 countButtons = CountButtons(); - for (int i = 0; i < countButtons; ++i) - { + for (int i = 0; i < countButtons; ++i) { ButtonAt(i)->SetViewColor(ConvertColorType(aBorderColor)); ButtonAt(i)->SetLowColor(ConvertColorType(aBackgroundColor)); @@ -217,15 +210,12 @@ class HAIKU_SDL_MessageBox : public BAlert BString message = aMessage; int32 length = message.CountChars(); - for (int i = 0, c = 0; i < length; ++i) - { + for (int i = 0, c = 0; i < length; ++i) { c++; - if (*(message.CharAt(i)) == '\n') - { + if (*(message.CharAt(i)) == '\n') { c = 0; } - if (c > final) - { + if (c > final) { final = c; } } @@ -237,20 +227,17 @@ class HAIKU_SDL_MessageBox : public BAlert SetMessageText(const char *aMessage) { fThereIsLongLine = CheckLongLines(aMessage); - if (fThereIsLongLine) - { + if (fThereIsLongLine) { fMessageBoxTextView->SetWordWrap(true); } rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR); - if (fCustomColorScheme) - { + if (fCustomColorScheme) { textColor = fTextColor; } /* - if (fNoTitledWindow) - { + if (fNoTitledWindow) { fMessageBoxTextView->SetFontAndColor(be_bold_font); fMessageBoxTextView->Insert(fTitle); fMessageBoxTextView->Insert("\n\n"); @@ -268,16 +255,14 @@ class HAIKU_SDL_MessageBox : public BAlert void AddSdlButtons(const SDL_MessageBoxButtonData *aButtons, int aNumButtons) { - for (int i = 0; i < aNumButtons; ++i) - { + for (int i = 0; i < aNumButtons; ++i) { fButtons.push_back(&aButtons[i]); } std::sort(fButtons.begin(), fButtons.end(), &HAIKU_SDL_MessageBox::SortButtonsPredicate); size_t countButtons = fButtons.size(); - for (size_t i = 0; i < countButtons; ++i) - { + for (size_t i = 0; i < countButtons; ++i) { switch (fButtons[i]->flags) { case SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT: @@ -341,12 +326,9 @@ protected: virtual void FrameResized(float aNewWidth, float aNewHeight) { - if (fComputedMessageBoxWidth > aNewWidth) - { + if (fComputedMessageBoxWidth > aNewWidth) { ResizeTo(fComputedMessageBoxWidth, aNewHeight); - } - else - { + } else { BAlert::FrameResized(aNewWidth, aNewHeight); } } @@ -374,38 +356,32 @@ HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) // "You need a valid BApplication object before interacting with the app_server." // "2 BApplication objects were created. Only one is allowed." BApplication *application = NULL; - if (be_app == NULL) - { + if (be_app == NULL) { application = new(std::nothrow) BApplication(signature); - if (application == NULL) - { + if (application == NULL) { return SDL_SetError("Cannot create the BApplication object. Lack of memory?"); } } HAIKU_SDL_MessageBox *SDL_MessageBox = new(std::nothrow) HAIKU_SDL_MessageBox(messageboxdata); - if (SDL_MessageBox == NULL) - { + if (SDL_MessageBox == NULL) { return SDL_SetError("Cannot create the HAIKU_SDL_MessageBox (BAlert inheritor) object. Lack of memory?"); } const int closeButton = SDL_MessageBox->GetCloseButtonId(); int pushedButton = SDL_MessageBox->Go(); // The close button is equivalent to pressing Escape. - if (closeButton != G_CLOSE_BUTTON_ID && pushedButton == G_CLOSE_BUTTON_ID) - { + if (closeButton != G_CLOSE_BUTTON_ID && pushedButton == G_CLOSE_BUTTON_ID) { pushedButton = closeButton; } // It's deleted by itself after the "Go()" method was executed. /* - if (messageBox != NULL) - { + if (messageBox != NULL) { delete messageBox; } */ - if (application != NULL) - { + if (application != NULL) { delete application; } diff --git a/src/video/haiku/SDL_bmodes.cc b/src/video/haiku/SDL_bmodes.cc index 5e51647ca1..8fc6bfdac7 100644 --- a/src/video/haiku/SDL_bmodes.cc +++ b/src/video/haiku/SDL_bmodes.cc @@ -49,18 +49,18 @@ struct SDL_DisplayModeData { #endif static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { - return ((SDL_BWin*)(window->driverdata)); + return (SDL_BWin *)(window->driverdata); } static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); + return (SDL_BApp *)be_app; } static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) { #if WRAP_BMODE - return ((SDL_DisplayModeData*)mode->driverdata)->bmode; + return ((SDL_DisplayModeData *)mode->driverdata)->bmode; #else - return (display_mode*)(mode->driverdata); + return (display_mode *)(mode->driverdata); #endif } @@ -80,24 +80,24 @@ void _SpoutModeData(display_mode *bmode) { printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height); printf("\th,v = (%i,%i)\n", bmode->h_display_start, bmode->v_display_start); - if(bmode->flags) { + if (bmode->flags) { printf("\tFlags:\n"); - if(bmode->flags & B_SCROLL) { + if (bmode->flags & B_SCROLL) { printf("\t\tB_SCROLL\n"); } - if(bmode->flags & B_8_BIT_DAC) { + if (bmode->flags & B_8_BIT_DAC) { printf("\t\tB_8_BIT_DAC\n"); } - if(bmode->flags & B_HARDWARE_CURSOR) { + if (bmode->flags & B_HARDWARE_CURSOR) { printf("\t\tB_HARDWARE_CURSOR\n"); } - if(bmode->flags & B_PARALLEL_ACCESS) { + if (bmode->flags & B_PARALLEL_ACCESS) { printf("\t\tB_PARALLEL_ACCESS\n"); } - if(bmode->flags & B_DPMS) { + if (bmode->flags & B_DPMS) { printf("\t\tB_DPMS\n"); } - if(bmode->flags & B_IO_FB_NA) { + if (bmode->flags & B_IO_FB_NA) { printf("\t\tB_IO_FB_NA\n"); } } @@ -109,21 +109,21 @@ void _SpoutModeData(display_mode *bmode) { printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n", bmode->timing.v_display, bmode->timing.v_sync_start, bmode->timing.v_sync_end, bmode->timing.v_total); - if(bmode->timing.flags) { + if (bmode->timing.flags) { printf("\t\tFlags:\n"); - if(bmode->timing.flags & B_BLANK_PEDESTAL) { + if (bmode->timing.flags & B_BLANK_PEDESTAL) { printf("\t\t\tB_BLANK_PEDESTAL\n"); } - if(bmode->timing.flags & B_TIMING_INTERLACED) { + if (bmode->timing.flags & B_TIMING_INTERLACED) { printf("\t\t\tB_TIMING_INTERLACED\n"); } - if(bmode->timing.flags & B_POSITIVE_HSYNC) { + if (bmode->timing.flags & B_POSITIVE_HSYNC) { printf("\t\t\tB_POSITIVE_HSYNC\n"); } - if(bmode->timing.flags & B_POSITIVE_VSYNC) { + if (bmode->timing.flags & B_POSITIVE_VSYNC) { printf("\t\t\tB_POSITIVE_VSYNC\n"); } - if(bmode->timing.flags & B_SYNC_ON_GREEN) { + if (bmode->timing.flags & B_SYNC_ON_GREEN) { printf("\t\t\tB_SYNC_ON_GREEN\n"); } } @@ -247,7 +247,7 @@ void HAIKU_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { bscreen.GetModeList(&bmodes, &count); bscreen.GetMode(&this_bmode); - for(i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) { // FIXME: Apparently there are errors with colorspace changes if (bmodes[i].space == this_bmode.space) { _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode); @@ -258,10 +258,10 @@ void HAIKU_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { } -int HAIKU_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ +int HAIKU_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { /* Get the current screen */ BScreen bscreen; - if(!bscreen.IsValid()) { + if (!bscreen.IsValid()) { printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__); } @@ -273,8 +273,8 @@ int HAIKU_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode uint32 c = 0, i; display_mode *bmode_list; bscreen.GetModeList(&bmode_list, &c); - for(i = 0; i < c; ++i) { - if( bmode_list[i].space == bmode->space && + for (i = 0; i < c; ++i) { + if ( bmode_list[i].space == bmode->space && bmode_list[i].virtual_width == bmode->virtual_width && bmode_list[i].virtual_height == bmode->virtual_height ) { bmode = &bmode_list[i]; @@ -282,7 +282,7 @@ int HAIKU_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode } } - if(bscreen.SetMode(bmode) != B_OK) { + if (bscreen.SetMode(bmode) != B_OK) { return SDL_SetError("Bad video mode"); } diff --git a/src/video/haiku/SDL_bopengl.cc b/src/video/haiku/SDL_bopengl.cc index 72bdb77f48..76751a6471 100644 --- a/src/video/haiku/SDL_bopengl.cc +++ b/src/video/haiku/SDL_bopengl.cc @@ -36,11 +36,11 @@ extern "C" { static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { - return ((SDL_BWin*)(window->driverdata)); + return (SDL_BWin *)(window->driverdata); } static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); + return (SDL_BApp *)be_app; } /* Passing a NULL path means load pointers from the application */ @@ -51,7 +51,7 @@ int HAIKU_GL_LoadLibrary(_THIS, const char *path) int32 cookie = 0; while (get_next_image_info(0, &cookie, &info) == B_OK) { void *location = NULL; - if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY, + if ( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY, &location) == B_OK) { _this->gl_config.dll_handle = (void *) (addr_t) info.id; @@ -175,9 +175,9 @@ void HAIKU_GL_UnloadLibrary(_THIS) { currently in use. */ void HAIKU_GL_RebootContexts(_THIS) { SDL_Window *window = _this->windows; - while(window) { + while (window) { SDL_BWin *bwin = _ToBeWin(window); - if(bwin->GetGLView()) { + if (bwin->GetGLView()) { bwin->LockLooper(); bwin->RemoveGLView(); bwin->CreateGLView(bwin->GetGLType()); diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index 3c7968b90d..a09118c7ac 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -41,7 +41,7 @@ extern "C" { #include "SDL_bevents.h" static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { - return ((SDL_BWin*)(window->driverdata)); + return (SDL_BWin *)(window->driverdata); } /* FIXME: Undefined functions */ @@ -196,7 +196,7 @@ HAIKU_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) SDL_Surface *converted; converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0); - if (!converted) { + if (converted == NULL) { return NULL; } @@ -218,8 +218,9 @@ static int HAIKU_ShowCursor(SDL_Cursor *cursor) { SDL_Mouse *mouse = SDL_GetMouse(); - if (!mouse) + if (mouse == NULL) { return 0; + } if (cursor) { BCursor *hCursor = (BCursor*)cursor->driverdata; @@ -237,7 +238,7 @@ static int HAIKU_SetRelativeMouseMode(SDL_bool enabled) { SDL_Window *window = SDL_GetMouseFocus(); - if (!window) { + if (window == NULL) { return 0; } @@ -257,8 +258,9 @@ HAIKU_SetRelativeMouseMode(SDL_bool enabled) static void HAIKU_MouseInit(_THIS) { SDL_Mouse *mouse = SDL_GetMouse(); - if (!mouse) + if (mouse == NULL) { return; + } mouse->CreateCursor = HAIKU_CreateCursor; mouse->CreateSystemCursor = HAIKU_CreateSystemCursor; mouse->ShowCursor = HAIKU_ShowCursor; @@ -290,7 +292,7 @@ int HAIKU_VideoInit(_THIS) #endif /* We're done! */ - return (0); + return 0; } void HAIKU_VideoQuit(_THIS) @@ -307,7 +309,7 @@ int HAIKU_OpenURL(const char *url) { BUrl burl(url); const status_t rc = burl.OpenWithPreferredApplication(false); - return (rc == B_NO_ERROR) ? 0 : SDL_SetError("URL open failed (err=%d)", (int) rc); + return (rc == B_NO_ERROR) ? 0 : SDL_SetError("URL open failed (err=%d)", (int)rc); } #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bwindow.cc b/src/video/haiku/SDL_bwindow.cc index 26cdb7c29b..b8742c9b51 100644 --- a/src/video/haiku/SDL_bwindow.cc +++ b/src/video/haiku/SDL_bwindow.cc @@ -34,11 +34,11 @@ extern "C" { #endif static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { - return ((SDL_BWin*)(window->driverdata)); + return (SDL_BWin *)(window->driverdata); } static SDL_INLINE SDL_BApp *_GetBeApp() { - return ((SDL_BApp*)be_app); + return (SDL_BApp *)be_app; } static int _InitWindow(_THIS, SDL_Window *window) { @@ -52,23 +52,24 @@ static int _InitWindow(_THIS, SDL_Window *window) { window->y + window->h - 1 ); - if(window->flags & SDL_WINDOW_FULLSCREEN) { + if (window->flags & SDL_WINDOW_FULLSCREEN) { /* TODO: Add support for this flag */ printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__); } - if(window->flags & SDL_WINDOW_OPENGL) { + if (window->flags & SDL_WINDOW_OPENGL) { /* TODO: Add support for this flag */ } - if(!(window->flags & SDL_WINDOW_RESIZABLE)) { + if (!(window->flags & SDL_WINDOW_RESIZABLE)) { flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE; } - if(window->flags & SDL_WINDOW_BORDERLESS) { + if (window->flags & SDL_WINDOW_BORDERLESS) { look = B_NO_BORDER_WINDOW_LOOK; } SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags); - if(bwin == NULL) + if (bwin == NULL) { return -1; + } window->driverdata = bwin; int32 winID = _GetBeApp()->GetID(window); @@ -90,8 +91,9 @@ int HAIKU_CreateWindow(_THIS, SDL_Window *window) { int HAIKU_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { SDL_BWin *otherBWin = (SDL_BWin*)data; - if(!otherBWin->LockLooper()) + if (!otherBWin->LockLooper()) { return -1; + } /* Create the new window and initialize its members */ window->x = (int)otherBWin->Frame().left; @@ -100,7 +102,7 @@ int HAIKU_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { window->h = (int)otherBWin->Frame().Height(); /* Set SDL flags */ - if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) { + if (!(otherBWin->Flags() & B_NOT_RESIZABLE)) { window->flags |= SDL_WINDOW_RESIZABLE; } @@ -195,7 +197,7 @@ void HAIKU_SetWindowFullscreen(_THIS, SDL_Window * window, } -void HAIKU_SetWindowMinimumSize(_THIS, SDL_Window * window){ +void HAIKU_SetWindowMinimumSize(_THIS, SDL_Window * window) { BMessage msg(BWIN_MINIMUM_SIZE_WINDOW); msg.AddInt32("window-w", window->w -1); msg.AddInt32("window-h", window->h -1); diff --git a/src/video/kmsdrm/SDL_kmsdrmdyn.c b/src/video/kmsdrm/SDL_kmsdrmdyn.c index 96a63b96fd..cd78d7c5cb 100644 --- a/src/video/kmsdrm/SDL_kmsdrmdyn.c +++ b/src/video/kmsdrm/SDL_kmsdrmdyn.c @@ -57,8 +57,9 @@ KMSDRM_GetSym(const char *fnname, int *pHasModule) for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) { if (kmsdrmlibs[i].lib != NULL) { fn = SDL_LoadFunction(kmsdrmlibs[i].lib, fnname); - if (fn != NULL) + if (fn != NULL) { break; + } } } @@ -69,8 +70,9 @@ KMSDRM_GetSym(const char *fnname, int *pHasModule) SDL_Log("KMSDRM: Symbol '%s' NOT FOUND!\n", fnname); #endif - if (fn == NULL) - *pHasModule = 0; /* kill this module. */ + if (fn == NULL) { + *pHasModule = 0; /* kill this module. */ + } return fn; } diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c index 5722e041a0..08cf26c72f 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.c +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c @@ -158,7 +158,7 @@ KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) int i; int ret; - if (!curdata || !dispdata->cursor_bo) { + if (curdata == NULL || !dispdata->cursor_bo) { return SDL_SetError("Cursor or display not initialized properly."); } @@ -169,7 +169,7 @@ KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) ready_buffer = (uint8_t*)SDL_calloc(1, bufsize); - if (!ready_buffer) { + if (ready_buffer == NULL) { ret = SDL_OutOfMemory(); goto cleanup; } @@ -249,12 +249,12 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) ret = NULL; cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor)); - if (!cursor) { + if (cursor == NULL) { SDL_OutOfMemory(); goto cleanup; } curdata = (KMSDRM_CursorData *) SDL_calloc(1, sizeof(*curdata)); - if (!curdata) { + if (curdata == NULL) { SDL_OutOfMemory(); goto cleanup; } @@ -319,13 +319,13 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor) /* Get the mouse focused window, if any. */ mouse = SDL_GetMouse(); - if (!mouse) { + if (mouse == NULL) { return SDL_SetError("No mouse."); } window = mouse->focus; - if (!window || !cursor) { + if (window == NULL || cursor == NULL) { /* If no window is focused by mouse or cursor is NULL, since we have no window (no mouse->focus) and hence diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c index 883d38db11..b144559a1d 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c @@ -135,7 +135,7 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) { /* Get an actual usable fb for the next front buffer. */ fb_info = KMSDRM_FBFromBO(_this, windata->next_bo); - if (!fb_info) { + if (fb_info == NULL) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not get a framebuffer"); return 0; } diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 78a2ce26bb..2102f6dbd6 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -90,7 +90,7 @@ get_driindex(void) SDL_strlcpy(device, kmsdrm_dri_path, sizeof(device)); folder = opendir(device); - if (!folder) { + if (folder == NULL) { SDL_SetError("Failed to open directory '%s'", device); return -ENOENT; } @@ -128,7 +128,7 @@ get_driindex(void) KMSDRM_drmModeGetConnector( drm_fd, resources->connectors[i]); - if (!conn) { + if (conn == NULL) { continue; } @@ -245,13 +245,13 @@ KMSDRM_CreateDevice(void) } device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); return NULL; } viddata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - if (!viddata) { + if (viddata == NULL) { SDL_OutOfMemory(); goto cleanup; } @@ -308,8 +308,9 @@ KMSDRM_CreateDevice(void) cleanup: SDL_free(device); - if (viddata) + if (viddata) { SDL_free(viddata); + } return NULL; } @@ -351,7 +352,7 @@ KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo) when the backing buffer is destroyed */ fb_info = (KMSDRM_FBInfo *)SDL_calloc(1, sizeof(KMSDRM_FBInfo)); - if (!fb_info) { + if (fb_info == NULL) { SDL_OutOfMemory(); return NULL; } @@ -475,7 +476,7 @@ KMSDRM_WaitPageflip(_THIS, SDL_WindowData *windata) { because it's ordered, while the list on the connector is mostly random.*/ static drmModeModeInfo* KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay * display, -uint32_t width, uint32_t height, uint32_t refresh_rate){ +uint32_t width, uint32_t height, uint32_t refresh_rate) { SDL_DisplayData *dispdata = (SDL_DisplayData *) display->driverdata; drmModeConnector *connector = dispdata->connector; @@ -543,11 +544,13 @@ KMSDRM_CrtcGetPropId(uint32_t drm_fd, drmModePropertyPtr drm_prop = KMSDRM_drmModeGetProperty(drm_fd, props->props[i]); - if (!drm_prop) + if (!drm_prop) { continue; + } - if (SDL_strcmp(drm_prop->name, name) == 0) + if (SDL_strcmp(drm_prop->name, name) == 0) { prop_id = drm_prop->prop_id; + } KMSDRM_drmModeFreeProperty(drm_prop); } @@ -562,8 +565,9 @@ static SDL_bool KMSDRM_VrrPropId(uint32_t drm_fd, uint32_t crtc_id, uint32_t *vr crtc_id, DRM_MODE_OBJECT_CRTC); - if (!drm_props) + if (!drm_props) { return SDL_FALSE; + } *vrr_prop_id = KMSDRM_CrtcGetPropId(drm_fd, drm_props, @@ -588,14 +592,16 @@ KMSDRM_ConnectorCheckVrrCapable(uint32_t drm_fd, output_id, DRM_MODE_OBJECT_CONNECTOR); - if(!props) + if (!props) { return SDL_FALSE; + } for (i = 0; !found && i < props->count_props; ++i) { drmModePropertyPtr drm_prop = KMSDRM_drmModeGetProperty(drm_fd, props->props[i]); - if (!drm_prop) + if (!drm_prop) { continue; + } if (SDL_strcasecmp(drm_prop->name, name) == 0) { prop_value = props->prop_values[i]; @@ -604,8 +610,9 @@ KMSDRM_ConnectorCheckVrrCapable(uint32_t drm_fd, KMSDRM_drmModeFreeProperty(drm_prop); } - if(found) - return prop_value ? SDL_TRUE: SDL_FALSE; + if (found) { + return prop_value ? SDL_TRUE : SDL_FALSE; + } return SDL_FALSE; } @@ -614,8 +621,9 @@ void KMSDRM_CrtcSetVrr(uint32_t drm_fd, uint32_t crtc_id, SDL_bool enabled) { uint32_t vrr_prop_id; - if (!KMSDRM_VrrPropId(drm_fd, crtc_id, &vrr_prop_id)) + if (!KMSDRM_VrrPropId(drm_fd, crtc_id, &vrr_prop_id)) { return; + } KMSDRM_drmModeObjectSetProperty(drm_fd, crtc_id, @@ -632,22 +640,25 @@ KMSDRM_CrtcGetVrr(uint32_t drm_fd, uint32_t crtc_id) SDL_bool object_prop_value; int i; - if (!KMSDRM_VrrPropId(drm_fd, crtc_id, &vrr_prop_id)) + if (!KMSDRM_VrrPropId(drm_fd, crtc_id, &vrr_prop_id)) { return SDL_FALSE; + } props = KMSDRM_drmModeObjectGetProperties(drm_fd, crtc_id, DRM_MODE_OBJECT_CRTC); - if(!props) + if (!props) { return SDL_FALSE; + } for (i = 0; i < props->count_props; ++i) { drmModePropertyPtr drm_prop = KMSDRM_drmModeGetProperty(drm_fd, props->props[i]); - if (!drm_prop) + if (!drm_prop) { continue; + } object_prop_id = drm_prop->prop_id; object_prop_value = props->prop_values[i] ? SDL_TRUE : SDL_FALSE; @@ -678,7 +689,7 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) /* Reserve memory for the new display's driverdata. */ dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); - if (!dispdata) { + if (dispdata == NULL) { ret = SDL_OutOfMemory(); goto cleanup; } @@ -699,7 +710,7 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) for (i = 0; i < resources->count_encoders; i++) { encoder = KMSDRM_drmModeGetEncoder(viddata->drm_fd, resources->encoders[i]); - if (!encoder) { + if (encoder == NULL) { continue; } @@ -711,13 +722,13 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) encoder = NULL; } - if (!encoder) { + if (encoder == NULL) { /* No encoder was connected, find the first supported one */ for (i = 0; i < resources->count_encoders; i++) { encoder = KMSDRM_drmModeGetEncoder(viddata->drm_fd, resources->encoders[i]); - if (!encoder) { + if (encoder == NULL) { continue; } @@ -736,7 +747,7 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) } } - if (!encoder) { + if (encoder == NULL) { ret = SDL_SetError("No connected encoder found for connector."); goto cleanup; } @@ -746,7 +757,7 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) /* If no CRTC was connected to the encoder, find the first CRTC that is supported by the encoder, and use that. */ - if (!crtc) { + if (crtc == NULL) { for (i = 0; i < resources->count_crtcs; i++) { if (encoder->possible_crtcs & (1 << i)) { encoder->crtc_id = resources->crtcs[i]; @@ -756,7 +767,7 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) } } - if (!crtc) { + if (crtc == NULL) { ret = SDL_SetError("No CRTC found for connector."); goto cleanup; } @@ -828,7 +839,7 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) /* save previous vrr state */ dispdata->saved_vrr = KMSDRM_CrtcGetVrr(viddata->drm_fd, crtc->crtc_id); /* try to enable vrr */ - if(KMSDRM_ConnectorCheckVrrCapable(viddata->drm_fd, connector->connector_id, "VRR_CAPABLE")) { + if (KMSDRM_ConnectorCheckVrrCapable(viddata->drm_fd, connector->connector_id, "VRR_CAPABLE")) { SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Enabling VRR"); KMSDRM_CrtcSetVrr(viddata->drm_fd, crtc->crtc_id, SDL_TRUE); } @@ -841,7 +852,7 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) There's no problem with it being still incomplete. */ modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData)); - if (!modedata) { + if (modedata == NULL) { ret = SDL_OutOfMemory(); goto cleanup; } @@ -860,8 +871,9 @@ KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resources) SDL_AddVideoDisplay(&display, SDL_FALSE); cleanup: - if (encoder) + if (encoder) { KMSDRM_drmModeFreeEncoder(encoder); + } if (ret) { /* Error (complete) cleanup */ if (dispdata) { @@ -910,7 +922,7 @@ KMSDRM_InitDisplays (_THIS) { /* Get all of the available connectors / devices / crtcs */ resources = KMSDRM_drmModeGetResources(viddata->drm_fd); - if (!resources) { + if (resources == NULL) { ret = SDL_SetError("drmModeGetResources(%d) failed", viddata->drm_fd); goto cleanup; } @@ -921,7 +933,7 @@ KMSDRM_InitDisplays (_THIS) { drmModeConnector *connector = KMSDRM_drmModeGetConnector(viddata->drm_fd, resources->connectors[i]); - if (!connector) { + if (connector == NULL) { continue; } @@ -931,8 +943,7 @@ KMSDRM_InitDisplays (_THIS) { so if it fails (no encoder for connector, no valid video mode for connector etc...) we can keep looking for connected connectors. */ KMSDRM_AddDisplay(_this, connector, resources); - } - else { + } else { /* If it's not, free it now. */ KMSDRM_drmModeFreeConnector(connector); } @@ -961,8 +972,9 @@ KMSDRM_InitDisplays (_THIS) { viddata->drm_fd = -1; cleanup: - if (resources) + if (resources) { KMSDRM_drmModeFreeResources(resources); + } if (ret) { if (viddata->drm_fd >= 0) { close(viddata->drm_fd); @@ -1054,7 +1066,7 @@ KMSDRM_DestroySurfaces(_THIS, SDL_Window *window) &dispdata->original_mode); } - if(ret) { + if (ret) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not restore CRTC"); } @@ -1308,7 +1320,7 @@ KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) return 0; } - if (!modedata) { + if (modedata == NULL) { return SDL_SetError("Mode doesn't have an associated index"); } @@ -1332,7 +1344,7 @@ KMSDRM_DestroyWindow(_THIS, SDL_Window *window) SDL_bool is_vulkan = window->flags & SDL_WINDOW_VULKAN; /* Is this a VK window? */ unsigned int i, j; - if (!windata) { + if (windata == NULL) { return; } @@ -1417,8 +1429,8 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window) /* Allocate window internal data */ windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); - if (!windata) { - return(SDL_OutOfMemory()); + if (windata == NULL) { + return SDL_OutOfMemory(); } /* Setup driver data for this window */ @@ -1450,7 +1462,7 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window) but only when we come here for the first time, and only if it's not a VK window. */ if ((ret = KMSDRM_GBMInit(_this, dispdata))) { - return (SDL_SetError("Can't init GBM on window creation.")); + return SDL_SetError("Can't init GBM on window creation."); } } @@ -1467,10 +1479,10 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window) _this->gl_config.major_version = 2; _this->gl_config.minor_version = 0; if (SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA) < 0) { - return (SDL_SetError("Can't load EGL/GL library on window creation.")); + return SDL_SetError("Can't load EGL/GL library on window creation."); } } - + _this->gl_config.driver_loaded = 1; } @@ -1500,7 +1512,7 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window) /* Create the window surfaces with the size we have just chosen. Needs the window diverdata in place. */ if ((ret = KMSDRM_CreateSurfaces(_this, window))) { - return (SDL_SetError("Can't window GBM/EGL surfaces on window creation.")); + return SDL_SetError("Can't window GBM/EGL surfaces on window creation."); } } /* NON-Vulkan block ends. */ @@ -1514,7 +1526,7 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window) viddata->max_windows = new_max_windows; if (!viddata->windows) { - return (SDL_OutOfMemory()); + return SDL_OutOfMemory(); } } diff --git a/src/video/kmsdrm/SDL_kmsdrmvulkan.c b/src/video/kmsdrm/SDL_kmsdrmvulkan.c index 1a97d09492..1f4b2598e8 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvulkan.c +++ b/src/video/kmsdrm/SDL_kmsdrmvulkan.c @@ -52,19 +52,23 @@ int KMSDRM_Vulkan_LoadLibrary(_THIS, const char *path) SDL_bool hasDisplayExtension = SDL_FALSE; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; - if(_this->vulkan_config.loader_handle) + if (_this->vulkan_config.loader_handle) { return SDL_SetError("Vulkan already loaded"); + } /* Load the Vulkan library */ - if(!path) + if (path == NULL) { path = SDL_getenv("SDL_VULKAN_LIBRARY"); - if(!path) + } + if (path == NULL) { path = DEFAULT_VULKAN; + } _this->vulkan_config.loader_handle = SDL_LoadObject(path); - if(!_this->vulkan_config.loader_handle) + if (!_this->vulkan_config.loader_handle) { return -1; + } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); @@ -72,43 +76,44 @@ int KMSDRM_Vulkan_LoadLibrary(_THIS, const char *path) vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); - if(!vkGetInstanceProcAddr) + if (!vkGetInstanceProcAddr) { goto fail; + } _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr; _this->vulkan_config.vkEnumerateInstanceExtensionProperties = (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)( VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties"); - if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) + if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) { goto fail; + } extensions = SDL_Vulkan_CreateInstanceExtensionsList( (PFN_vkEnumerateInstanceExtensionProperties) _this->vulkan_config.vkEnumerateInstanceExtensionProperties, &extensionCount); - if(!extensions) + if (extensions == NULL) { goto fail; + } - for(i = 0; i < extensionCount; i++) + for (i = 0; i < extensionCount; i++) { - if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasSurfaceExtension = SDL_TRUE; - else if(SDL_strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, extensions[i].extensionName) == 0) + } else if (SDL_strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasDisplayExtension = SDL_TRUE; + } } SDL_free(extensions); - if(!hasSurfaceExtension) - { + if (!hasSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension"); goto fail; - } - else if(!hasDisplayExtension) - { + } else if (!hasDisplayExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_DISPLAY_EXTENSION_NAME "extension"); goto fail; @@ -124,8 +129,7 @@ fail: void KMSDRM_Vulkan_UnloadLibrary(_THIS) { - if(_this->vulkan_config.loader_handle) - { + if (_this->vulkan_config.loader_handle) { SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; } @@ -149,8 +153,7 @@ SDL_bool KMSDRM_Vulkan_GetInstanceExtensions(_THIS, static const char *const extensionsForKMSDRM[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME }; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } @@ -258,8 +261,7 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS, (PFN_vkCreateDisplayModeKHR)vkGetInstanceProcAddr( instance, "vkCreateDisplayModeKHR"); - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); goto clean; } @@ -273,8 +275,7 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS, /* that the VK_KHR_Display extension is active on the instance. */ /* That's the central extension we need for x-less VK! */ /****************************************************************/ - if(!vkCreateDisplayPlaneSurfaceKHR) - { + if (!vkCreateDisplayPlaneSurfaceKHR) { SDL_SetError(VK_KHR_DISPLAY_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); goto clean; @@ -444,9 +445,9 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS, /* The plane must be bound to the chosen display, or not in use. If none of these is true, iterate to another plane. */ - if (!((plane_props[i].currentDisplay == display) || - (plane_props[i].currentDisplay == VK_NULL_HANDLE))) + if (!((plane_props[i].currentDisplay == display) || (plane_props[i].currentDisplay == VK_NULL_HANDLE))) { continue; + } /* Iterate the list of displays supported by this plane in order to find out if the chosen display is among them. */ @@ -501,8 +502,7 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS, &display_plane_surface_create_info, NULL, surface); - if(result != VK_SUCCESS) - { + if (result != VK_SUCCESS) { SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); goto clean; @@ -511,16 +511,21 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS, ret = SDL_TRUE; clean: - if (physical_devices) - SDL_free (physical_devices); - if (display_props) - SDL_free (display_props); - if (device_props) - SDL_free (device_props); - if (plane_props) - SDL_free (plane_props); - if (mode_props) - SDL_free (mode_props); + if (physical_devices) { + SDL_free(physical_devices); + } + if (display_props) { + SDL_free(display_props); + } + if (device_props) { + SDL_free(device_props); + } + if (plane_props) { + SDL_free(plane_props); + } + if (mode_props) { + SDL_free(mode_props); + } return ret; } diff --git a/src/video/n3ds/SDL_n3dsframebuffer.c b/src/video/n3ds/SDL_n3dsframebuffer.c index ba4ec51bfa..1de24d023d 100644 --- a/src/video/n3ds/SDL_n3dsframebuffer.c +++ b/src/video/n3ds/SDL_n3dsframebuffer.c @@ -48,7 +48,7 @@ SDL_N3DS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void FreePreviousWindowFramebuffer(window); framebuffer = CreateNewWindowFramebuffer(window); - if (!framebuffer) { + if (framebuffer == NULL) { return SDL_OutOfMemory(); } @@ -86,7 +86,7 @@ SDL_N3DS_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rect u32 bufsize; surface = (SDL_Surface *) SDL_GetWindowData(window, N3DS_SURFACE); - if (!surface) { + if (surface == NULL) { return SDL_SetError("%s: Unable to get the window surface.", __func__); } @@ -94,8 +94,8 @@ SDL_N3DS_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rect framebuffer = (u32 *) gfxGetFramebuffer(drv_data->screen, GFX_LEFT, &width, &height); bufsize = width * height * 4; - CopyFramebuffertoN3DS(framebuffer, (Dimensions){ width, height }, - surface->pixels, (Dimensions){ surface->w, surface->h }); + CopyFramebuffertoN3DS(framebuffer, (Dimensions) { width, height }, + surface->pixels, (Dimensions) { surface->w, surface->h }); FlushN3DSBuffer(framebuffer, bufsize, drv_data->screen); return 0; diff --git a/src/video/n3ds/SDL_n3dsvideo.c b/src/video/n3ds/SDL_n3dsvideo.c index d4a46ad065..490e4110b2 100644 --- a/src/video/n3ds/SDL_n3dsvideo.c +++ b/src/video/n3ds/SDL_n3dsvideo.c @@ -59,9 +59,9 @@ static SDL_VideoDevice * N3DS_CreateDevice(void) { SDL_VideoDevice *device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); - return (0); + return 0; } device->VideoInit = N3DS_VideoInit; diff --git a/src/video/ngage/SDL_ngageevents.cpp b/src/video/ngage/SDL_ngageevents.cpp index a136333764..71d9975db9 100644 --- a/src/video/ngage/SDL_ngageevents.cpp +++ b/src/video/ngage/SDL_ngageevents.cpp @@ -47,8 +47,7 @@ NGAGE_PumpEvents(_THIS) { SDL_VideoData *phdata = (SDL_VideoData*)_this->driverdata; - while (phdata->NGAGE_WsEventStatus != KRequestPending) - { + while (phdata->NGAGE_WsEventStatus != KRequestPending) { phdata->NGAGE_WsSession.GetEvent(phdata->NGAGE_WsEvent); HandleWsEvent(_this, phdata->NGAGE_WsEvent); diff --git a/src/video/ngage/SDL_ngageframebuffer.cpp b/src/video/ngage/SDL_ngageframebuffer.cpp index 98ff9ff71a..f8cea52bd8 100644 --- a/src/video/ngage/SDL_ngageframebuffer.cpp +++ b/src/video/ngage/SDL_ngageframebuffer.cpp @@ -57,7 +57,7 @@ int SDL_NGAGE_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * forma /* Create a new one */ SDL_GetWindowSize(window, &w, &h); surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format); - if (! surface) { + if (surface == NULL) { return -1; } @@ -98,21 +98,16 @@ int SDL_NGAGE_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * forma * * In 12 bpp machines the table has 16 entries. */ - if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 8) - { + if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 8) { phdata->NGAGE_FrameBuffer += 512; - } - else - { + } else { phdata->NGAGE_FrameBuffer += 32; } #if 0 - if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 12) - { + if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 12) { phdata->NGAGE_FrameBuffer += 16 * 2; } - if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 16) - { + if (phdata->NGAGE_HasFrameBuffer && GetBpp(displayMode) == 16) { phdata->NGAGE_FrameBuffer += 16 * 2; } #endif @@ -154,14 +149,12 @@ int SDL_NGAGE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect SDL_Surface *surface; surface = (SDL_Surface *) SDL_GetWindowData(window, NGAGE_SURFACE); - if (! surface) - { + if (surface == NULL) { return SDL_SetError("Couldn't find ngage surface for window"); } /* Send the data to the display */ - if (SDL_getenv("SDL_VIDEO_NGAGE_SAVE_FRAMES")) - { + if (SDL_getenv("SDL_VIDEO_NGAGE_SAVE_FRAMES")) { char file[128]; SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp", (int)SDL_GetWindowID(window), ++frame_number); @@ -231,8 +224,7 @@ void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer) /* Render the rectangles in the list */ - for (i = 0; i < numrects; ++i) - { + for (i = 0; i < numrects; ++i) { const SDL_Rect& currentRect = rects[i]; SDL_Rect rect2; rect2.x = currentRect.x; @@ -240,8 +232,7 @@ void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer) rect2.w = currentRect.w; rect2.h = currentRect.h; - if (rect2.w <= 0 || rect2.h <= 0) /* Sanity check */ - { + if (rect2.w <= 0 || rect2.h <= 0) /* Sanity check */ { continue; } @@ -250,8 +241,7 @@ void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer) /* Check rects validity, i.e. upper and lower bounds */ TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1); TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1); - if (maxX < 0 || maxY < 0) /* sanity check */ - { + if (maxX < 0 || maxY < 0) /* sanity check */ { continue; } /* Clip from bottom */ @@ -274,22 +264,19 @@ void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer) TUint16* bitmapLine = (TUint16*)screen->pixels + sourceStartOffset; TUint16* screenMemory = screenBuffer + targetStartOffset; - if (skipValue == 1) - { - for(TInt y = 0 ; y < sourceRectHeight ; y++) + if (skipValue == 1) { + for (TInt y = 0 ; y < sourceRectHeight ; y++) { Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes); bitmapLine += sourceScanlineLength; screenMemory += targetScanlineLength; } - } - else - { - for(TInt y = 0 ; y < sourceRectHeight ; y++) + } else { + for (TInt y = 0 ; y < sourceRectHeight ; y++) { TUint16* bitmapPos = bitmapLine; /* 2 bytes per pixel */ TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */ - for(TInt x = 0 ; x < sourceRectWidth ; x++) + for (TInt x = 0 ; x < sourceRectWidth ; x++) { __ASSERT_DEBUG(screenMemory < (screenBuffer + phdata->NGAGE_ScreenSize.iWidth * phdata->NGAGE_ScreenSize.iHeight), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt)); @@ -308,17 +295,16 @@ void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer) // 256 color paletted mode: 8 bpp --> 12 bpp default: { - if(phdata->NGAGE_BytesPerPixel <= 2) - { + if (phdata->NGAGE_BytesPerPixel <= 2) { TUint8* bitmapLine = (TUint8*)screen->pixels + sourceStartOffset; TUint16* screenMemory = screenBuffer + targetStartOffset; - for(TInt y = 0 ; y < sourceRectHeight ; y++) + for (TInt y = 0 ; y < sourceRectHeight ; y++) { TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */ TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */ /* Convert each pixel from 256 palette to 4k color values */ - for(TInt x = 0 ; x < sourceRectWidth ; x++) + for (TInt x = 0 ; x < sourceRectWidth ; x++) { __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (phdata->NGAGE_ScreenSize.iWidth * phdata->NGAGE_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt)); @@ -329,17 +315,15 @@ void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer) bitmapLine += sourceScanlineLength; screenMemory += targetScanlineLength; } - } - else - { + } else { TUint8* bitmapLine = (TUint8*)screen->pixels + sourceStartOffset; TUint32* screenMemory = reinterpret_cast(screenBuffer + targetStartOffset); - for(TInt y = 0 ; y < sourceRectHeight ; y++) + for (TInt y = 0 ; y < sourceRectHeight ; y++) { TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */ TUint32* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */ /* Convert each pixel from 256 palette to 4k color values */ - for(TInt x = 0 ; x < sourceRectWidth ; x++) + for (TInt x = 0 ; x < sourceRectWidth ; x++) { __ASSERT_DEBUG(screenMemoryLinePos < (reinterpret_cast(screenBuffer) + (phdata->NGAGE_ScreenSize.iWidth * phdata->NGAGE_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(screenMemoryLinePos >= reinterpret_cast(screenBuffer), User::Panic(_L("SDL"), KErrCorrupt)); @@ -360,8 +344,7 @@ void DirectUpdate(_THIS, int numrects, SDL_Rect *rects) { SDL_VideoData *phdata = (SDL_VideoData*)_this->driverdata; - if (! phdata->NGAGE_IsWindowFocused) - { + if (! phdata->NGAGE_IsWindowFocused) { SDL_PauseAudio(1); SDL_Delay(1000); return; @@ -372,18 +355,15 @@ void DirectUpdate(_THIS, int numrects, SDL_Rect *rects) TUint16* screenBuffer = (TUint16*)phdata->NGAGE_FrameBuffer; #if 0 - if (phdata->NGAGE_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) - { + if (phdata->NGAGE_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) { // ... - } - else + } else #endif { DirectDraw(_this, numrects, rects, screenBuffer); } - for (int i = 0; i < numrects; ++i) - { + for (int i = 0; i < numrects; ++i) { TInt aAx = rects[i].x; TInt aAy = rects[i].y; TInt aBx = rects[i].w; diff --git a/src/video/ngage/SDL_ngagevideo.cpp b/src/video/ngage/SDL_ngagevideo.cpp index 7611b273dc..fad39734ea 100644 --- a/src/video/ngage/SDL_ngagevideo.cpp +++ b/src/video/ngage/SDL_ngagevideo.cpp @@ -58,29 +58,24 @@ NGAGE_DeleteDevice(SDL_VideoDevice * device) { SDL_VideoData *phdata = (SDL_VideoData*)device->driverdata; - if (phdata) - { + if (phdata) { /* Free Epoc resources */ /* Disable events for me */ - if (phdata->NGAGE_WsEventStatus != KRequestPending) - { + if (phdata->NGAGE_WsEventStatus != KRequestPending) { phdata->NGAGE_WsSession.EventReadyCancel(); } - if (phdata->NGAGE_RedrawEventStatus != KRequestPending) - { + if (phdata->NGAGE_RedrawEventStatus != KRequestPending) { phdata->NGAGE_WsSession.RedrawReadyCancel(); } free(phdata->NGAGE_DrawDevice); - if (phdata->NGAGE_WsWindow.WsHandle()) - { + if (phdata->NGAGE_WsWindow.WsHandle()) { phdata->NGAGE_WsWindow.Close(); } - if (phdata->NGAGE_WsWindowGroup.WsHandle()) - { + if (phdata->NGAGE_WsWindowGroup.WsHandle()) { phdata->NGAGE_WsWindowGroup.Close(); } @@ -90,8 +85,7 @@ NGAGE_DeleteDevice(SDL_VideoDevice * device) delete phdata->NGAGE_WsScreen; phdata->NGAGE_WsScreen = NULL; - if (phdata->NGAGE_WsSession.WsHandle()) - { + if (phdata->NGAGE_WsSession.WsHandle()) { phdata->NGAGE_WsSession.Close(); } @@ -99,8 +93,7 @@ NGAGE_DeleteDevice(SDL_VideoDevice * device) phdata = NULL; } - if (device) - { + if (device) { SDL_free(device); device = NULL; } @@ -114,18 +107,17 @@ NGAGE_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); - return (0); + return 0; } /* Initialize internal N-Gage specific data */ phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - if (! phdata) - { + if (phdata == NULL) { SDL_OutOfMemory(); SDL_free(device); - return (0); + return 0; } /* General video */ diff --git a/src/video/ngage/SDL_ngagewindow.cpp b/src/video/ngage/SDL_ngagewindow.cpp index 5b0682b29f..206e8b83d0 100644 --- a/src/video/ngage/SDL_ngagewindow.cpp +++ b/src/video/ngage/SDL_ngagewindow.cpp @@ -37,7 +37,7 @@ NGAGE_CreateWindow(_THIS, SDL_Window* window) { NGAGE_Window* ngage_window = (NGAGE_Window*)SDL_calloc(1, sizeof(NGAGE_Window)); - if (!ngage_window) { + if (ngage_window == NULL) { return SDL_OutOfMemory(); } diff --git a/src/video/offscreen/SDL_offscreenframebuffer.c b/src/video/offscreen/SDL_offscreenframebuffer.c index 376058856b..2e97e58f37 100644 --- a/src/video/offscreen/SDL_offscreenframebuffer.c +++ b/src/video/offscreen/SDL_offscreenframebuffer.c @@ -40,7 +40,7 @@ int SDL_OFFSCREEN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * f /* Create a new one */ SDL_GetWindowSize(window, &w, &h); surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format); - if (!surface) { + if (surface == NULL) { return -1; } @@ -58,7 +58,7 @@ int SDL_OFFSCREEN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_ SDL_Surface *surface; surface = (SDL_Surface *) SDL_GetWindowData(window, OFFSCREEN_SURFACE); - if (!surface) { + if (surface == NULL) { return SDL_SetError("Couldn't find offscreen surface for window"); } diff --git a/src/video/offscreen/SDL_offscreenvideo.c b/src/video/offscreen/SDL_offscreenvideo.c index a065f73faa..db4dcb20e4 100644 --- a/src/video/offscreen/SDL_offscreenvideo.c +++ b/src/video/offscreen/SDL_offscreenvideo.c @@ -59,9 +59,9 @@ OFFSCREEN_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); - return (0); + return 0; } /* General video */ diff --git a/src/video/offscreen/SDL_offscreenwindow.c b/src/video/offscreen/SDL_offscreenwindow.c index fd85f77e5e..a6aa4d4631 100644 --- a/src/video/offscreen/SDL_offscreenwindow.c +++ b/src/video/offscreen/SDL_offscreenwindow.c @@ -32,7 +32,7 @@ OFFSCREEN_CreateWindow(_THIS, SDL_Window* window) { OFFSCREEN_Window *offscreen_window = SDL_calloc(1, sizeof(OFFSCREEN_Window)); - if (!offscreen_window) { + if (offscreen_window == NULL) { return SDL_OutOfMemory(); } diff --git a/src/video/ps2/SDL_ps2video.c b/src/video/ps2/SDL_ps2video.c index b5422dc303..17c1525330 100644 --- a/src/video/ps2/SDL_ps2video.c +++ b/src/video/ps2/SDL_ps2video.c @@ -105,9 +105,9 @@ static SDL_VideoDevice *PS2_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); - return (0); + return 0; } /* Set the function pointers */ diff --git a/src/video/psp/SDL_pspevents.c b/src/video/psp/SDL_pspevents.c index 62bfdf1755..d821a00c9b 100644 --- a/src/video/psp/SDL_pspevents.c +++ b/src/video/psp/SDL_pspevents.c @@ -87,9 +87,9 @@ void PSP_PumpEvents(_THIS) /* HPRM Keyboard */ changed = old_keys ^ keys; old_keys = keys; - if(changed) { - for(i=0; i= 0) { - if((length % sizeof(SIrKeybScanCodeData)) == 0){ + if (pspIrKeybReadinput(buffer, &length) >= 0) { + if ((length % sizeof(SIrKeybScanCodeData)) == 0) { count = length / sizeof(SIrKeybScanCodeData); - for( i=0; i < count; i++ ) { + for ( i=0; i < count; i++ ) { unsigned char raw, pressed; scanData=(SIrKeybScanCodeData*) buffer+i; raw = scanData->raw; @@ -131,8 +131,9 @@ void PSP_InitOSKeymap(_THIS) { #ifdef PSPIRKEYB int i; - for (i=0; igl_config.depth_size; - if (_this->gl_config.alpha_size) - { + if (_this->gl_config.alpha_size) { attribs[i++] = EGL_ALPHA_SIZE; attribs[i++] = _this->gl_config.alpha_size; } - if (_this->gl_config.stencil_size) - { + if (_this->gl_config.stencil_size) { attribs[i++] = EGL_STENCIL_SIZE; attribs[i++] = _this->gl_config.stencil_size; } @@ -117,8 +115,7 @@ PSP_GL_CreateContext(_THIS, SDL_Window * window) EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs)); - if (num_configs == 0) - { + if (num_configs == 0) { SDL_SetError("No valid EGL configs for requested mode"); return 0; } diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c index 877e262916..a29ebb3de8 100644 --- a/src/video/raspberry/SDL_rpivideo.c +++ b/src/video/raspberry/SDL_rpivideo.c @@ -345,7 +345,7 @@ RPI_DestroyWindow(_THIS, SDL_Window * window) SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; - if(data) { + if (data) { if (data->double_buffer) { /* Wait for vsync, and then stop vsync callbacks and destroy related stuff, if needed */ SDL_LockMutex(data->vsync_cond_mutex); diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c index f9f5728cc6..63fdba82b4 100644 --- a/src/video/riscos/SDL_riscosevents.c +++ b/src/video/riscos/SDL_riscosevents.c @@ -147,8 +147,9 @@ RISCOS_InitEvents(_THIS) _kernel_swi_regs regs; int i, status; - for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) + for (i = 0; i < RISCOS_MAX_KEYS_PRESSED; i++) { driverdata->key_pressed[i] = 255; + } status = (_kernel_osbyte(202, 0, 255) & 0xFF); SDL_ToggleModState(KMOD_NUM, (status & (1 << 2)) == 0); diff --git a/src/video/riscos/SDL_riscosmessagebox.c b/src/video/riscos/SDL_riscosmessagebox.c index c506e80048..1e566c18de 100644 --- a/src/video/riscos/SDL_riscosmessagebox.c +++ b/src/video/riscos/SDL_riscosmessagebox.c @@ -40,10 +40,12 @@ RISCOS_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) regs.r[0] = (unsigned int)&error; regs.r[1] = (1 << 8) | (1 << 4); - if (messageboxdata->flags == SDL_MESSAGEBOX_INFORMATION) + if (messageboxdata->flags == SDL_MESSAGEBOX_INFORMATION) { regs.r[1] |= (1 << 9); - else if (messageboxdata->flags == SDL_MESSAGEBOX_WARNING) + } else if (messageboxdata->flags == SDL_MESSAGEBOX_WARNING) { regs.r[1] |= (2 << 9); + } + regs.r[2] = (unsigned int)messageboxdata->title; regs.r[3] = 0; regs.r[4] = 0; @@ -51,8 +53,9 @@ RISCOS_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_strlcpy(buttonstring, "" , 1024); for (i = 0; i < messageboxdata->numbuttons; i++) { SDL_strlcat(buttonstring, messageboxdata->buttons[i].text, 1024); - if (i + 1 < messageboxdata->numbuttons) + if (i + 1 < messageboxdata->numbuttons) { SDL_strlcat(buttonstring, ",", 1024); + } } regs.r[5] = (unsigned int)buttonstring; diff --git a/src/video/riscos/SDL_riscosmodes.c b/src/video/riscos/SDL_riscosmodes.c index 9500b22297..383a4bdf82 100644 --- a/src/video/riscos/SDL_riscosmodes.c +++ b/src/video/riscos/SDL_riscosmodes.c @@ -88,7 +88,7 @@ static size_t measure_mode_block(const int *block) { size_t blockSize = ((block[0] & 0xFF) == 3) ? 7 : 5; - while(block[blockSize] != -1) { + while (block[blockSize] != -1) { blockSize += 2; } blockSize++; @@ -169,7 +169,7 @@ convert_mode_block(const int *block) } dst = SDL_malloc(40); - if (!dst) { + if (dst == NULL) { return NULL; } @@ -249,7 +249,7 @@ RISCOS_GetDisplayModes(_THIS, SDL_VideoDisplay * display) } block = SDL_malloc(-regs.r[7]); - if (!block) { + if (block == NULL) { SDL_OutOfMemory(); return; } @@ -268,8 +268,9 @@ RISCOS_GetDisplayModes(_THIS, SDL_VideoDisplay * display) continue; } - if (mode.format == SDL_PIXELFORMAT_UNKNOWN) + if (mode.format == SDL_PIXELFORMAT_UNKNOWN) { continue; + } mode.driverdata = convert_mode_block(pos + 4); if (!mode.driverdata) { diff --git a/src/video/riscos/SDL_riscosvideo.c b/src/video/riscos/SDL_riscosvideo.c index 163b91e539..6732f0c295 100644 --- a/src/video/riscos/SDL_riscosvideo.c +++ b/src/video/riscos/SDL_riscosvideo.c @@ -56,9 +56,9 @@ RISCOS_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); - return (0); + return 0; } /* Initialize internal data */ diff --git a/src/video/riscos/SDL_riscoswindow.c b/src/video/riscos/SDL_riscoswindow.c index d8f9c81366..23000e494d 100644 --- a/src/video/riscos/SDL_riscoswindow.c +++ b/src/video/riscos/SDL_riscoswindow.c @@ -36,7 +36,7 @@ RISCOS_CreateWindow(_THIS, SDL_Window * window) SDL_WindowData *driverdata; driverdata = (SDL_WindowData *) SDL_calloc(1, sizeof(*driverdata)); - if (!driverdata) { + if (driverdata == NULL) { return SDL_OutOfMemory(); } driverdata->window = window; @@ -55,8 +55,9 @@ RISCOS_DestroyWindow(_THIS, SDL_Window * window) { SDL_WindowData *driverdata = (SDL_WindowData *) window->driverdata; - if (!driverdata) + if (driverdata == NULL) { return; + } SDL_free(driverdata); window->driverdata = NULL; diff --git a/src/video/vita/SDL_vitaframebuffer.c b/src/video/vita/SDL_vitaframebuffer.c index 1c558486b3..c14700f628 100644 --- a/src/video/vita/SDL_vitaframebuffer.c +++ b/src/video/vita/SDL_vitaframebuffer.c @@ -43,11 +43,13 @@ void *vita_gpu_alloc(unsigned int type, unsigned int size, SceUID *uid) *uid = sceKernelAllocMemBlock("gpu_mem", type, size, NULL); - if (*uid < 0) + if (*uid < 0) { return NULL; + } - if (sceKernelGetMemBlockBase(*uid, &mem) < 0) + if (sceKernelGetMemBlockBase(*uid, &mem) < 0) { return NULL; + } return mem; } @@ -55,8 +57,9 @@ void *vita_gpu_alloc(unsigned int type, unsigned int size, SceUID *uid) void vita_gpu_free(SceUID uid) { void *mem = NULL; - if (sceKernelGetMemBlockBase(uid, &mem) < 0) + if (sceKernelGetMemBlockBase(uid, &mem) < 0) { return; + } sceKernelFreeMemBlock(uid); } @@ -101,7 +104,7 @@ void VITA_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; - if (!data) { + if (data == NULL) { /* The window wasn't fully initialized */ return; } diff --git a/src/video/vita/SDL_vitagl_pvr.c b/src/video/vita/SDL_vitagl_pvr.c index 189d06e80d..538a583f98 100644 --- a/src/video/vita/SDL_vitagl_pvr.c +++ b/src/video/vita/SDL_vitagl_pvr.c @@ -52,10 +52,8 @@ VITA_GL_LoadLibrary(_THIS, const char *path) char* default_path = "app0:module"; char target_path[MAX_PATH]; - if (skip_init == NULL) // we don't care about actual value - { - if (override != NULL) - { + if (skip_init == NULL) // we don't care about actual value { + if (override != NULL) { default_path = override; } @@ -99,8 +97,7 @@ VITA_GL_CreateContext(_THIS, SDL_Window * window) context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); - if (context != NULL) - { + if (context != NULL) { FB_WIDTH = window->w; FB_HEIGHT = window->h; set_getprocaddress((void *(*)(const char *))eglGetProcAddress); diff --git a/src/video/vita/SDL_vitagles.c b/src/video/vita/SDL_vitagles.c index 7dc96b77d5..6a2d8621ed 100644 --- a/src/video/vita/SDL_vitagles.c +++ b/src/video/vita/SDL_vitagles.c @@ -136,8 +136,7 @@ VITA_GLES_CreateContext(_THIS, SDL_Window * window) EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs)); - if (num_configs == 0) - { + if (num_configs == 0) { SDL_SetError("No valid EGL configs for requested mode"); return 0; } diff --git a/src/video/vita/SDL_vitagles_pvr.c b/src/video/vita/SDL_vitagles_pvr.c index a94efe135e..8f11d39d85 100644 --- a/src/video/vita/SDL_vitagles_pvr.c +++ b/src/video/vita/SDL_vitagles_pvr.c @@ -41,10 +41,8 @@ VITA_GLES_LoadLibrary(_THIS, const char *path) char* default_path = "app0:module"; char target_path[MAX_PATH]; - if (skip_init == NULL) // we don't care about actual value - { - if (override != NULL) - { + if (skip_init == NULL) // we don't care about actual value { + if (override != NULL) { default_path = override; } diff --git a/src/video/vita/SDL_vitakeyboard.c b/src/video/vita/SDL_vitakeyboard.c index c4c9cbbad6..d2a8674cb9 100644 --- a/src/video/vita/SDL_vitakeyboard.c +++ b/src/video/vita/SDL_vitakeyboard.c @@ -50,17 +50,16 @@ void VITA_PollKeyboard(void) { // We skip polling keyboard if no window is created - if (Vita_Window == NULL) + if (Vita_Window == NULL) { return; + } - if (keyboard_hid_handle > 0) - { + if (keyboard_hid_handle > 0) { int numReports = sceHidKeyboardRead(keyboard_hid_handle, (SceHidKeyboardReport**)&k_reports, SCE_HID_MAX_REPORT); if (numReports < 0) { keyboard_hid_handle = 0; - } - else if (numReports) { + } else if (numReports) { // Numlock and Capslock state changes only on a SDL_PRESSED event // The k_report only reports the state of the LED if (k_reports[numReports - 1].modifiers[1] & 0x1) { @@ -68,8 +67,7 @@ VITA_PollKeyboard(void) SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); locks |= 0x1; } - } - else { + } else { if (locks & 0x1) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR); SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); @@ -83,8 +81,7 @@ VITA_PollKeyboard(void) SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); locks |= 0x2; } - } - else { + } else { if (locks & 0x2) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); @@ -98,8 +95,7 @@ VITA_PollKeyboard(void) SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_SCROLLLOCK); locks |= 0x4; } - } - else { + } else { if (locks & 0x4) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_SCROLLLOCK); locks &= ~0x4; @@ -112,64 +108,56 @@ VITA_PollKeyboard(void) if (changed_modifiers & 0x01) { if (prev_modifiers & 0x01) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LCTRL); - } - else { + } else { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LCTRL); } } if (changed_modifiers & 0x02) { if (prev_modifiers & 0x02) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT); - } - else { + } else { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT); } } if (changed_modifiers & 0x04) { if (prev_modifiers & 0x04) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LALT); - } - else { + } else { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LALT); } } if (changed_modifiers & 0x08) { if (prev_modifiers & 0x08) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LGUI); - } - else { + } else { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LGUI); } } if (changed_modifiers & 0x10) { if (prev_modifiers & 0x10) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RCTRL); - } - else { + } else { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RCTRL); } } if (changed_modifiers & 0x20) { if (prev_modifiers & 0x20) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT); - } - else { + } else { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RSHIFT); } } if (changed_modifiers & 0x40) { if (prev_modifiers & 0x40) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RALT); - } - else { + } else { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RALT); } } if (changed_modifiers & 0x80) { if (prev_modifiers & 0x80) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RGUI); - } - else { + } else { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RGUI); } } diff --git a/src/video/vita/SDL_vitamessagebox.c b/src/video/vita/SDL_vitamessagebox.c index 4921139868..6fe7048f42 100644 --- a/src/video/vita/SDL_vitamessagebox.c +++ b/src/video/vita/SDL_vitamessagebox.c @@ -43,8 +43,7 @@ int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SceCommonDialogErrorCode init_result; SDL_bool setup_minimal_gxm = SDL_FALSE; - if (messageboxdata->numbuttons > 3) - { + if (messageboxdata->numbuttons > 3) { return -1; } @@ -58,20 +57,15 @@ int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) msgParam.msg = (const SceChar8*)message; SDL_zero(buttonParam); - if (messageboxdata->numbuttons == 3) - { + if (messageboxdata->numbuttons == 3) { msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_3BUTTONS; msgParam.buttonParam = &buttonParam; buttonParam.msg1 = messageboxdata->buttons[0].text; buttonParam.msg2 = messageboxdata->buttons[1].text; buttonParam.msg3 = messageboxdata->buttons[2].text; - } - else if (messageboxdata->numbuttons == 2) - { + } else if (messageboxdata->numbuttons == 2) { msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_YESNO; - } - else if (messageboxdata->numbuttons == 1) - { + } else if (messageboxdata->numbuttons == 1) { msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_OK; } param.userMsgParam = &msgParam; @@ -81,8 +75,7 @@ int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) init_result = sceMsgDialogInit(¶m); // Setup display if it hasn't been initialized before - if (init_result == SCE_COMMON_DIALOG_ERROR_GXM_IS_UNINITIALIZED) - { + if (init_result == SCE_COMMON_DIALOG_ERROR_GXM_IS_UNINITIALIZED) { gxm_minimal_init_for_common_dialog(); init_result = sceMsgDialogInit(¶m); setup_minimal_gxm = SDL_TRUE; @@ -90,50 +83,34 @@ int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) gxm_init_for_common_dialog(); - if (init_result >= 0) - { - while (sceMsgDialogGetStatus() == SCE_COMMON_DIALOG_STATUS_RUNNING) - { + if (init_result >= 0) { + while (sceMsgDialogGetStatus() == SCE_COMMON_DIALOG_STATUS_RUNNING) { gxm_swap_for_common_dialog(); } SDL_zero(dialog_result); sceMsgDialogGetResult(&dialog_result); - if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON1) - { + if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON1) { *buttonid = messageboxdata->buttons[0].buttonid; - } - else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON2) - { + } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON2) { *buttonid = messageboxdata->buttons[1].buttonid; - } - else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON3) - { + } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON3) { *buttonid = messageboxdata->buttons[2].buttonid; - } - else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_YES) - { + } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_YES) { *buttonid = messageboxdata->buttons[0].buttonid; - } - else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_NO) - { + } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_NO) { *buttonid = messageboxdata->buttons[1].buttonid; - } - else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_OK) - { + } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_OK) { *buttonid = messageboxdata->buttons[0].buttonid; } sceMsgDialogTerm(); - } - else - { + } else { return -1; } gxm_term_for_common_dialog(); - if (setup_minimal_gxm) - { + if (setup_minimal_gxm) { gxm_minimal_term_for_common_dialog(); } diff --git a/src/video/vita/SDL_vitamouse.c b/src/video/vita/SDL_vitamouse.c index d2337ba3ae..5b53f70e98 100644 --- a/src/video/vita/SDL_vitamouse.c +++ b/src/video/vita/SDL_vitamouse.c @@ -44,16 +44,14 @@ void VITA_PollMouse(void) { // We skip polling mouse if no window is created - if (Vita_Window == NULL) + if (Vita_Window == NULL) { return; + } - if (mouse_hid_handle > 0) - { + if (mouse_hid_handle > 0) { int numReports = sceHidMouseRead(mouse_hid_handle, (SceHidMouseReport**)&m_reports, SCE_HID_MAX_REPORT); - if (numReports > 0) - { - for (int i = 0; i <= numReports - 1; i++) - { + if (numReports > 0) { + for (int i = 0; i <= numReports - 1; i++) { Uint8 changed_buttons = m_reports[i].buttons ^ prev_buttons; if (changed_buttons & 0x1) { @@ -77,8 +75,7 @@ VITA_PollMouse(void) prev_buttons = m_reports[i].buttons; - if (m_reports[i].rel_x || m_reports[i].rel_y) - { + if (m_reports[i].rel_x || m_reports[i].rel_y) { SDL_SendMouseMotion(Vita_Window, 0, 1, m_reports[i].rel_x, m_reports[i].rel_y); } } diff --git a/src/video/vita/SDL_vitatouch.c b/src/video/vita/SDL_vitatouch.c index 5ac01652da..f4a62ec22e 100644 --- a/src/video/vita/SDL_vitatouch.c +++ b/src/video/vita/SDL_vitatouch.c @@ -54,7 +54,7 @@ VITA_InitTouch(void) sceTouchEnableTouchForce(SCE_TOUCH_PORT_FRONT); sceTouchEnableTouchForce(SCE_TOUCH_PORT_BACK); - for(int port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) { + for (int port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) { SceTouchPanelInfo panelinfo; sceTouchGetPanelInfo(port, &panelinfo); @@ -73,7 +73,7 @@ VITA_InitTouch(void) } void -VITA_QuitTouch(void){ +VITA_QuitTouch(void) { sceTouchDisableTouchForce(SCE_TOUCH_PORT_FRONT); sceTouchDisableTouchForce(SCE_TOUCH_PORT_BACK); } @@ -85,20 +85,20 @@ VITA_PollTouch(void) int port; // We skip polling touch if no window is created - if (Vita_Window == NULL) + if (Vita_Window == NULL) { return; + } SDL_memcpy(touch_old, touch, sizeof(touch_old)); - for(port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) { + for (port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) { /** Skip polling of Touch Device if environment variable is set **/ if (((port == 0) && disableFrontPoll) || ((port == 1) && disableBackPoll)) { continue; } sceTouchPeek(port, &touch[port], 1); if (touch[port].reportNum > 0) { - for (int i = 0; i < touch[port].reportNum; i++) - { + for (int i = 0; i < touch[port].reportNum; i++) { // adjust coordinates and forces to return normalized values // for the front, screen area is used as a reference (for direct touch) // e.g. touch_x = 1.0 corresponds to screen_x = 960 @@ -120,7 +120,7 @@ VITA_PollTouch(void) finger_id = (SDL_FingerID) touch[port].report[i].id; // Skip if finger was already previously down - if(!finger_down) { + if (!finger_down) { // Send an initial touch SDL_SendTouch((SDL_TouchID)port, finger_id, diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c index ddda96bb2d..cd2b40b05b 100644 --- a/src/video/vita/SDL_vitavideo.c +++ b/src/video/vita/SDL_vitavideo.c @@ -140,7 +140,7 @@ VITA_Create() #if defined(SDL_VIDEO_VITA_PIB) || defined(SDL_VIDEO_VITA_PVR) #if defined(SDL_VIDEO_VITA_PVR_OGL) -if(SDL_getenv("VITA_PVR_OGL") != NULL) { +if (SDL_getenv("VITA_PVR_OGL") != NULL) { device->GL_LoadLibrary = VITA_GL_LoadLibrary; device->GL_CreateContext = VITA_GL_CreateContext; device->GL_GetProcAddress = VITA_GL_GetProcAddress; @@ -270,8 +270,7 @@ VITA_CreateWindow(_THIS, SDL_Window * window) window->driverdata = wdata; // Vita can only have one window - if (Vita_Window != NULL) - { + if (Vita_Window != NULL) { return SDL_SetError("Only one window supported"); } @@ -295,7 +294,7 @@ VITA_CreateWindow(_THIS, SDL_Window * window) win.windowSize = PSP2_WINDOW_960X544; } if ((window->flags & SDL_WINDOW_OPENGL) != 0) { - if(SDL_getenv("VITA_PVR_OGL") != NULL) { + if (SDL_getenv("VITA_PVR_OGL") != NULL) { /* Set version to 2.1 and PROFILE to ES */ temp_major = _this->gl_config.major_version; temp_minor = _this->gl_config.minor_version; @@ -309,7 +308,7 @@ VITA_CreateWindow(_THIS, SDL_Window * window) if (wdata->egl_surface == EGL_NO_SURFACE) { return SDL_SetError("Could not create GLES window surface"); } - if(SDL_getenv("VITA_PVR_OGL") != NULL) { + if (SDL_getenv("VITA_PVR_OGL") != NULL) { /* Revert */ _this->gl_config.major_version = temp_major; _this->gl_config.minor_version = temp_minor; @@ -406,10 +405,10 @@ static void utf16_to_utf8(const uint16_t *src, uint8_t *dst) { for (i = 0; src[i]; i++) { if ((src[i] & 0xFF80) == 0) { *(dst++) = src[i] & 0xFF; - } else if((src[i] & 0xF800) == 0) { + } else if ((src[i] & 0xF800) == 0) { *(dst++) = ((src[i] >> 6) & 0xFF) | 0xC0; *(dst++) = (src[i] & 0x3F) | 0x80; - } else if((src[i] & 0xFC00) == 0xD800 && (src[i + 1] & 0xFC00) == 0xDC00) { + } else if ((src[i] & 0xFC00) == 0xD800 && (src[i + 1] & 0xFC00) == 0xDC00) { *(dst++) = (((src[i] + 64) >> 8) & 0x3) | 0xF0; *(dst++) = (((src[i] >> 2) + 16) & 0x3F) | 0x80; *(dst++) = ((src[i] >> 4) & 0x30) | 0x80 | ((src[i + 1] << 2) & 0xF); @@ -440,13 +439,11 @@ void VITA_ImeEventHandler(void *arg, const SceImeEventData *e) if (e->param.text.caretIndex == 0) { SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_BACKSPACE); sceImeSetText((SceWChar16 *)libime_initval, 4); - } - else { + } else { scancode = SDL_GetScancodeFromKey(*(SceWChar16 *)&libime_out[1]); if (scancode == SDL_SCANCODE_SPACE) { SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_SPACE); - } - else { + } else { utf16_to_utf8((SceWChar16 *)&libime_out[1], utf8_buffer); SDL_SendKeyboardText((const char*)utf8_buffer); } @@ -556,7 +553,7 @@ SDL_bool VITA_IsScreenKeyboardShown(_THIS, SDL_Window *window) return videodata->ime_active; #else SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus(); - return (dialogStatus == SCE_COMMON_DIALOG_STATUS_RUNNING); + return dialogStatus == SCE_COMMON_DIALOG_STATUS_RUNNING; #endif } @@ -593,8 +590,9 @@ void VITA_PumpEvents(_THIS) SDL_SendKeyboardText((const char*)utf8_buffer); // Send enter key only on enter - if (result.button == SCE_IME_DIALOG_BUTTON_ENTER) + if (result.button == SCE_IME_DIALOG_BUTTON_ENTER) { SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_RETURN); + } sceImeDialogTerm(); diff --git a/src/video/vivante/SDL_vivantevulkan.c b/src/video/vivante/SDL_vivantevulkan.c index 798c5e446b..66c8cd84c5 100644 --- a/src/video/vivante/SDL_vivantevulkan.c +++ b/src/video/vivante/SDL_vivantevulkan.c @@ -41,19 +41,19 @@ int VIVANTE_Vulkan_LoadLibrary(_THIS, const char *path) SDL_bool hasSurfaceExtension = SDL_FALSE; SDL_bool hasDisplayExtension = SDL_FALSE; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; - if(_this->vulkan_config.loader_handle) + if (_this->vulkan_config.loader_handle) { return SDL_SetError("Vulkan already loaded"); + } /* Load the Vulkan loader library */ - if(!path) + if (path == NULL) { path = SDL_getenv("SDL_VULKAN_LIBRARY"); - if(!path) - { + } + if (path == NULL) { /* If no path set, try Vivante fb vulkan driver explicitly */ path = "libvulkan-fb.so"; _this->vulkan_config.loader_handle = SDL_LoadObject(path); - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { /* If that couldn't be loaded, fall back to default name */ path = "libvulkan.so"; _this->vulkan_config.loader_handle = SDL_LoadObject(path); @@ -61,43 +61,45 @@ int VIVANTE_Vulkan_LoadLibrary(_THIS, const char *path) } else { _this->vulkan_config.loader_handle = SDL_LoadObject(path); } - if(!_this->vulkan_config.loader_handle) + if (!_this->vulkan_config.loader_handle) { return -1; + } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vivante: Loaded vulkan driver %s", path); vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); - if(!vkGetInstanceProcAddr) + if (!vkGetInstanceProcAddr) { goto fail; + } _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr; _this->vulkan_config.vkEnumerateInstanceExtensionProperties = (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)( VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties"); - if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) + if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) { goto fail; + } extensions = SDL_Vulkan_CreateInstanceExtensionsList( (PFN_vkEnumerateInstanceExtensionProperties) _this->vulkan_config.vkEnumerateInstanceExtensionProperties, &extensionCount); - if(!extensions) + if (extensions == NULL) { goto fail; - for(i = 0; i < extensionCount; i++) + } + for (i = 0; i < extensionCount; i++) { - if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasSurfaceExtension = SDL_TRUE; - else if(SDL_strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, extensions[i].extensionName) == 0) + } else if (SDL_strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasDisplayExtension = SDL_TRUE; + } } SDL_free(extensions); - if(!hasSurfaceExtension) - { + if (!hasSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension"); goto fail; - } - else if(!hasDisplayExtension) - { + } else if (!hasDisplayExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_DISPLAY_EXTENSION_NAME "extension"); goto fail; @@ -112,8 +114,7 @@ fail: void VIVANTE_Vulkan_UnloadLibrary(_THIS) { - if(_this->vulkan_config.loader_handle) - { + if (_this->vulkan_config.loader_handle) { SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; } @@ -127,8 +128,7 @@ SDL_bool VIVANTE_Vulkan_GetInstanceExtensions(_THIS, static const char *const extensionsForVivante[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME }; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } @@ -142,8 +142,7 @@ SDL_bool VIVANTE_Vulkan_CreateSurface(_THIS, VkInstance instance, VkSurfaceKHR *surface) { - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } diff --git a/src/video/wayland/SDL_waylanddyn.c b/src/video/wayland/SDL_waylanddyn.c index bdceeb6efc..58f7e51709 100644 --- a/src/video/wayland/SDL_waylanddyn.c +++ b/src/video/wayland/SDL_waylanddyn.c @@ -66,8 +66,9 @@ WAYLAND_GetSym(const char *fnname, int *pHasModule) for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { if (waylandlibs[i].lib != NULL) { fn = SDL_LoadFunction(waylandlibs[i].lib, fnname); - if (fn != NULL) + if (fn != NULL) { break; + } } } @@ -78,8 +79,9 @@ WAYLAND_GetSym(const char *fnname, int *pHasModule) SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!\n", fnname); #endif - if (fn == NULL) - *pHasModule = 0; /* kill this module. */ + if (fn == NULL) { + *pHasModule = 0; /* kill this module. */ + } return fn; } diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index 15a19eba54..72e272efcc 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -430,7 +430,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer, struct SDL_WaylandInput *input = data; SDL_WindowData *window; - if (!surface) { + if (surface == NULL) { /* enter event for a window we've just destroyed */ return; } @@ -469,7 +469,7 @@ pointer_handle_leave(void *data, struct wl_pointer *pointer, { struct SDL_WaylandInput *input = data; - if (!surface || !SDL_WAYLAND_own_surface(surface)) { + if (surface == NULL || !SDL_WAYLAND_own_surface(surface)) { return; } @@ -734,7 +734,7 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer, { struct SDL_WaylandInput *input = data; - if(wl_seat_get_version(input->seat) >= 5) + if (wl_seat_get_version(input->seat) >= 5) pointer_handle_axis_common(input, AXIS_EVENT_CONTINUOUS, axis, value); else pointer_handle_axis_common_v1(input, time, axis, value); @@ -961,7 +961,7 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, char *map_str; const char *locale; - if (!data) { + if (data == NULL) { close(fd); return; } @@ -1100,7 +1100,7 @@ keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, SDL_WindowData *window; uint32_t *key; - if (!surface) { + if (surface == NULL) { /* enter event for a window we've just destroyed */ return; } @@ -1143,7 +1143,7 @@ keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, struct SDL_WaylandInput *input = data; SDL_WindowData *window; - if (!surface || !SDL_WAYLAND_own_surface(surface)) { + if (surface == NULL || !SDL_WAYLAND_own_surface(surface)) { return; } @@ -1172,7 +1172,7 @@ keyboard_input_get_text(char text[8], const struct SDL_WaylandInput *input, uint const xkb_keysym_t *syms; xkb_keysym_t sym; - if (!window || window->keyboard_device != input || !input->xkb.state) { + if (window == NULL || window->keyboard_device != input || !input->xkb.state) { return SDL_FALSE; } @@ -1287,7 +1287,7 @@ keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, } /* If a key is repeating, update the text to apply the modifier. */ - if(keyboard_repeat_is_set(&input->keyboard_repeat)) { + if (keyboard_repeat_is_set(&input->keyboard_repeat)) { char text[8]; const uint32_t key = keyboard_repeat_get_key(&input->keyboard_repeat); @@ -1709,8 +1709,11 @@ static char* Wayland_URIToLocal(char* uri) { char *file = NULL; SDL_bool local; - if (SDL_memcmp(uri,"file:/",6) == 0) uri += 6; /* local file? */ - else if (SDL_strstr(uri,":/") != NULL) return file; /* wrong scheme */ + if (SDL_memcmp(uri,"file:/",6) == 0) { + uri += 6; /* local file? */ + } else if (SDL_strstr(uri, ":/") != NULL) { + return file; /* wrong scheme */ + } local = uri[0] != '/' || (uri[0] != '\0' && uri[1] == '/'); @@ -2092,7 +2095,7 @@ tablet_tool_handle_proximity_in(void* data, struct zwp_tablet_tool_v2* tool, uin struct SDL_WaylandTabletInput* input = data; SDL_WindowData* window; - if (!surface) { + if (surface == NULL) { return; } @@ -2152,7 +2155,7 @@ tablet_tool_handle_down(void* data, struct zwp_tablet_tool_v2* tool, uint32_t se struct SDL_WaylandTabletInput* input = data; SDL_WindowData* window = input->tool_focus; input->is_down = SDL_TRUE; - if (!window) { + if (window == NULL) { /* tablet_tool_handle_proximity_out gets called when moving over the libdecoration csd. * that sets input->tool_focus (window) to NULL, but handle_{down,up} events are still * received. To prevent SIGSEGV this returns when this is the case. @@ -2171,7 +2174,7 @@ tablet_tool_handle_up(void* data, struct zwp_tablet_tool_v2* tool) input->is_down = SDL_FALSE; - if (!window) { + if (window == NULL) { /* tablet_tool_handle_proximity_out gets called when moving over the libdecoration csd. * that sets input->tool_focus (window) to NULL, but handle_{down,up} events are still * received. To prevent SIGSEGV this returns when this is the case. @@ -2373,7 +2376,7 @@ Wayland_input_add_tablet(struct SDL_WaylandInput *input, struct SDL_WaylandTable { struct SDL_WaylandTabletInput* tablet_input; - if (!tablet_manager || !input || !input->seat) { + if (tablet_manager == NULL || input == NULL || !input->seat) { return; } @@ -2413,8 +2416,9 @@ Wayland_display_add_input(SDL_VideoData *d, uint32_t id, uint32_t version) struct SDL_WaylandInput *input; input = SDL_calloc(1, sizeof *input); - if (input == NULL) + if (input == NULL) { return; + } input->display = d; input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, SDL_min(SDL_WL_SEAT_VERSION, version)); @@ -2447,8 +2451,9 @@ void Wayland_display_destroy_input(SDL_VideoData *d) { struct SDL_WaylandInput *input = d->input; - if (!input) + if (input == NULL) { return; + } if (input->data_device != NULL) { Wayland_data_device_clear_selection(input->data_device); @@ -2469,11 +2474,13 @@ void Wayland_display_destroy_input(SDL_VideoData *d) SDL_free(input->text_input); } - if (input->keyboard) + if (input->keyboard) { wl_keyboard_destroy(input->keyboard); + } - if (input->pointer) + if (input->pointer) { wl_pointer_destroy(input->pointer); + } if (input->touch) { SDL_DelTouch(1); @@ -2484,20 +2491,25 @@ void Wayland_display_destroy_input(SDL_VideoData *d) Wayland_input_destroy_tablet(input); } - if (input->seat) + if (input->seat) { wl_seat_destroy(input->seat); + } - if (input->xkb.compose_state) + if (input->xkb.compose_state) { WAYLAND_xkb_compose_state_unref(input->xkb.compose_state); + } - if (input->xkb.compose_table) + if (input->xkb.compose_table) { WAYLAND_xkb_compose_table_unref(input->xkb.compose_table); + } - if (input->xkb.state) + if (input->xkb.state) { WAYLAND_xkb_state_unref(input->xkb.state); + } - if (input->xkb.keymap) + if (input->xkb.keymap) { WAYLAND_xkb_keymap_unref(input->xkb.keymap); + } SDL_free(input); d->input = NULL; @@ -2513,8 +2525,9 @@ void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id) void Wayland_display_destroy_relative_pointer_manager(SDL_VideoData *d) { - if (d->relative_pointer_manager) + if (d->relative_pointer_manager) { zwp_relative_pointer_manager_v1_destroy(d->relative_pointer_manager); + } } void Wayland_display_add_pointer_constraints(SDL_VideoData *d, uint32_t id) @@ -2526,8 +2539,9 @@ void Wayland_display_add_pointer_constraints(SDL_VideoData *d, uint32_t id) void Wayland_display_destroy_pointer_constraints(SDL_VideoData *d) { - if (d->pointer_constraints) + if (d->pointer_constraints) { zwp_pointer_constraints_v1_destroy(d->pointer_constraints); + } } static void @@ -2592,8 +2606,9 @@ lock_pointer_to_window(SDL_Window *window, SDL_VideoData *d = input->display; struct zwp_locked_pointer_v1 *locked_pointer; - if (w->locked_pointer) + if (w->locked_pointer) { return; + } locked_pointer = zwp_pointer_constraints_v1_lock_pointer(d->pointer_constraints, @@ -2624,20 +2639,24 @@ int Wayland_input_lock_pointer(struct SDL_WaylandInput *input) SDL_Window *window; struct zwp_relative_pointer_v1 *relative_pointer; - if (!d->relative_pointer_manager) + if (!d->relative_pointer_manager) { return -1; + } - if (!d->pointer_constraints) + if (!d->pointer_constraints) { return -1; + } - if (!input->pointer) + if (!input->pointer) { return -1; + } /* If we have a pointer confine active, we must destroy it here because * creating a locked pointer otherwise would be a protocol error. */ - for (window = vd->windows; window; window = window->next) + for (window = vd->windows; window; window = window->next) { pointer_confine_destroy(window); + } if (!input->relative_pointer) { relative_pointer = @@ -2650,8 +2669,9 @@ int Wayland_input_lock_pointer(struct SDL_WaylandInput *input) input->relative_pointer = relative_pointer; } - for (window = vd->windows; window; window = window->next) + for (window = vd->windows; window; window = window->next) { lock_pointer_to_window(window, input); + } d->relative_mouse_mode = 1; @@ -2667,8 +2687,9 @@ int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input) for (window = vd->windows; window; window = window->next) { w = window->driverdata; - if (w->locked_pointer) + if (w->locked_pointer) { zwp_locked_pointer_v1_destroy(w->locked_pointer); + } w->locked_pointer = NULL; } @@ -2677,8 +2698,9 @@ int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input) d->relative_mouse_mode = 0; - for (window = vd->windows; window; window = window->next) + for (window = vd->windows; window; window = window->next) { Wayland_input_confine_pointer(input, window); + } return 0; } @@ -2707,11 +2729,13 @@ int Wayland_input_confine_pointer(struct SDL_WaylandInput *input, SDL_Window *wi struct zwp_confined_pointer_v1 *confined_pointer; struct wl_region *confine_rect; - if (!d->pointer_constraints) + if (!d->pointer_constraints) { return -1; + } - if (!input->pointer) + if (!input->pointer) { return -1; + } /* A confine may already be active, in which case we should destroy it and * create a new one. @@ -2721,12 +2745,14 @@ int Wayland_input_confine_pointer(struct SDL_WaylandInput *input, SDL_Window *wi /* We cannot create a confine if the pointer is already locked. Defer until * the pointer is unlocked. */ - if (d->relative_mouse_mode) + if (d->relative_mouse_mode) { return 0; + } /* Don't confine the pointer if it shouldn't be confined. */ - if (SDL_RectEmpty(&window->mouse_rect) && !(window->flags & SDL_WINDOW_MOUSE_GRABBED)) + if (SDL_RectEmpty(&window->mouse_rect) && !(window->flags & SDL_WINDOW_MOUSE_GRABBED)) { return 0; + } if (SDL_RectEmpty(&window->mouse_rect)) { confine_rect = NULL; @@ -2775,11 +2801,13 @@ int Wayland_input_grab_keyboard(SDL_Window *window, struct SDL_WaylandInput *inp SDL_WindowData *w = window->driverdata; SDL_VideoData *d = input->display; - if (!d->key_inhibitor_manager) + if (!d->key_inhibitor_manager) { return -1; + } - if (w->key_inhibitor) + if (w->key_inhibitor) { return 0; + } w->key_inhibitor = zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(d->key_inhibitor_manager, diff --git a/src/video/wayland/SDL_waylandkeyboard.c b/src/video/wayland/SDL_waylandkeyboard.c index 5cea5effcb..1f3900b019 100644 --- a/src/video/wayland/SDL_waylandkeyboard.c +++ b/src/video/wayland/SDL_waylandkeyboard.c @@ -62,8 +62,9 @@ Wayland_StartTextInput(_THIS) const SDL_Rect *rect = &input->text_input->cursor_rect; /* Don't re-enable if we're already enabled. */ - if (input->text_input->is_enabled) + if (input->text_input->is_enabled) { return; + } /* For some reason this has to be done twice, it appears to be a * bug in mutter? Maybe? @@ -118,7 +119,7 @@ Wayland_SetTextInputRect(_THIS, const SDL_Rect *rect) { SDL_VideoData *driverdata = _this->driverdata; - if (!rect) { + if (rect == NULL) { SDL_InvalidParamError("rect"); return; } @@ -126,8 +127,7 @@ Wayland_SetTextInputRect(_THIS, const SDL_Rect *rect) if (driverdata->text_input_manager) { struct SDL_WaylandInput *input = driverdata->input; if (input != NULL && input->text_input) { - if (!SDL_RectEquals(rect, &input->text_input->cursor_rect)) - { + if (!SDL_RectEquals(rect, &input->text_input->cursor_rect)) { SDL_copyp(&input->text_input->cursor_rect, rect); zwp_text_input_v3_set_cursor_rectangle(input->text_input->text_input, rect->x, @@ -156,7 +156,7 @@ Wayland_HasScreenKeyboardSupport(_THIS) SDL_VideoData *driverdata = _this->driverdata; SDL_bool haskeyboard = (driverdata->input != NULL) && (driverdata->input->keyboard != NULL); SDL_bool hastextmanager = (driverdata->text_input_manager != NULL); - return (!haskeyboard && hastextmanager); + return !haskeyboard && hastextmanager; } #endif /* SDL_VIDEO_DRIVER_WAYLAND */ diff --git a/src/video/wayland/SDL_waylandmessagebox.c b/src/video/wayland/SDL_waylandmessagebox.c index 484eca5f28..fb711b7f4b 100644 --- a/src/video/wayland/SDL_waylandmessagebox.c +++ b/src/video/wayland/SDL_waylandmessagebox.c @@ -139,14 +139,14 @@ Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) } } output = SDL_malloc(output_len + 1); - if (!output) { + if (output == NULL) { close(fd_pipe[0]); return SDL_OutOfMemory(); } output[0] = '\0'; outputfp = fdopen(fd_pipe[0], "r"); - if (!outputfp) { + if (outputfp == NULL) { SDL_free(output); close(fd_pipe[0]); return SDL_SetError("Couldn't open pipe for reading: %s", strerror(errno)); diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c index 7884fb93ed..7edba9f811 100644 --- a/src/video/wayland/SDL_waylandmouse.c +++ b/src/video/wayland/SDL_waylandmouse.c @@ -116,7 +116,7 @@ wayland_dbus_read_cursor_size(int *size) DBusMessage *reply; SDL_DBusContext *dbus = SDL_DBus_GetContext(); - if (!dbus || !size) { + if (dbus == NULL || size == NULL) { return SDL_FALSE; } @@ -139,7 +139,7 @@ wayland_dbus_read_cursor_theme(char **theme) DBusMessage *reply; SDL_DBusContext *dbus = SDL_DBus_GetContext(); - if (!dbus || !theme) { + if (dbus == NULL || theme == NULL) { return SDL_FALSE; } @@ -295,7 +295,7 @@ wayland_create_tmp_file(off_t size) int fd; xdg_path = SDL_getenv("XDG_RUNTIME_DIR"); - if (!xdg_path) { + if (xdg_path == NULL) { return -1; } @@ -303,8 +303,9 @@ wayland_create_tmp_file(off_t size) SDL_strlcat(tmp_path, template, PATH_MAX); fd = mkostemp(tmp_path, O_CLOEXEC); - if (fd < 0) + if (fd < 0) { return -1; + } if (ftruncate(fd, size) < 0) { close(fd); @@ -339,8 +340,7 @@ create_buffer_from_shm(Wayland_CursorData *d, int shm_fd; shm_fd = wayland_create_tmp_file(size); - if (shm_fd < 0) - { + if (shm_fd < 0) { return SDL_SetError("Creating mouse cursor buffer failed."); } @@ -385,7 +385,7 @@ Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) SDL_VideoDevice *vd = SDL_GetVideoDevice (); SDL_VideoData *wd = (SDL_VideoData *) vd->driverdata; Wayland_CursorData *data = SDL_calloc (1, sizeof (Wayland_CursorData)); - if (!data) { + if (data == NULL) { SDL_OutOfMemory(); SDL_free(cursor); return NULL; @@ -431,7 +431,7 @@ Wayland_CreateSystemCursor(SDL_SystemCursor id) cursor = SDL_calloc(1, sizeof (*cursor)); if (cursor) { Wayland_CursorData *cdata = SDL_calloc (1, sizeof (Wayland_CursorData)); - if (!cdata) { + if (cdata == NULL) { SDL_OutOfMemory(); SDL_free(cursor); return NULL; @@ -477,7 +477,7 @@ Wayland_FreeCursorData(Wayland_CursorData *d) static void Wayland_FreeCursor(SDL_Cursor *cursor) { - if (!cursor) { + if (cursor == NULL) { return; } @@ -502,11 +502,11 @@ Wayland_ShowCursor(SDL_Cursor *cursor) struct wl_pointer *pointer = d->pointer; float scale = 1.0f; - if (!pointer) + if (pointer == NULL) { return -1; + } - if (cursor) - { + if (cursor) { Wayland_CursorData *data = cursor->driverdata; /* TODO: High-DPI custom cursors? -flibit */ @@ -533,9 +533,7 @@ Wayland_ShowCursor(SDL_Cursor *cursor) input->relative_mode_override = SDL_FALSE; } - } - else - { + } else { input->cursor_visible = SDL_FALSE; wl_pointer_set_cursor(pointer, input->pointer_enter_serial, NULL, 0, 0); } @@ -577,8 +575,9 @@ Wayland_SetRelativeMouseMode(SDL_bool enabled) if (enabled) { /* Disable mouse warp emulation if it's enabled. */ - if (data->input->relative_mode_override) + if (data->input->relative_mode_override) { data->input->relative_mode_override = SDL_FALSE; + } /* If the app has used relative mode before, it probably shouldn't * also be emulating it using repeated mouse warps, so disable diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c index 72346348ed..1026b92de5 100644 --- a/src/video/wayland/SDL_waylandopengles.c +++ b/src/video/wayland/SDL_waylandopengles.c @@ -184,8 +184,7 @@ Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) if (window && context) { ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); - } - else { + } else { ret = SDL_EGL_MakeCurrent(_this, NULL, NULL); } diff --git a/src/video/wayland/SDL_waylandtouch.h b/src/video/wayland/SDL_waylandtouch.h index e4436f9f4f..8487adb9af 100644 --- a/src/video/wayland/SDL_waylandtouch.h +++ b/src/video/wayland/SDL_waylandtouch.h @@ -99,7 +99,7 @@ qt_surface_extension_get_extended_surface(struct qt_surface_extension *qt_surfac id = wl_proxy_create((struct wl_proxy *) qt_surface_extension, &qt_extended_surface_interface); - if (!id) + if (id == NULL) return NULL; WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_surface_extension, diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 09c3125b5c..c2bf9228d6 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -200,7 +200,7 @@ Wayland_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_free(data); WAYLAND_wl_display_disconnect(display); SDL_WAYLAND_UnloadSymbols(); @@ -596,7 +596,7 @@ display_handle_done(void *data, if (driverdata->has_logical_size) { /* If xdg-output is present, calculate the true scale of the desktop */ driverdata->scale_factor = (float)native_mode.w / (float)driverdata->width; - } else { /* Scale the desktop coordinates, if xdg-output isn't present */ + } else { /* Scale the desktop coordinates, if xdg-output isn't present */ driverdata->width /= driverdata->scale_factor; driverdata->height /= driverdata->scale_factor; } @@ -702,7 +702,7 @@ Wayland_add_display(SDL_VideoData *d, uint32_t id) SDL_WaylandOutputData *data; output = wl_registry_bind(d->registry, id, &wl_output_interface, 2); - if (!output) { + if (output == NULL) { SDL_SetError("Failed to retrieve output."); return; } diff --git a/src/video/wayland/SDL_waylandvulkan.c b/src/video/wayland/SDL_waylandvulkan.c index 96b525adaa..3c6c169706 100644 --- a/src/video/wayland/SDL_waylandvulkan.c +++ b/src/video/wayland/SDL_waylandvulkan.c @@ -49,51 +49,56 @@ int Wayland_Vulkan_LoadLibrary(_THIS, const char *path) SDL_bool hasSurfaceExtension = SDL_FALSE; SDL_bool hasWaylandSurfaceExtension = SDL_FALSE; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; - if(_this->vulkan_config.loader_handle) + if (_this->vulkan_config.loader_handle) { return SDL_SetError("Vulkan already loaded"); + } /* Load the Vulkan loader library */ - if(!path) + if (path == NULL) { path = SDL_getenv("SDL_VULKAN_LIBRARY"); - if(!path) + } + if (path == NULL) { path = DEFAULT_VULKAN; + } _this->vulkan_config.loader_handle = SDL_LoadObject(path); - if(!_this->vulkan_config.loader_handle) + if (!_this->vulkan_config.loader_handle) { return -1; + } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); - if(!vkGetInstanceProcAddr) + if (!vkGetInstanceProcAddr) { goto fail; + } _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr; _this->vulkan_config.vkEnumerateInstanceExtensionProperties = (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)( VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties"); - if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) + if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) { goto fail; + } extensions = SDL_Vulkan_CreateInstanceExtensionsList( (PFN_vkEnumerateInstanceExtensionProperties) _this->vulkan_config.vkEnumerateInstanceExtensionProperties, &extensionCount); - if(!extensions) + if (extensions == NULL) { goto fail; - for(i = 0; i < extensionCount; i++) + } + for (i = 0; i < extensionCount; i++) { - if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasSurfaceExtension = SDL_TRUE; - else if(SDL_strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + } else if (SDL_strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasWaylandSurfaceExtension = SDL_TRUE; + } } SDL_free(extensions); - if(!hasSurfaceExtension) - { + if (!hasSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension"); goto fail; - } - else if(!hasWaylandSurfaceExtension) - { + } else if (!hasWaylandSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "extension"); goto fail; @@ -108,8 +113,7 @@ fail: void Wayland_Vulkan_UnloadLibrary(_THIS) { - if(_this->vulkan_config.loader_handle) - { + if (_this->vulkan_config.loader_handle) { SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; } @@ -123,8 +127,7 @@ SDL_bool Wayland_Vulkan_GetInstanceExtensions(_THIS, static const char *const extensionsForWayland[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME }; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } @@ -148,14 +151,12 @@ SDL_bool Wayland_Vulkan_CreateSurface(_THIS, VkWaylandSurfaceCreateInfoKHR createInfo; VkResult result; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } - if(!vkCreateWaylandSurfaceKHR) - { + if (!vkCreateWaylandSurfaceKHR) { SDL_SetError(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); return SDL_FALSE; @@ -168,8 +169,7 @@ SDL_bool Wayland_Vulkan_CreateSurface(_THIS, createInfo.surface = windowData->surface; result = vkCreateWaylandSurfaceKHR(instance, &createInfo, NULL, surface); - if(result != VK_SUCCESS) - { + if (result != VK_SUCCESS) { SDL_SetError("vkCreateWaylandSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); return SDL_FALSE; diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index d37a526a58..c3835ce318 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -1898,8 +1898,9 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window) SDL_VideoData *c; data = SDL_calloc(1, sizeof *data); - if (data == NULL) + if (data == NULL) { return SDL_OutOfMemory(); + } c = _this->driverdata; window->driverdata = data; diff --git a/src/video/windows/SDL_windowsclipboard.c b/src/video/windows/SDL_windowsclipboard.c index e961a2be4d..4ba650e2e7 100644 --- a/src/video/windows/SDL_windowsclipboard.c +++ b/src/video/windows/SDL_windowsclipboard.c @@ -125,7 +125,7 @@ WIN_GetClipboardText(_THIS) } CloseClipboard(); } - if (!text) { + if (text == NULL) { text = SDL_strdup(""); } return text; diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index c230df8ccc..49680bffe0 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -277,8 +277,7 @@ WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, Uint32 mouseFlags, SDL_ if (bSwapButtons) { if (button == SDL_BUTTON_LEFT) { button = SDL_BUTTON_RIGHT; - } - else if (button == SDL_BUTTON_RIGHT) { + } else if (button == SDL_BUTTON_RIGHT) { button = SDL_BUTTON_LEFT; } } @@ -331,26 +330,36 @@ WIN_CheckRawMouseButtons(ULONG rawButtons, SDL_WindowData *data, SDL_MouseID mou if (rawButtons != data->mouse_button_flags) { Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL); SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0; - if ((rawButtons & RI_MOUSE_BUTTON_1_DOWN)) + if ((rawButtons & RI_MOUSE_BUTTON_1_DOWN)) { WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_1_DOWN), mouseFlags, swapButtons, data, SDL_BUTTON_LEFT, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_1_UP)) + } + if ((rawButtons & RI_MOUSE_BUTTON_1_UP)) { WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_1_UP), mouseFlags, swapButtons, data, SDL_BUTTON_LEFT, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_2_DOWN)) + } + if ((rawButtons & RI_MOUSE_BUTTON_2_DOWN)) { WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_2_DOWN), mouseFlags, swapButtons, data, SDL_BUTTON_RIGHT, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_2_UP)) + } + if ((rawButtons & RI_MOUSE_BUTTON_2_UP)) { WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_2_UP), mouseFlags, swapButtons, data, SDL_BUTTON_RIGHT, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_3_DOWN)) + } + if ((rawButtons & RI_MOUSE_BUTTON_3_DOWN)) { WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_3_DOWN), mouseFlags, swapButtons, data, SDL_BUTTON_MIDDLE, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_3_UP)) + } + if ((rawButtons & RI_MOUSE_BUTTON_3_UP)) { WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_3_UP), mouseFlags, swapButtons, data, SDL_BUTTON_MIDDLE, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_4_DOWN)) + } + if ((rawButtons & RI_MOUSE_BUTTON_4_DOWN)) { WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_4_DOWN), mouseFlags, swapButtons, data, SDL_BUTTON_X1, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_4_UP)) + } + if ((rawButtons & RI_MOUSE_BUTTON_4_UP)) { WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_4_UP), mouseFlags, swapButtons, data, SDL_BUTTON_X1, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_5_DOWN)) + } + if ((rawButtons & RI_MOUSE_BUTTON_5_DOWN)) { WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_5_DOWN), mouseFlags, swapButtons, data, SDL_BUTTON_X2, mouseID); - if ((rawButtons & RI_MOUSE_BUTTON_5_UP)) + } + if ((rawButtons & RI_MOUSE_BUTTON_5_UP)) { WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_5_UP), mouseFlags, swapButtons, data, SDL_BUTTON_X2, mouseID); + } data->mouse_button_flags = rawButtons; } } @@ -649,12 +658,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) /* Get the window data for the window */ data = WIN_GetWindowDataFromHWND(hwnd); #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - if (!data) { + if (data == NULL) { /* Fallback */ data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData")); } #endif - if (!data) { + if (data == NULL) { return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam); } @@ -671,8 +680,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) #endif /* WMMSG_DEBUG */ #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata)) + if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata)) { return 0; + } #endif switch (msg) { @@ -1270,8 +1280,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) /* We'll do our own drawing, prevent flicker */ case WM_ERASEBKGND: - if (!data->videodata->cleared) - { + if (!data->videodata->cleared) { RECT client_rect; HBRUSH brush; data->videodata->cleared = SDL_TRUE; @@ -1280,12 +1289,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) FillRect(GetDC(hwnd), &client_rect, brush); DeleteObject(brush); } - return (1); + return 1; case WM_SYSCOMMAND: { if ((wParam & 0xFFF0) == SC_KEYMENU) { - return (0); + return 0; } #if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER) @@ -1293,7 +1302,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if ((wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER) { if (SDL_GetVideoDevice()->suspend_screensaver) { - return (0); + return 0; } } #endif /* System has screensaver support */ @@ -1371,15 +1380,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) * If we're handling our own touches, we don't want any gestures. * Not all of these settings are documented. * The use of the undocumented ones was suggested by https://github.com/bjarkeck/GCGJ/blob/master/Monogame/Windows/WinFormsGameForm.cs . */ - return TABLET_DISABLE_PRESSANDHOLD | /* disables press and hold (right-click) gesture */ - TABLET_DISABLE_PENTAPFEEDBACK | /* disables UI feedback on pen up (waves) */ - TABLET_DISABLE_PENBARRELFEEDBACK | /* disables UI feedback on pen button down (circle) */ - TABLET_DISABLE_TOUCHUIFORCEON | - TABLET_DISABLE_TOUCHUIFORCEOFF | - TABLET_DISABLE_TOUCHSWITCH | - TABLET_DISABLE_FLICKS | /* disables pen flicks (back, forward, drag down, drag up) */ - TABLET_DISABLE_SMOOTHSCROLLING | - TABLET_DISABLE_FLICKFALLBACKKEYS; + return TABLET_DISABLE_PRESSANDHOLD | TABLET_DISABLE_PENTAPFEEDBACK | TABLET_DISABLE_PENBARRELFEEDBACK | TABLET_DISABLE_TOUCHUIFORCEON | TABLET_DISABLE_TOUCHUIFORCEOFF | TABLET_DISABLE_TOUCHSWITCH | TABLET_DISABLE_FLICKS | TABLET_DISABLE_SMOOTHSCROLLING | TABLET_DISABLE_FLICKFALLBACKKEYS; /* disables press and hold (right-click) gesture */ + /* disables UI feedback on pen up (waves) */ + /* disables UI feedback on pen button down (circle) */ + /* disables pen flicks (back, forward, drag down, drag up) */ #endif /* HAVE_TPCSHRD_H */ @@ -1838,7 +1842,7 @@ WIN_PumpEvents(_THIS) not grabbing the keyboard. Note: If we *are* grabbing the keyboard, GetKeyState() will return inaccurate results for VK_LWIN and VK_RWIN but we don't need it anyway. */ focusWindow = SDL_GetKeyboardFocus(); - if (!focusWindow || !(focusWindow->flags & SDL_WINDOW_KEYBOARD_GRABBED)) { + if (focusWindow == NULL || !(focusWindow->flags & SDL_WINDOW_KEYBOARD_GRABBED)) { if ((keystate[SDL_SCANCODE_LGUI] == SDL_PRESSED) && !(GetKeyState(VK_LWIN) & 0x8000)) { SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LGUI); } @@ -1868,8 +1872,12 @@ HINSTANCE SDL_Instance = NULL; static void WIN_CleanRegisterApp(WNDCLASSEX wcex) { #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - if (wcex.hIcon) DestroyIcon(wcex.hIcon); - if (wcex.hIconSm) DestroyIcon(wcex.hIconSm); + if (wcex.hIcon) { + DestroyIcon(wcex.hIcon); + } + if (wcex.hIconSm) { + DestroyIcon(wcex.hIconSm); + } #endif SDL_free(SDL_Appname); SDL_Appname = NULL; @@ -1888,10 +1896,10 @@ SDL_RegisterApp(const char *name, Uint32 style, void *hInst) /* Only do this once... */ if (app_registered) { ++app_registered; - return (0); + return 0; } SDL_assert(SDL_Appname == NULL); - if (!name) { + if (name == NULL) { name = "SDL_app"; #if defined(CS_BYTEALIGNCLIENT) || defined(CS_OWNDC) style = (CS_BYTEALIGNCLIENT | CS_OWNDC); diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c index 4076e6f52e..389cf94f82 100644 --- a/src/video/windows/SDL_windowsframebuffer.c +++ b/src/video/windows/SDL_windowsframebuffer.c @@ -65,8 +65,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi masks = (Uint32*)((Uint8*)info + info->bmiHeader.biSize); *format = SDL_MasksToPixelFormatEnum(bpp, masks[0], masks[1], masks[2], 0); } - if (*format == SDL_PIXELFORMAT_UNKNOWN) - { + if (*format == SDL_PIXELFORMAT_UNKNOWN) { /* We'll use RGB format for now */ *format = SDL_PIXELFORMAT_RGB888; @@ -112,7 +111,7 @@ void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; - if (!data) { + if (data == NULL) { /* The window wasn't fully initialized */ return; } diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index bd9dacc183..ba2570950a 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -248,7 +248,7 @@ WIN_SetTextInputRect(_THIS, const SDL_Rect *rect) SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; HIMC himc = 0; - if (!rect) { + if (rect == NULL) { SDL_InvalidParamError("rect"); return; } @@ -257,8 +257,7 @@ WIN_SetTextInputRect(_THIS, const SDL_Rect *rect) videodata->ime_rect = *rect; himc = ImmGetContext(videodata->ime_hwnd_current); - if (himc) - { + if (himc) { COMPOSITIONFORM cof; CANDIDATEFORM caf; @@ -437,15 +436,17 @@ IME_Init(SDL_VideoData *videodata, HWND hwnd) static void IME_Enable(SDL_VideoData *videodata, HWND hwnd) { - if (!videodata->ime_initialized || !videodata->ime_hwnd_current) + if (!videodata->ime_initialized || !videodata->ime_hwnd_current) { return; + } if (!videodata->ime_available) { IME_Disable(videodata, hwnd); return; } - if (videodata->ime_hwnd_current == videodata->ime_hwnd_main) + if (videodata->ime_hwnd_current == videodata->ime_hwnd_main) { ImmAssociateContext(videodata->ime_hwnd_current, videodata->ime_himc); + } videodata->ime_enabled = SDL_TRUE; IME_UpdateInputLocale(videodata); @@ -455,12 +456,14 @@ IME_Enable(SDL_VideoData *videodata, HWND hwnd) static void IME_Disable(SDL_VideoData *videodata, HWND hwnd) { - if (!videodata->ime_initialized || !videodata->ime_hwnd_current) + if (!videodata->ime_initialized || !videodata->ime_hwnd_current) { return; + } IME_ClearComposition(videodata); - if (videodata->ime_hwnd_current == videodata->ime_hwnd_main) + if (videodata->ime_hwnd_current == videodata->ime_hwnd_main) { ImmAssociateContext(videodata->ime_hwnd_current, (HIMC)0); + } videodata->ime_enabled = SDL_FALSE; UILess_DisableUIUpdates(videodata); @@ -469,12 +472,14 @@ IME_Disable(SDL_VideoData *videodata, HWND hwnd) static void IME_Quit(SDL_VideoData *videodata) { - if (!videodata->ime_initialized) + if (!videodata->ime_initialized) { return; + } UILess_ReleaseSinks(videodata); - if (videodata->ime_hwnd_main) + if (videodata->ime_hwnd_main) { ImmAssociateContext(videodata->ime_hwnd_main, videodata->ime_himc); + } videodata->ime_hwnd_main = 0; videodata->ime_himc = 0; @@ -506,30 +511,33 @@ IME_GetReadingString(SDL_VideoData *videodata, HWND hwnd) BOOL vertical = FALSE; UINT maxuilen = 0; - if (videodata->ime_uiless) + if (videodata->ime_uiless) { return; + } videodata->ime_readingstring[0] = 0; id = IME_GetId(videodata, 0); - if (!id) + if (!id) { return; + } himc = ImmGetContext(hwnd); - if (!himc) + if (!himc) { return; + } if (videodata->GetReadingString) { len = videodata->GetReadingString(himc, 0, 0, &err, &vertical, &maxuilen); if (len) { - if (len > SDL_arraysize(buffer)) + if (len > SDL_arraysize(buffer)) { len = SDL_arraysize(buffer); + } len = videodata->GetReadingString(himc, len, s, &err, &vertical, &maxuilen); } SDL_wcslcpy(videodata->ime_readingstring, s, len); - } - else { + } else { LPINPUTCONTEXT2 lpimc = videodata->ImmLockIMC(himc); LPBYTE p = 0; s = 0; @@ -539,8 +547,9 @@ IME_GetReadingString(SDL_VideoData *videodata, HWND hwnd) case IMEID_CHT_VER43: case IMEID_CHT_VER44: p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 24); - if (!p) + if (!p) { break; + } len = *(DWORD *)(p + 7*4 + 32*4); s = (WCHAR *)(p + 56); @@ -549,12 +558,14 @@ IME_GetReadingString(SDL_VideoData *videodata, HWND hwnd) case IMEID_CHT_VER52: case IMEID_CHS_VER53: p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 4); - if (!p) + if (!p) { break; + } p = *(LPBYTE *)((LPBYTE)p + 1*4 + 5*4); - if (!p) + if (!p) { break; + } len = *(DWORD *)(p + 1*4 + (16*2+2*4) + 5*4 + 16*2); s = (WCHAR *)(p + 1*4 + (16*2+2*4) + 5*4); @@ -563,8 +574,9 @@ IME_GetReadingString(SDL_VideoData *videodata, HWND hwnd) { int offset = (IME_GetId(videodata, 1) >= 0x00000002) ? 8 : 7; p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + offset * 4); - if (!p) + if (!p) { break; + } len = *(DWORD *)(p + 7*4 + 16*2*4); s = (WCHAR *)(p + 6*4 + 16*2*1); @@ -572,8 +584,9 @@ IME_GetReadingString(SDL_VideoData *videodata, HWND hwnd) break; case IMEID_CHS_VER42: p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 1*4 + 1*4 + 6*4); - if (!p) + if (!p) { break; + } len = *(DWORD *)(p + 1*4 + (16*2+2*4) + 5*4 + 16*2); s = (WCHAR *)(p + 1*4 + (16*2+2*4) + 5*4); @@ -596,8 +609,9 @@ IME_InputLangChanged(SDL_VideoData *videodata) { UINT lang = PRIMLANG(); IME_UpdateInputLocale(videodata); - if (!videodata->ime_uiless) + if (!videodata->ime_uiless) { videodata->ime_candlistindexbase = (videodata->ime_hkl == CHT_HKL_DAYI) ? 0 : 1; + } IME_SetupAPI(videodata); if (lang != PRIMLANG()) { @@ -621,8 +635,9 @@ IME_GetId(SDL_VideoData *videodata, UINT uIndex) SDL_assert(uIndex < sizeof(dwRet) / sizeof(dwRet[0])); hkl = videodata->ime_hkl; - if (hklprev == hkl) + if (hklprev == hkl) { return dwRet[uIndex]; + } hklprev = hkl; SDL_assert(uIndex == 0); @@ -702,16 +717,19 @@ IME_SetupAPI(SDL_VideoData *videodata) HKL hkl = 0; videodata->GetReadingString = 0; videodata->ShowReadingWindow = 0; - if (videodata->ime_uiless) + if (videodata->ime_uiless) { return; + } hkl = videodata->ime_hkl; - if (!ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1)) + if (!ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1)) { return; + } hime = SDL_LoadObject(ime_file); - if (!hime) + if (hime == NULL) { return; + } videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT)) SDL_LoadFunction(hime, "GetReadingString"); @@ -734,8 +752,9 @@ IME_SetWindow(SDL_VideoData* videodata, HWND hwnd) if (videodata->ime_threadmgr) { struct ITfDocumentMgr *document_mgr = 0; if (SUCCEEDED(videodata->ime_threadmgr->lpVtbl->AssociateFocus(videodata->ime_threadmgr, hwnd, NULL, &document_mgr))) { - if (document_mgr) + if (document_mgr) { document_mgr->lpVtbl->Release(document_mgr); + } } } } @@ -745,8 +764,9 @@ IME_UpdateInputLocale(SDL_VideoData *videodata) { HKL hklnext = GetKeyboardLayout(0); - if (hklnext == videodata->ime_hkl) + if (hklnext == videodata->ime_hkl) { return; + } videodata->ime_hkl = hklnext; videodata->ime_candvertical = (PRIMLANG() == LANG_KOREAN || LANG() == LANG_CHS) ? SDL_FALSE : SDL_TRUE; @@ -756,16 +776,19 @@ static void IME_ClearComposition(SDL_VideoData *videodata) { HIMC himc = 0; - if (!videodata->ime_initialized) + if (!videodata->ime_initialized) { return; + } himc = ImmGetContext(videodata->ime_hwnd_current); - if (!himc) + if (!himc) { return; + } ImmNotifyIME(himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0); - if (videodata->ime_uiless) + if (videodata->ime_uiless) { ImmSetCompositionString(himc, SCS_SETSTR, TEXT(""), sizeof(TCHAR), TEXT(""), sizeof(TCHAR)); + } ImmNotifyIME(himc, NI_CLOSECANDIDATE, 0, 0); ImmReleaseContext(videodata->ime_hwnd_current, himc); @@ -775,8 +798,9 @@ IME_ClearComposition(SDL_VideoData *videodata) static SDL_bool IME_IsTextInputShown(SDL_VideoData* videodata) { - if (!videodata->ime_initialized || !videodata->ime_available || !videodata->ime_enabled) + if (!videodata->ime_initialized || !videodata->ime_available || !videodata->ime_enabled) { return SDL_FALSE; + } return videodata->ime_uicontext != 0 ? SDL_TRUE : SDL_FALSE; } @@ -789,8 +813,9 @@ IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD string) length = ImmGetCompositionStringW(himc, string, NULL, 0); if (length > 0 && videodata->ime_composition_length < length) { - if (videodata->ime_composition != NULL) + if (videodata->ime_composition != NULL) { SDL_free(videodata->ime_composition); + } videodata->ime_composition = (WCHAR*)SDL_malloc(length + sizeof(WCHAR)); videodata->ime_composition_length = length; @@ -803,8 +828,9 @@ IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD string) videodata->ime_composition_length ); - if (length < 0) + if (length < 0) { length = 0; + } length /= sizeof(WCHAR); videodata->ime_cursor = LOWORD(ImmGetCompositionStringW(himc, GCS_CURSORPOS, 0, 0)); @@ -815,8 +841,9 @@ IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD string) // Traditional Chinese IMEs add a placeholder U+3000 // Simplified Chinese IMEs seem to add a placeholder U+0020 sometimes int i; - for (i = videodata->ime_cursor + 1; i < length; ++i) + for (i = videodata->ime_cursor + 1; i < length; ++i) { videodata->ime_composition[i - 1] = videodata->ime_composition[i]; + } --length; } @@ -834,15 +861,15 @@ IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD string) ImmGetCompositionString(himc, GCS_COMPATTR, attributes, length); for (start = 0; start < length; ++start) { - if (attributes[start] == ATTR_TARGET_CONVERTED || - attributes[start] == ATTR_TARGET_NOTCONVERTED) + if (attributes[start] == ATTR_TARGET_CONVERTED || attributes[start] == ATTR_TARGET_NOTCONVERTED) { break; + } } for (end = start; end < length; ++end) { - if (attributes[end] != ATTR_TARGET_CONVERTED && - attributes[end] != ATTR_TARGET_NOTCONVERTED) + if (attributes[end] != ATTR_TARGET_CONVERTED && attributes[end] != ATTR_TARGET_NOTCONVERTED) { break; + } } if (start == length) { @@ -886,8 +913,7 @@ IME_SendEditingEvent(SDL_VideoData *videodata) SDL_wcslcpy(buffer, videodata->ime_composition, len + 1); SDL_wcslcat(buffer, videodata->ime_readingstring, size); SDL_wcslcat(buffer, &videodata->ime_composition[len], size); - } - else { + } else { buffer = (WCHAR*)SDL_malloc(size + sizeof(WCHAR)); buffer[0] = 0; SDL_wcslcpy(buffer, videodata->ime_composition, size); @@ -906,11 +932,13 @@ IME_AddCandidate(SDL_VideoData *videodata, UINT i, LPCWSTR candidate) LPWSTR end = &dst[MAX_CANDLENGTH - 1]; SDL_COMPILE_TIME_ASSERT(IME_CANDIDATE_INDEXING_REQUIRES, MAX_CANDLIST == 10); *dst++ = (WCHAR)(TEXT('0') + ((i + videodata->ime_candlistindexbase) % 10)); - if (videodata->ime_candvertical) + if (videodata->ime_candvertical) { *dst++ = TEXT(' '); + } - while (*candidate && dst < end) + while (*candidate && dst < end) { *dst++ = *candidate++; + } *dst = (WCHAR)'\0'; } @@ -922,11 +950,13 @@ IME_GetCandidateList(HWND hwnd, SDL_VideoData *videodata) DWORD size; LPCANDIDATELIST cand_list; - if (IME_ShowCandidateList(videodata) < 0) + if (IME_ShowCandidateList(videodata) < 0) { return; + } himc = ImmGetContext(hwnd); - if (!himc) + if (!himc) { return; + } size = ImmGetCandidateListW(himc, 0, 0, 0); if (size != 0) { cand_list = (LPCANDIDATELIST)SDL_malloc(size); @@ -945,13 +975,13 @@ IME_GetCandidateList(HWND hwnd, SDL_VideoData *videodata) for (i = 0; i < videodata->ime_candcount; ++i) { size_t len = SDL_wcslen((LPWSTR)((DWORD_PTR)cand_list + cand_list->dwOffset[i])) + 1; if (len + cchars > maxcandchar) { - if (i > cand_list->dwSelection) + if (i > cand_list->dwSelection) { break; + } page_start = i; cchars = len; - } - else { + } else { cchars += len; } } @@ -982,11 +1012,13 @@ IME_ShowCandidateList(SDL_VideoData *videodata) videodata->ime_candcount = 0; candidates = SDL_realloc(videodata->ime_candidates, MAX_CANDSIZE); - if (candidates != NULL) + if (candidates != NULL) { videodata->ime_candidates = (WCHAR *)candidates; + } - if (videodata->ime_candidates == NULL) + if (videodata->ime_candidates == NULL) { return -1; + } SDL_memset(videodata->ime_candidates, 0, MAX_CANDSIZE); @@ -1011,17 +1043,16 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD { SDL_bool trap = SDL_FALSE; HIMC himc = 0; - if (!videodata->ime_initialized || !videodata->ime_available || !videodata->ime_enabled) + if (!videodata->ime_initialized || !videodata->ime_available || !videodata->ime_enabled) { return SDL_FALSE; + } switch (msg) { case WM_KEYDOWN: - if (wParam == VK_PROCESSKEY) - { + if (wParam == VK_PROCESSKEY) { videodata->ime_uicontext = 1; trap = SDL_TRUE; - } - else + } else videodata->ime_uicontext = 0; break; case WM_INPUTLANGCHANGE: @@ -1046,8 +1077,9 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD IME_SendInputEvent(videodata); } if (*lParam & GCS_COMPSTR) { - if (!videodata->ime_uiless) + if (!videodata->ime_uiless) { videodata->ime_readingstring[0] = 0; + } IME_GetCompositionString(videodata, himc, GCS_COMPSTR); IME_SendEditingEvent(videodata); @@ -1059,8 +1091,9 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD videodata->ime_composition[0] = 0; videodata->ime_readingstring[0] = 0; videodata->ime_cursor = 0; - if (videodata->ime_suppress_endcomposition_event == SDL_FALSE) + if (videodata->ime_suppress_endcomposition_event == SDL_FALSE) { SDL_SendEditingText("", 0, 0); + } videodata->ime_suppress_endcomposition_event = SDL_FALSE; break; case WM_IME_NOTIFY: @@ -1071,8 +1104,9 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD break; case IMN_OPENCANDIDATE: case IMN_CHANGECANDIDATE: - if (videodata->ime_uiless) + if (videodata->ime_uiless) { break; + } trap = SDL_TRUE; videodata->ime_uicontext = 1; @@ -1094,8 +1128,9 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD case IMEID_CHT_VER44: case IMEID_CHS_VER41: case IMEID_CHS_VER42: - if (*lParam == 1 || *lParam == 2) + if (*lParam == 1 || *lParam == 2) { trap = SDL_TRUE; + } break; case IMEID_CHT_VER50: @@ -1103,12 +1138,9 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD case IMEID_CHT_VER52: case IMEID_CHT_VER60: case IMEID_CHS_VER53: - if (*lParam == 16 - || *lParam == 17 - || *lParam == 26 - || *lParam == 27 - || *lParam == 28) + if (*lParam == 16 || *lParam == 17 || *lParam == 26 || *lParam == 27 || *lParam == 28) { trap = SDL_TRUE; + } break; } } @@ -1142,8 +1174,9 @@ UILess_GetCandidateList(SDL_VideoData *videodata, ITfCandidateListUIElement *pca DWORD pgsize = 0; UINT i, j; - if (IME_ShowCandidateList(videodata) < 0) + if (IME_ShowCandidateList(videodata) < 0) { return; + } pcandlist->lpVtbl->GetSelection(pcandlist, &selection); pcandlist->lpVtbl->GetCount(pcandlist, &count); @@ -1199,14 +1232,16 @@ STDMETHODIMP_(ULONG) TSFSink_Release(TSFSink *sink) STDMETHODIMP UIElementSink_QueryInterface(TSFSink *sink, REFIID riid, PVOID *ppv) { - if (!ppv) + if (ppv == NULL) { return E_INVALIDARG; + } *ppv = 0; - if (WIN_IsEqualIID(riid, &IID_IUnknown)) + if (WIN_IsEqualIID(riid, &IID_IUnknown)) { *ppv = (IUnknown *)sink; - else if (WIN_IsEqualIID(riid, &IID_ITfUIElementSink)) + } else if (WIN_IsEqualIID(riid, &IID_ITfUIElementSink)) { *ppv = (ITfUIElementSink *)sink; + } if (*ppv) { TSFSink_AddRef(sink); @@ -1234,8 +1269,9 @@ STDMETHODIMP UIElementSink_BeginUIElement(TSFSink *sink, DWORD dwUIElementId, BO ITfReadingInformationUIElement *preading = 0; ITfCandidateListUIElement *pcandlist = 0; SDL_VideoData *videodata = (SDL_VideoData *)sink->data; - if (!element) + if (element == NULL) { return E_INVALIDARG; + } *pbShow = FALSE; if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) { @@ -1244,8 +1280,7 @@ STDMETHODIMP UIElementSink_BeginUIElement(TSFSink *sink, DWORD dwUIElementId, BO SysFreeString(bstr); } preading->lpVtbl->Release(preading); - } - else if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfCandidateListUIElement, (LPVOID *)&pcandlist))) { + } else if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfCandidateListUIElement, (LPVOID *)&pcandlist))) { videodata->ime_candref++; UILess_GetCandidateList(videodata, pcandlist); pcandlist->lpVtbl->Release(pcandlist); @@ -1259,8 +1294,9 @@ STDMETHODIMP UIElementSink_UpdateUIElement(TSFSink *sink, DWORD dwUIElementId) ITfReadingInformationUIElement *preading = 0; ITfCandidateListUIElement *pcandlist = 0; SDL_VideoData *videodata = (SDL_VideoData *)sink->data; - if (!element) + if (element == NULL) { return E_INVALIDARG; + } if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) { BSTR bstr; @@ -1271,8 +1307,7 @@ STDMETHODIMP UIElementSink_UpdateUIElement(TSFSink *sink, DWORD dwUIElementId) SysFreeString(bstr); } preading->lpVtbl->Release(preading); - } - else if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfCandidateListUIElement, (LPVOID *)&pcandlist))) { + } else if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfCandidateListUIElement, (LPVOID *)&pcandlist))) { UILess_GetCandidateList(videodata, pcandlist); pcandlist->lpVtbl->Release(pcandlist); } @@ -1285,8 +1320,9 @@ STDMETHODIMP UIElementSink_EndUIElement(TSFSink *sink, DWORD dwUIElementId) ITfReadingInformationUIElement *preading = 0; ITfCandidateListUIElement *pcandlist = 0; SDL_VideoData *videodata = (SDL_VideoData *)sink->data; - if (!element) + if (element == NULL) { return E_INVALIDARG; + } if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) { videodata->ime_readingstring[0] = 0; @@ -1295,8 +1331,9 @@ STDMETHODIMP UIElementSink_EndUIElement(TSFSink *sink, DWORD dwUIElementId) } if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfCandidateListUIElement, (LPVOID *)&pcandlist))) { videodata->ime_candref--; - if (videodata->ime_candref == 0) + if (videodata->ime_candref == 0) { IME_CloseCandidateList(videodata); + } pcandlist->lpVtbl->Release(pcandlist); } @@ -1305,14 +1342,16 @@ STDMETHODIMP UIElementSink_EndUIElement(TSFSink *sink, DWORD dwUIElementId) STDMETHODIMP IPPASink_QueryInterface(TSFSink *sink, REFIID riid, PVOID *ppv) { - if (!ppv) + if (ppv == NULL) { return E_INVALIDARG; + } *ppv = 0; - if (WIN_IsEqualIID(riid, &IID_IUnknown)) + if (WIN_IsEqualIID(riid, &IID_IUnknown)) { *ppv = (IUnknown *)sink; - else if (WIN_IsEqualIID(riid, &IID_ITfInputProcessorProfileActivationSink)) + } else if (WIN_IsEqualIID(riid, &IID_ITfInputProcessorProfileActivationSink)) { *ppv = (ITfInputProcessorProfileActivationSink *)sink; + } if (*ppv) { TSFSink_AddRef(sink); @@ -1326,8 +1365,9 @@ STDMETHODIMP IPPASink_OnActivated(TSFSink *sink, DWORD dwProfileType, LANGID lan static const GUID TF_PROFILE_DAYI = { 0x037B2C25, 0x480C, 0x4D7F, { 0xB0, 0x27, 0xD6, 0xCA, 0x6B, 0x69, 0x78, 0x8A } }; SDL_VideoData *videodata = (SDL_VideoData *)sink->data; videodata->ime_candlistindexbase = WIN_IsEqualGUID(&TF_PROFILE_DAYI, guidProfile) ? 0 : 1; - if (WIN_IsEqualIID(catid, &GUID_TFCAT_TIP_KEYBOARD) && (dwFlags & TF_IPSINK_FLAG_ACTIVE)) + if (WIN_IsEqualIID(catid, &GUID_TFCAT_TIP_KEYBOARD) && (dwFlags & TF_IPSINK_FLAG_ACTIVE)) { IME_InputLangChanged((SDL_VideoData *)sink->data); + } IME_HideCandidateList(videodata); return S_OK; @@ -1353,8 +1393,9 @@ static void UILess_EnableUIUpdates(SDL_VideoData *videodata) { ITfSource *source = 0; - if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie != TF_INVALID_COOKIE) + if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie != TF_INVALID_COOKIE) { return; + } if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) { source->lpVtbl->AdviseSink(source, &IID_ITfUIElementSink, (IUnknown *)videodata->ime_uielemsink, &videodata->ime_uielemsinkcookie); @@ -1366,8 +1407,9 @@ static void UILess_DisableUIUpdates(SDL_VideoData *videodata) { ITfSource *source = 0; - if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie == TF_INVALID_COOKIE) + if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie == TF_INVALID_COOKIE) { return; + } if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) { source->lpVtbl->UnadviseSink(source, videodata->ime_uielemsinkcookie); @@ -1382,11 +1424,13 @@ UILess_SetupSinks(SDL_VideoData *videodata) TfClientId clientid = 0; SDL_bool result = SDL_FALSE; ITfSource *source = 0; - if (FAILED(CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgrEx, (LPVOID *)&videodata->ime_threadmgrex))) + if (FAILED(CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgrEx, (LPVOID *)&videodata->ime_threadmgrex))) { return SDL_FALSE; + } - if (FAILED(videodata->ime_threadmgrex->lpVtbl->ActivateEx(videodata->ime_threadmgrex, &clientid, TF_TMAE_UIELEMENTENABLEDONLY))) + if (FAILED(videodata->ime_threadmgrex->lpVtbl->ActivateEx(videodata->ime_threadmgrex, &clientid, TF_TMAE_UIELEMENTENABLEDONLY))) { return SDL_FALSE; + } videodata->ime_uielemsink = SDL_malloc(sizeof(TSFSink)); videodata->ime_ippasink = SDL_malloc(sizeof(TSFSink)); @@ -1450,8 +1494,9 @@ StartDrawToBitmap(HDC hdc, HBITMAP *hhbm, int width, int height) infoHeader->biBitCount = 32; infoHeader->biCompression = BI_RGB; *hhbm = CreateDIBSection(hdc, &info, DIB_RGB_COLORS, (void **)&bits, 0, 0); - if (*hhbm) + if (*hhbm) { SelectObject(hdc, *hhbm); + } } return bits; } @@ -1506,8 +1551,9 @@ IME_PositionCandidateList(SDL_VideoData *videodata, SIZE size) left -= right - winw; right = winw; } - if (bottom < winh) + if (bottom < winh) { ok = SDL_TRUE; + } /* Top */ if (!ok) { @@ -1519,8 +1565,9 @@ IME_PositionCandidateList(SDL_VideoData *videodata, SIZE size) left -= right - winw; right = winw; } - if (top >= 0) + if (top >= 0) { ok = SDL_TRUE; + } } /* Right */ @@ -1529,8 +1576,9 @@ IME_PositionCandidateList(SDL_VideoData *videodata, SIZE size) top = 0; right = left + size.cx; bottom = size.cy; - if (right < winw) + if (right < winw) { ok = SDL_TRUE; + } } /* Left */ @@ -1539,8 +1587,9 @@ IME_PositionCandidateList(SDL_VideoData *videodata, SIZE size) top = 0; right = videodata->ime_rect.x; bottom = size.cy; - if (right >= 0) + if (right >= 0) { ok = SDL_TRUE; + } } /* Window too small, show at (0,0) */ @@ -1624,8 +1673,7 @@ IME_RenderCandidateList(SDL_VideoData *videodata, HDC hdc) (candcount * candpadding * 2) + (candcount * maxcandsize.cy) ; - } - else { + } else { size.cx = (listborder * 2) + (listpadding * 2) + @@ -1634,8 +1682,9 @@ IME_RenderCandidateList(SDL_VideoData *videodata, HDC hdc) (candcount * candpadding * 2) + ((candcount - 1) * horzcandspacing); - for (i = 0; i < candcount; ++i) + for (i = 0; i < candcount; ++i) { size.cx += candsizes[i].cx; + } size.cy = (listborder * 2) + @@ -1667,12 +1716,12 @@ IME_RenderCandidateList(SDL_VideoData *videodata, HDC hdc) top = listborder + listpadding + (i * candborder * 2) + (i * candpadding * 2) + ((i + 1) * candmargin) + (i * maxcandsize.cy); right = size.cx - listborder - listpadding - candmargin; bottom = top + maxcandsize.cy + (candpadding * 2) + (candborder * 2); - } - else { + } else { left = listborder + listpadding + (i * candborder * 2) + (i * candpadding * 2) + ((i + 1) * candmargin) + (i * horzcandspacing); - for (j = 0; j < i; ++j) + for (j = 0; j < i; ++j) { left += candsizes[j].cx; + } top = listborder + listpadding + candmargin; right = left + candsizes[i].cx + (candpadding * 2) + (candborder * 2); @@ -1683,8 +1732,7 @@ IME_RenderCandidateList(SDL_VideoData *videodata, HDC hdc) SelectObject(hdc, selpen); SelectObject(hdc, selbrush); SetTextColor(hdc, seltextcolor); - } - else { + } else { SelectObject(hdc, candpen); SelectObject(hdc, candbrush); SetTextColor(hdc, candtextcolor); @@ -1711,8 +1759,9 @@ IME_Render(SDL_VideoData *videodata) { HDC hdc = CreateCompatibleDC(NULL); - if (videodata->ime_candlist) + if (videodata->ime_candlist) { IME_RenderCandidateList(videodata, hdc); + } DeleteDC(hdc); @@ -1721,8 +1770,9 @@ IME_Render(SDL_VideoData *videodata) void IME_Present(SDL_VideoData *videodata) { - if (videodata->ime_dirty) + if (videodata->ime_dirty) { IME_Render(videodata); + } /* FIXME: Need to show the IME bitmap */ } diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 25d40a19a5..bfbf3c3bba 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -345,7 +345,7 @@ static SDL_bool ExpandDialogSpace(WIN_DialogData *dialog, size_t space) if (size > dialog->size) { void *data = SDL_realloc(dialog->data, size); - if (!data) { + if (data == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } @@ -388,12 +388,12 @@ static SDL_bool AddDialogString(WIN_DialogData *dialog, const char *string) size_t count; SDL_bool status; - if (!string) { + if (string == NULL) { string = ""; } wstring = WIN_UTF8ToStringW(string); - if (!wstring) { + if (wstring == NULL) { return SDL_FALSE; } @@ -523,7 +523,7 @@ static WIN_DialogData *CreateDialogData(int w, int h, const char *caption) Vec2ToDLU(&dialogTemplate.cx, &dialogTemplate.cy); dialog = (WIN_DialogData *)SDL_calloc(1, sizeof(*dialog)); - if (!dialog) { + if (dialog == NULL) { return NULL; } @@ -566,8 +566,10 @@ static WIN_DialogData *CreateDialogData(int w, int h, const char *caption) { HDC ScreenDC = GetDC(NULL); int LogicalPixelsY = GetDeviceCaps(ScreenDC, LOGPIXELSY); - if (!LogicalPixelsY) /* This can happen if the application runs out of GDI handles */ - LogicalPixelsY = 72; + if (!LogicalPixelsY) { + LogicalPixelsY = 72; /* This can happen if the application runs out of GDI handles */ + } + WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / LogicalPixelsY); ReleaseDC(NULL, ScreenDC); } @@ -805,8 +807,9 @@ WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) } /* Ensure the size is wide enough for all of the buttons. */ - if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin) + if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin) { Size.cx = messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin; + } /* Reset the height to the icon size if it is actually bigger than the text. */ if (icon && Size.cy < IconMargin * 2 + IconHeight) { @@ -817,7 +820,7 @@ WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) Size.cy += ButtonHeight + TextMargin; dialog = CreateDialogData(Size.cx, Size.cy, messageboxdata->title); - if (!dialog) { + if (dialog == NULL) { return -1; } @@ -977,8 +980,7 @@ WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) pButtons = SDL_malloc(sizeof (TASKDIALOG_BUTTON) * messageboxdata->numbuttons); TaskConfig.nDefaultButton = 0; nCancelButton = 0; - for (i = 0; i < messageboxdata->numbuttons; i++) - { + for (i = 0; i < messageboxdata->numbuttons; i++) { const char *buttontext; if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT) { pButton = &pButtons[i]; diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index 2e44140147..78af47917e 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -174,7 +174,7 @@ WIN_GetDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode * mod } data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data)); - if (!data) { + if (data == NULL) { return SDL_FALSE; } @@ -217,7 +217,7 @@ WIN_GetDisplayNameVista(const WCHAR *deviceName) LONG rc; dll = SDL_LoadObject("USER32.DLL"); - if (!dll) { + if (dll == NULL) { return NULL; } @@ -225,7 +225,7 @@ WIN_GetDisplayNameVista(const WCHAR *deviceName) pQueryDisplayConfig = (SDL_WIN32PROC_QueryDisplayConfig) SDL_LoadFunction(dll, "QueryDisplayConfig"); pDisplayConfigGetDeviceInfo = (SDL_WIN32PROC_DisplayConfigGetDeviceInfo) SDL_LoadFunction(dll, "DisplayConfigGetDeviceInfo"); - if (!pGetDisplayConfigBufferSizes || !pQueryDisplayConfig || !pDisplayConfigGetDeviceInfo) { + if (pGetDisplayConfigBufferSizes == NULL || pQueryDisplayConfig == NULL || pDisplayConfigGetDeviceInfo == NULL) { goto WIN_GetDisplayNameVista_failed; } @@ -316,7 +316,7 @@ WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool se // Prevent adding duplicate displays. Do this after we know the display is // ready to be added to allow any displays that we can't fully query to be // removed - for(i = 0; i < _this->num_displays; ++i) { + for (i = 0; i < _this->num_displays; ++i) { SDL_DisplayData *driverdata = (SDL_DisplayData *)_this->displays[i].driverdata; if (SDL_wcscmp(driverdata->DeviceName, info->szDevice) == 0) { driverdata->MonitorHandle = hMonitor; @@ -333,7 +333,7 @@ WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool se } displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata)); - if (!displaydata) { + if (displaydata == NULL) { return SDL_FALSE; } SDL_memcpy(displaydata->DeviceName, info->szDevice, sizeof(displaydata->DeviceName)); @@ -583,7 +583,7 @@ void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut) *dpiOut = 96; } - if (!videodevice || !videodevice->driverdata) { + if (videodevice == NULL || !videodevice->driverdata) { return; } @@ -637,7 +637,7 @@ void WIN_ScreenPointToSDL(int *x, int *y) float ddpi, hdpi, vdpi; int x_pixels, y_pixels; - if (!videodevice || !videodevice->driverdata) { + if (videodevice == NULL || !videodevice->driverdata) { return; } diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index 2ef0f14520..31d8f608e7 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -235,7 +235,7 @@ WIN_FreeCursor(SDL_Cursor * cursor) static int WIN_ShowCursor(SDL_Cursor * cursor) { - if (!cursor) { + if (cursor == NULL) { cursor = SDL_blank_cursor; } if (cursor) { diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index ba92474187..a53260334c 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -187,7 +187,7 @@ WIN_GL_GetProcAddress(_THIS, const char *proc) /* This is to pick up extensions */ func = _this->gl_data->wglGetProcAddress(proc); - if (!func) { + if (func == NULL) { /* This is probably a normal GL function */ func = GetProcAddress(_this->gl_config.dll_handle, proc); } @@ -350,11 +350,13 @@ HasExtension(const char *extension, const char *extensions) /* Extension names should not have spaces. */ where = SDL_strchr(extension, ' '); - if (where || *extension == '\0') + if (where || *extension == '\0') { return SDL_FALSE; + } - if (!extensions) + if (extensions == NULL) { return SDL_FALSE; + } /* It takes a bit of care to be fool-proof about parsing the * OpenGL extensions string. Don't be fooled by sub-strings, @@ -364,13 +366,16 @@ HasExtension(const char *extension, const char *extensions) for (;;) { where = SDL_strstr(start, extension); - if (!where) + if (where == NULL) { break; + } terminator = where + SDL_strlen(extension); - if (where == start || *(where - 1) == ' ') - if (*terminator == ' ' || *terminator == '\0') + if (where == start || *(where - 1) == ' ') { + if (*terminator == ' ' || *terminator == '\0') { return SDL_TRUE; + } + } start = terminator; } @@ -661,11 +666,7 @@ WIN_GL_UseEGL(_THIS) SDL_assert(_this->gl_data != NULL); SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES); - return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE) - || _this->gl_config.major_version == 1 /* No WGL extension for OpenGL ES 1.x profiles. */ - || _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major - || (_this->gl_config.major_version == _this->gl_data->es_profile_max_supported_version.major - && _this->gl_config.minor_version > _this->gl_data->es_profile_max_supported_version.minor)); + return SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE) || _this->gl_config.major_version == 1 || _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major || (_this->gl_config.major_version == _this->gl_data->es_profile_max_supported_version.major && _this->gl_config.minor_version > _this->gl_data->es_profile_max_supported_version.minor); /* No WGL extension for OpenGL ES 1.x profiles. */ } SDL_GLContext @@ -711,7 +712,7 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window) _this->gl_config.flags == 0) { /* Create legacy context */ context = _this->gl_data->wglCreateContext(hdc); - if( share_context != 0 ) { + if ( share_context != 0 ) { _this->gl_data->wglShareLists(share_context, context); } } else { @@ -809,15 +810,15 @@ WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) } /* sanity check that higher level handled this. */ - SDL_assert(window || (!window && !context)); + SDL_assert(window || (window == NULL && !context)); /* Some Windows drivers freak out if hdc is NULL, even when context is NULL, against spec. Since hdc is _supposed_ to be ignored if context is NULL, we either use the current GL window, or do nothing if we already have no current context. */ - if (!window) { + if (window == NULL) { window = SDL_GL_GetCurrentWindow(); - if (!window) { + if (window == NULL) { SDL_assert(SDL_GL_GetCurrentContext() == NULL); return 0; /* already done. */ } diff --git a/src/video/windows/SDL_windowsshape.c b/src/video/windows/SDL_windowsshape.c index 484566dd30..64af5a691a 100644 --- a/src/video/windows/SDL_windowsshape.c +++ b/src/video/windows/SDL_windowsshape.c @@ -29,7 +29,7 @@ SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window) { int resized_properly; SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper)); - if (!result) { + if (result == NULL) { SDL_OutOfMemory(); return NULL; } @@ -60,14 +60,13 @@ Win32_CreateShaper(SDL_Window * window) { static void CombineRectRegions(SDL_ShapeTree* node,void* closure) { HRGN mask_region = *((HRGN*)closure),temp_region = NULL; - if(node->kind == OpaqueShape) { + if (node->kind == OpaqueShape) { /* Win32 API regions exclude their outline, so we widen the region by one pixel in each direction to include the real outline. */ temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.x + node->data.shape.w + 1,node->data.shape.y + node->data.shape.h + 1); - if(mask_region != NULL) { + if (mask_region != NULL) { CombineRgn(mask_region,mask_region,temp_region,RGN_OR); DeleteObject(temp_region); - } - else + } else *((HRGN*)closure) = temp_region; } } @@ -77,7 +76,7 @@ Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape SDL_ShapeData *data; HRGN mask_region = NULL; - if( (shaper == NULL) || + if ( (shaper == NULL) || (shape == NULL) || ((shape->format->Amask == 0) && (shape_mode->mode != ShapeModeColorKey)) || (shape->w != shaper->window->w) || @@ -86,8 +85,9 @@ Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape } data = (SDL_ShapeData*)shaper->driverdata; - if(data->mask_tree != NULL) + if (data->mask_tree != NULL) { SDL_FreeShapeTree(&data->mask_tree); + } data->mask_tree = SDL_CalculateShapeTree(*shape_mode,shape); SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region); @@ -102,15 +102,18 @@ int Win32_ResizeWindowShape(SDL_Window *window) { SDL_ShapeData* data; - if (window == NULL) + if (window == NULL) { return -1; + } data = (SDL_ShapeData *)window->shaper->driverdata; - if (data == NULL) + if (data == NULL) { return -1; + } - if(data->mask_tree != NULL) + if (data->mask_tree != NULL) { SDL_FreeShapeTree(&data->mask_tree); - if(window->shaper->hasshape == SDL_TRUE) { + } + if (window->shaper->hasshape == SDL_TRUE) { window->shaper->userx = window->x; window->shaper->usery = window->y; SDL_SetWindowPosition(window,-1000,-1000); diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 08f36b5485..f72ee9d998 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -554,7 +554,7 @@ SDL_Direct3D9GetAdapterIndex(int displayIndex) SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex); int adapterIndex = D3DADAPTER_DEFAULT; - if (!pData) { + if (pData == NULL) { SDL_SetError("Invalid display index"); adapterIndex = -1; /* make sure we return something invalid */ } else { @@ -622,8 +622,12 @@ SDL_bool SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex) { #if !HAVE_DXGI_H - if (adapterIndex) *adapterIndex = -1; - if (outputIndex) *outputIndex = -1; + if (adapterIndex) { + *adapterIndex = -1; + } + if (outputIndex) { + *outputIndex = -1; + } SDL_SetError("SDL was compiled without DXGI support due to missing dxgi.h header"); return SDL_FALSE; #else @@ -635,12 +639,12 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex) IDXGIAdapter *pDXGIAdapter; IDXGIOutput* pDXGIOutput; - if (!adapterIndex) { + if (adapterIndex == NULL) { SDL_InvalidParamError("adapterIndex"); return SDL_FALSE; } - if (!outputIndex) { + if (outputIndex == NULL) { SDL_InvalidParamError("outputIndex"); return SDL_FALSE; } @@ -648,7 +652,7 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex) *adapterIndex = -1; *outputIndex = -1; - if (!pData) { + if (pData == NULL) { SDL_SetError("Invalid display index"); return SDL_FALSE; } diff --git a/src/video/windows/SDL_windowsvulkan.c b/src/video/windows/SDL_windowsvulkan.c index d6ea578245..a0f4d18b76 100644 --- a/src/video/windows/SDL_windowsvulkan.c +++ b/src/video/windows/SDL_windowsvulkan.c @@ -44,51 +44,56 @@ int WIN_Vulkan_LoadLibrary(_THIS, const char *path) SDL_bool hasSurfaceExtension = SDL_FALSE; SDL_bool hasWin32SurfaceExtension = SDL_FALSE; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; - if(_this->vulkan_config.loader_handle) + if (_this->vulkan_config.loader_handle) { return SDL_SetError("Vulkan already loaded"); + } /* Load the Vulkan loader library */ - if(!path) + if (path == NULL) { path = SDL_getenv("SDL_VULKAN_LIBRARY"); - if(!path) + } + if (path == NULL) { path = "vulkan-1.dll"; + } _this->vulkan_config.loader_handle = SDL_LoadObject(path); - if(!_this->vulkan_config.loader_handle) + if (!_this->vulkan_config.loader_handle) { return -1; + } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); - if(!vkGetInstanceProcAddr) + if (!vkGetInstanceProcAddr) { goto fail; + } _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr; _this->vulkan_config.vkEnumerateInstanceExtensionProperties = (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)( VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties"); - if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) + if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) { goto fail; + } extensions = SDL_Vulkan_CreateInstanceExtensionsList( (PFN_vkEnumerateInstanceExtensionProperties) _this->vulkan_config.vkEnumerateInstanceExtensionProperties, &extensionCount); - if(!extensions) + if (extensions == NULL) { goto fail; - for(i = 0; i < extensionCount; i++) + } + for (i = 0; i < extensionCount; i++) { - if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasSurfaceExtension = SDL_TRUE; - else if(SDL_strcmp(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + } else if (SDL_strcmp(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasWin32SurfaceExtension = SDL_TRUE; + } } SDL_free(extensions); - if(!hasSurfaceExtension) - { + if (!hasSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension"); goto fail; - } - else if(!hasWin32SurfaceExtension) - { + } else if (!hasWin32SurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_WIN32_SURFACE_EXTENSION_NAME "extension"); goto fail; @@ -103,8 +108,7 @@ fail: void WIN_Vulkan_UnloadLibrary(_THIS) { - if(_this->vulkan_config.loader_handle) - { + if (_this->vulkan_config.loader_handle) { SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; } @@ -118,8 +122,7 @@ SDL_bool WIN_Vulkan_GetInstanceExtensions(_THIS, static const char *const extensionsForWin32[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME }; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } @@ -143,14 +146,12 @@ SDL_bool WIN_Vulkan_CreateSurface(_THIS, VkWin32SurfaceCreateInfoKHR createInfo; VkResult result; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } - if(!vkCreateWin32SurfaceKHR) - { + if (!vkCreateWin32SurfaceKHR) { SDL_SetError(VK_KHR_WIN32_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); return SDL_FALSE; @@ -162,8 +163,7 @@ SDL_bool WIN_Vulkan_CreateSurface(_THIS, createInfo.hwnd = windowData->hwnd; result = vkCreateWin32SurfaceKHR(instance, &createInfo, NULL, surface); - if(result != VK_SUCCESS) - { + if (result != VK_SUCCESS) { SDL_SetError("vkCreateWin32SurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); return SDL_FALSE; diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 1a01a3468e..fa9280b719 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -302,7 +302,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre /* Allocate the window data */ data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); - if (!data) { + if (data == NULL) { return SDL_OutOfMemory(); } data->window = window; @@ -839,8 +839,7 @@ WIN_RaiseWindow(_THIS, SDL_Window * window) DWORD dwCurID = 0u; HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; - if(bForce) - { + if (bForce) { hCurWnd = GetForegroundWindow(); dwMyID = GetCurrentThreadId(); dwCurID = GetWindowThreadProcessId(hCurWnd, NULL); @@ -850,8 +849,7 @@ WIN_RaiseWindow(_THIS, SDL_Window * window) SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); } SetForegroundWindow(hwnd); - if (bForce) - { + if (bForce) { AttachThreadInput(dwCurID, dwMyID, FALSE); SetFocus(hwnd); SetActiveWindow(hwnd); @@ -1058,7 +1056,7 @@ WIN_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size) filename_utf8 = WIN_StringToUTF8(data->ICMFileName); if (filename_utf8) { iccProfileData = SDL_LoadFile(filename_utf8, size); - if (!iccProfileData) { + if (iccProfileData == NULL) { SDL_SetError("Could not open ICC profile"); } SDL_free(filename_utf8); @@ -1240,7 +1238,7 @@ void WIN_OnWindowEnter(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; - if (!data || !data->hwnd) { + if (data == NULL || !data->hwnd) { /* The window wasn't fully initialized */ return; } @@ -1398,8 +1396,9 @@ WIN_ClientPointToSDL(const SDL_Window *window, int *x, int *y) const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata); const SDL_VideoData *videodata = data->videodata; - if (!videodata->dpi_scaling_enabled) + if (!videodata->dpi_scaling_enabled) { return; + } *x = MulDiv(*x, 96, data->scaling_dpi); *y = MulDiv(*y, 96, data->scaling_dpi); @@ -1416,8 +1415,9 @@ WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y) const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata); const SDL_VideoData *videodata = data->videodata; - if (!videodata->dpi_scaling_enabled) + if (!videodata->dpi_scaling_enabled) { return; + } *x = MulDiv(*x, data->scaling_dpi, 96); *y = MulDiv(*y, data->scaling_dpi, 96); diff --git a/src/video/winrt/SDL_winrtgamebar.cpp b/src/video/winrt/SDL_winrtgamebar.cpp index e7005a4160..d3c0d7c5e7 100644 --- a/src/video/winrt/SDL_winrtgamebar.cpp +++ b/src/video/winrt/SDL_winrtgamebar.cpp @@ -120,7 +120,7 @@ WINRT_HandleGameBarIsInputRedirected_MainThread() return; } gameBar = WINRT_GetGameBar(); - if (!gameBar) { + if (gameBar == NULL) { /* Shouldn't happen, but just in case... */ return; } @@ -174,11 +174,11 @@ WINRT_QuitGameBar(_THIS) { SDL_VideoData *driverdata; IGameBarStatics_ *gameBar; - if (!_this || !_this->driverdata) { + if (_this == NULL || _this->driverdata == NULL) { return; } gameBar = WINRT_GetGameBar(); - if (!gameBar) { + if (gameBar == NULL) { return; } driverdata = (SDL_VideoData *)_this->driverdata; diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index e3ef11a0a3..8823101f1d 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -121,16 +121,16 @@ WINRT_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); - return (0); + return 0; } data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - if (!data) { + if (data == NULL) { SDL_OutOfMemory(); SDL_free(device); - return (0); + return 0; } device->driverdata = data; @@ -348,7 +348,7 @@ WINRT_AddDisplaysForOutput (_THIS, IDXGIAdapter1 * dxgiAdapter1, int outputIndex } dxgiModes = (DXGI_MODE_DESC *)SDL_calloc(numModes, sizeof(DXGI_MODE_DESC)); - if ( ! dxgiModes) { + if (dxgiModes == NULL) { SDL_OutOfMemory(); goto done; } @@ -610,7 +610,7 @@ WINRT_IsCoreWindowActive(CoreWindow ^ coreWindow) if (coreWindow->CustomProperties->HasKey("SDLHelperWindowActivationState")) { CoreWindowActivationState activationState = \ safe_cast(coreWindow->CustomProperties->Lookup("SDLHelperWindowActivationState")); - return (activationState != CoreWindowActivationState::Deactivated); + return activationState != CoreWindowActivationState::Deactivated; } /* Assume that non-SDL tracked windows are active, although this should diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c index d58e73e552..b1fe34b9c5 100644 --- a/src/video/x11/SDL_x11clipboard.c +++ b/src/video/x11/SDL_x11clipboard.c @@ -215,7 +215,7 @@ GetSlectionText(_THIS, Atom selection_type) X11_XFree(src); } - if (!text) { + if (text == NULL) { text = SDL_strdup(""); } diff --git a/src/video/x11/SDL_x11dyn.c b/src/video/x11/SDL_x11dyn.c index c20dc68541..3f466740db 100644 --- a/src/video/x11/SDL_x11dyn.c +++ b/src/video/x11/SDL_x11dyn.c @@ -77,8 +77,9 @@ X11_GetSym(const char *fnname, int *pHasModule) for (i = 0; i < SDL_TABLESIZE(x11libs); i++) { if (x11libs[i].lib != NULL) { fn = SDL_LoadFunction(x11libs[i].lib, fnname); - if (fn != NULL) + if (fn != NULL) { break; + } } } @@ -89,8 +90,9 @@ X11_GetSym(const char *fnname, int *pHasModule) printf("X11: Symbol '%s' NOT FOUND!\n", fnname); #endif - if (fn == NULL) - *pHasModule = 0; /* kill this module. */ + if (fn == NULL) { + *pHasModule = 0; /* kill this module. */ + } return fn; } diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 2b92198ad7..54464c5eff 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -100,7 +100,9 @@ static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop) int bytes_fetch = 0; do { - if (ret != NULL) X11_XFree(ret); + if (ret != NULL) { + X11_XFree(ret); + } X11_XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret); bytes_fetch += bytes_left; } while (bytes_left != 0); @@ -134,9 +136,15 @@ static Atom X11_PickTargetFromAtoms(Display *disp, Atom a0, Atom a1, Atom a2) { int count=0; Atom atom[3]; - if (a0 != None) atom[count++] = a0; - if (a1 != None) atom[count++] = a1; - if (a2 != None) atom[count++] = a2; + if (a0 != None) { + atom[count++] = a0; + } + if (a1 != None) { + atom[count++] = a1; + } + if (a2 != None) { + atom[count++] = a2; + } return X11_PickTarget(disp, atom, count); } @@ -150,10 +158,9 @@ static Bool X11_KeyRepeatCheckIfEvent(Display *display, XEvent *chkev, XPointer arg) { struct KeyRepeatCheckData *d = (struct KeyRepeatCheckData *) arg; - if (chkev->type == KeyPress && - chkev->xkey.keycode == d->event->xkey.keycode && - chkev->xkey.time - d->event->xkey.time < 2) + if (chkev->type == KeyPress && chkev->xkey.keycode == d->event->xkey.keycode && chkev->xkey.time - d->event->xkey.time < 2) { d->found = SDL_TRUE; + } return False; } @@ -166,9 +173,9 @@ static SDL_bool X11_KeyRepeat(Display *display, XEvent *event) struct KeyRepeatCheckData d; d.event = event; d.found = SDL_FALSE; - if (X11_XPending(display)) - X11_XCheckIfEvent(display, &dummyev, X11_KeyRepeatCheckIfEvent, - (XPointer) &d); + if (X11_XPending(display)) { + X11_XCheckIfEvent(display, &dummyev, X11_KeyRepeatCheckIfEvent, (XPointer)&d); + } return d.found; } @@ -270,8 +277,11 @@ static char* X11_URIToLocal(char* uri) { char *file = NULL; SDL_bool local; - if (SDL_memcmp(uri,"file:/",6) == 0) uri += 6; /* local file? */ - else if (SDL_strstr(uri,":/") != NULL) return file; /* wrong scheme */ + if (SDL_memcmp(uri,"file:/",6) == 0) { + uri += 6; /* local file? */ + } else if (SDL_strstr(uri, ":/") != NULL) { + return file; /* wrong scheme */ + } local = uri[0] != '/' || (uri[0] != '\0' && uri[1] == '/'); @@ -340,8 +350,8 @@ X11_GetNumLockModifierMask(_THIS) xmods = X11_XGetModifierMapping(display); n = xmods->max_keypermod; - for(i = 3; i < 8; i++) { - for(j = 0; j < n; j++) { + for (i = 3; i < 8; i++) { + for (j = 0; j < n; j++) { KeyCode kc = xmods->modifiermap[i * n + j]; if (viddata->key_layout[kc] == SDL_SCANCODE_NUMLOCKCLEAR) { num_mask = 1 << i; @@ -366,8 +376,8 @@ X11_GetScrollLockModifierMask(_THIS) xmods = X11_XGetModifierMapping(display); n = xmods->max_keypermod; - for(i = 3; i < 8; i++) { - for(j = 0; j < n; j++) { + for (i = 3; i < 8; i++) { + for (j = 0; j < n; j++) { KeyCode kc = xmods->modifiermap[i * n + j]; if (viddata->key_layout[kc] == SDL_SCANCODE_SCROLLLOCK) { num_mask = 1 << i; @@ -527,8 +537,9 @@ InitiateWindowResize(_THIS, const SDL_WindowData *data, const SDL_Point *point, Display *display = viddata->display; XEvent evt; - if (direction < _NET_WM_MOVERESIZE_SIZE_TOPLEFT || direction > _NET_WM_MOVERESIZE_SIZE_LEFT) + if (direction < _NET_WM_MOVERESIZE_SIZE_TOPLEFT || direction > _NET_WM_MOVERESIZE_SIZE_LEFT) { return; + } /* !!! FIXME: we need to regrab this if necessary when the drag is done. */ X11_XUngrabPointer(display, 0L); @@ -644,8 +655,9 @@ X11_HandleClipboardEvent(_THIS, const XEvent *xevent) if (req->target == XA_TARGETS) { supportedFormats[0] = XA_TARGETS; mime_formats = 1; - for (i = 0; i < SDL_X11_CLIPBOARD_MIME_TYPE_MAX; ++i) + for (i = 0; i < SDL_X11_CLIPBOARD_MIME_TYPE_MAX; ++i) { supportedFormats[mime_formats++] = X11_GetSDLCutBufferClipboardExternalFormat(display, i); + } X11_XChangeProperty(display, req->requestor, req->property, XA_ATOM, 32, PropModeReplace, (unsigned char*)supportedFormats, @@ -654,8 +666,9 @@ X11_HandleClipboardEvent(_THIS, const XEvent *xevent) sevent.xselection.target = XA_TARGETS; } else { for (i = 0; i < SDL_X11_CLIPBOARD_MIME_TYPE_MAX; ++i) { - if (X11_GetSDLCutBufferClipboardExternalFormat(display, i) != req->target) + if (X11_GetSDLCutBufferClipboardExternalFormat(display, i) != req->target) { continue; + } if (X11_XGetWindowProperty(display, DefaultRootWindow(display), X11_GetSDLCutBufferClipboardType(display, i, req->selection), 0, INT_MAX/4, False, X11_GetSDLCutBufferClipboardInternalFormat(display, i), &sevent.xselection.target, &seln_format, &nbytes, @@ -796,7 +809,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent) } #if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS - if(xevent->type == GenericEvent) { + if (xevent->type == GenericEvent) { X11_HandleGenericEvent(videodata, xevent); return; } @@ -839,7 +852,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent) } } } - if (!data) { + if (data == NULL) { /* The window for KeymapNotify, etc events is 0 */ if (xevent->type == KeymapNotify) { #ifdef DEBUG_XEVENTS @@ -884,7 +897,9 @@ X11_DispatchEvent(_THIS, XEvent *xevent) } } - if (name_of_atom) X11_XFree(name_of_atom); + if (name_of_atom) { + X11_XFree(name_of_atom); + } } return; } @@ -899,10 +914,12 @@ X11_DispatchEvent(_THIS, XEvent *xevent) xevent->xcrossing.x, xevent->xcrossing.y, xevent->xcrossing.mode); - if (xevent->xcrossing.mode == NotifyGrab) + if (xevent->xcrossing.mode == NotifyGrab) { printf("Mode: NotifyGrab\n"); - if (xevent->xcrossing.mode == NotifyUngrab) + } + if (xevent->xcrossing.mode == NotifyUngrab) { printf("Mode: NotifyUngrab\n"); + } #endif SDL_SetMouseFocus(data->window); @@ -934,10 +951,12 @@ X11_DispatchEvent(_THIS, XEvent *xevent) xevent->xcrossing.x, xevent->xcrossing.y, xevent->xcrossing.mode); - if (xevent->xcrossing.mode == NotifyGrab) + if (xevent->xcrossing.mode == NotifyGrab) { printf("Mode: NotifyGrab\n"); - if (xevent->xcrossing.mode == NotifyUngrab) + } + if (xevent->xcrossing.mode == NotifyUngrab) { printf("Mode: NotifyUngrab\n"); + } #endif if (!SDL_GetMouse()->relative_mode) { SDL_SendMouseMotion(data->window, 0, 0, xevent->xcrossing.x, xevent->xcrossing.y); @@ -977,14 +996,11 @@ X11_DispatchEvent(_THIS, XEvent *xevent) #ifdef DEBUG_XEVENTS printf("window %p: FocusIn!\n", data); #endif - if (!videodata->last_mode_change_deadline) /* no recent mode changes */ - { + if (!videodata->last_mode_change_deadline) /* no recent mode changes */ { data->pending_focus = PENDING_FOCUS_NONE; data->pending_focus_time = 0; X11_DispatchFocusIn(_this, data); - } - else - { + } else { data->pending_focus = PENDING_FOCUS_IN; data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_TIME; } @@ -1013,14 +1029,11 @@ X11_DispatchEvent(_THIS, XEvent *xevent) #ifdef DEBUG_XEVENTS printf("window %p: FocusOut!\n", data); #endif - if (!videodata->last_mode_change_deadline) /* no recent mode changes */ - { + if (!videodata->last_mode_change_deadline) /* no recent mode changes */ { data->pending_focus = PENDING_FOCUS_NONE; data->pending_focus_time = 0; X11_DispatchFocusOut(_this, data); - } - else - { + } else { data->pending_focus = PENDING_FOCUS_OUT; data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_TIME; } @@ -1070,7 +1083,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent) #endif #ifdef SDL_USE_IME - if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){ + if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode, (xevent->type == KeyPress ? SDL_PRESSED : SDL_RELEASED)); } #endif @@ -1163,7 +1176,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent) SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, xevent->xconfigure.x, xevent->xconfigure.y); #ifdef SDL_USE_IME - if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){ + if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { /* Update IME candidate list position */ SDL_IME_UpdateTextRect(NULL); } @@ -1206,12 +1219,11 @@ X11_DispatchEvent(_THIS, XEvent *xevent) /* pick from list of three */ data->xdnd_req = X11_PickTargetFromAtoms(display, xevent->xclient.data.l[2], xevent->xclient.data.l[3], xevent->xclient.data.l[4]); } - } - else if (xevent->xclient.message_type == videodata->XdndPosition) { + } else if (xevent->xclient.message_type == videodata->XdndPosition) { #ifdef DEBUG_XEVENTS Atom act= videodata->XdndActionCopy; - if(xdnd_version >= 2) { + if (xdnd_version >= 2) { act = xevent->xclient.data.l[4]; } printf("Action requested by user is : %s\n", X11_XGetAtomName(display , act)); @@ -1233,8 +1245,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent) X11_XSendEvent(display, xevent->xclient.data.l[0], False, NoEventMask, (XEvent*)&m); X11_XFlush(display); - } - else if(xevent->xclient.message_type == videodata->XdndDrop) { + } else if (xevent->xclient.message_type == videodata->XdndDrop) { if (data->xdnd_req == None) { /* say again - not interested! */ SDL_memset(&m, 0, sizeof(XClientMessageEvent)); @@ -1249,14 +1260,13 @@ X11_DispatchEvent(_THIS, XEvent *xevent) X11_XSendEvent(display, xevent->xclient.data.l[0], False, NoEventMask, (XEvent*)&m); } else { /* convert */ - if(xdnd_version >= 1) { + if (xdnd_version >= 1) { X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent->xclient.data.l[2]); } else { X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, CurrentTime); } } - } - else if ((xevent->xclient.message_type == videodata->WM_PROTOCOLS) && + } else if ((xevent->xclient.message_type == videodata->WM_PROTOCOLS) && (xevent->xclient.format == 32) && (xevent->xclient.data.l[0] == videodata->_NET_WM_PING)) { Window root = DefaultRootWindow(display); @@ -1278,8 +1288,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent) #endif SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0); break; - } - else if ((xevent->xclient.message_type == videodata->WM_PROTOCOLS) && + } else if ((xevent->xclient.message_type == videodata->WM_PROTOCOLS) && (xevent->xclient.format == 32) && (xevent->xclient.data.l[0] == videodata->WM_TAKE_FOCUS)) { @@ -1303,7 +1312,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent) case MotionNotify:{ SDL_Mouse *mouse = SDL_GetMouse(); - if(!mouse->relative_mode || mouse->relative_mode_warp) { + if (!mouse->relative_mode || mouse->relative_mode_warp) { #ifdef DEBUG_MOTION printf("window %p: X11 motion: %d,%d\n", data, xevent->xmotion.x, xevent->xmotion.y); #endif @@ -1323,13 +1332,12 @@ X11_DispatchEvent(_THIS, XEvent *xevent) } else { SDL_bool ignore_click = SDL_FALSE; int button = xevent->xbutton.button; - if(button == Button1) { + if (button == Button1) { if (ProcessHitTest(_this, data, xevent)) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0); break; /* don't pass this event on to app. */ } - } - else if(button > 7) { + } else if (button > 7) { /* X button values 4-7 are used for scrolling, so X1 is 8, X2 is 9, ... => subtract (8-SDL_BUTTON_X1) to get value SDL expects */ button -= (8-SDL_BUTTON_X1); @@ -1672,7 +1680,7 @@ X11_WaitEventTimeout(_THIS, int timeout) X11_DispatchEvent(_this, &xevent); #ifdef SDL_USE_IME - if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){ + if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { SDL_IME_PumpEvents(); } #endif @@ -1715,7 +1723,7 @@ X11_PumpEvents(_THIS) } #ifdef SDL_USE_IME - if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){ + if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { SDL_IME_PumpEvents(); } #endif diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c index 123ad8ffbe..b98d27e93d 100644 --- a/src/video/x11/SDL_x11framebuffer.c +++ b/src/video/x11/SDL_x11framebuffer.c @@ -35,9 +35,9 @@ static int shm_errhandler(Display *d, XErrorEvent *e) { if ( e->error_code == BadAccess ) { shm_error = True; - return(0); + return 0; } else - return(X_handler(d,e)); + return X_handler(d, e); } static SDL_bool have_mitshm(Display *dpy) @@ -95,8 +95,9 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, X11_XShmAttach(display, shminfo); X11_XSync(display, False); X11_XSetErrorHandler(X_handler); - if ( shm_error ) + if (shm_error) { shmdt(shminfo->shmaddr); + } } else { shm_error = True; } @@ -160,26 +161,25 @@ X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, /* Clipped? */ continue; } - if (x < 0) - { + if (x < 0) { x += w; w += rects[i].x; } - if (y < 0) - { + if (y < 0) { y += h; h += rects[i].y; } - if (x + w > window->w) + if (x + w > window->w) { w = window->w - x; - if (y + h > window->h) + } + if (y + h > window->h) { h = window->h - y; + } X11_XShmPutImage(display, data->xwindow, data->gc, data->ximage, x, y, x, y, w, h, False); } - } - else + } else #endif /* !NO_SHARED_MEMORY */ { for (i = 0; i < numrects; ++i) { @@ -192,20 +192,20 @@ X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, /* Clipped? */ continue; } - if (x < 0) - { + if (x < 0) { x += w; w += rects[i].x; } - if (y < 0) - { + if (y < 0) { y += h; h += rects[i].y; } - if (x + w > window->w) + if (x + w > window->w) { w = window->w - x; - if (y + h > window->h) + } + if (y + h > window->h) { h = window->h - y; + } X11_XPutImage(display, data->xwindow, data->gc, data->ximage, x, y, x, y, w, h); @@ -223,7 +223,7 @@ X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window) SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display; - if (!data) { + if (data == NULL) { /* The window wasn't fully initialized */ return; } diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c index fcaafeef11..710c7cbd8a 100644 --- a/src/video/x11/SDL_x11keyboard.c +++ b/src/video/x11/SDL_x11keyboard.c @@ -432,7 +432,7 @@ X11_StopTextInput(_THIS) void X11_SetTextInputRect(_THIS, const SDL_Rect *rect) { - if (!rect) { + if (rect == NULL) { SDL_InvalidParamError("rect"); return; } diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index 351b9726bd..d74a43e0bd 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -249,7 +249,7 @@ X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data ) const int linecount = CountLinesOfText(text); TextLineData *plinedata = (TextLineData *) SDL_malloc(sizeof (TextLineData) * linecount); - if (!plinedata) { + if (plinedata == NULL) { return SDL_OutOfMemory(); } @@ -277,8 +277,9 @@ X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data ) text += length + 1; /* Break if there are no more linefeeds. */ - if ( !lf ) + if (lf == NULL) { break; + } } /* Bump up the text height slightly. */ @@ -631,7 +632,7 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data ) data->button_press_index = -1; /* Reset what button is currently depressed. */ data->mouse_over_index = -1; /* Reset what button the mouse is over. */ - while( !close_dialog ) { + while ( !close_dialog ) { XEvent e; SDL_bool draw = SDL_TRUE; @@ -641,8 +642,9 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data ) /* If X11_XFilterEvent returns True, then some input method has filtered the event, and the client should discard the event. */ - if ( ( e.type != Expose ) && X11_XFilterEvent( &e, None ) ) + if ((e.type != Expose) && X11_XFilterEvent(&e, None)) { continue; + } switch( e.type ) { case Expose: @@ -692,13 +694,15 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data ) KeySym key = X11_XLookupKeysym( &e.xkey, 0 ); /* If this is a key release for something we didn't get the key down for, then bail. */ - if ( key != last_key_pressed ) + if (key != last_key_pressed) { break; + } - if ( key == XK_Escape ) + if ( key == XK_Escape ) { mask = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT; - else if ( ( key == XK_Return ) || ( key == XK_KP_Enter ) ) + } else if ((key == XK_Return) || (key == XK_KP_Enter)) { mask = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT; + } if ( mask ) { int i; @@ -762,8 +766,9 @@ X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_zero(data); - if ( !SDL_X11_LoadSymbols() ) + if (!SDL_X11_LoadSymbols()) { return -1; + } #if SDL_SET_LOCALE origlocale = setlocale(LC_ALL, NULL); diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index 6322319afa..8736eefb74 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -331,7 +331,7 @@ X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput outputid, XRRScre } output_info = X11_XRRGetOutputInfo(dpy, res, outputid); - if (!output_info || !output_info->crtc || output_info->connection == RR_Disconnected) { + if (output_info == NULL || !output_info->crtc || output_info->connection == RR_Disconnected) { X11_XRRFreeOutputInfo(output_info); return 0; /* ignore this one. */ } @@ -343,7 +343,7 @@ X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput outputid, XRRScre X11_XRRFreeOutputInfo(output_info); crtc = X11_XRRGetCrtcInfo(dpy, res, output_crtc); - if (!crtc) { + if (crtc == NULL) { return 0; /* oh well, ignore it. */ } @@ -359,12 +359,12 @@ X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput outputid, XRRScre X11_XRRFreeCrtcInfo(crtc); displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata)); - if (!displaydata) { + if (displaydata == NULL) { return SDL_OutOfMemory(); } modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData)); - if (!modedata) { + if (modedata == NULL) { SDL_free(displaydata); return SDL_OutOfMemory(); } @@ -434,7 +434,7 @@ X11_HandleXRandROutputChange(_THIS, const XRROutputChangeNotifyEvent *ev) XVisualInfo vinfo; if (get_visualinfo(dpy, screen, &vinfo) == 0) { XRRScreenResources *res = X11_XRRGetScreenResourcesCurrent(dpy, RootWindow(dpy, screen)); - if (!res || res->noutput == 0) { + if (res == NULL || res->noutput == 0) { if (res) { X11_XRRFreeScreenResources(res); } @@ -493,13 +493,13 @@ X11_InitModes_XRandR(_THIS) } res = X11_XRRGetScreenResourcesCurrent(dpy, RootWindow(dpy, screen)); - if (!res || res->noutput == 0) { + if (res == NULL || res->noutput == 0) { if (res) { X11_XRRFreeScreenResources(res); } res = X11_XRRGetScreenResources(dpy, RootWindow(dpy, screen)); - if (!res) { + if (res == NULL) { continue; } } @@ -538,7 +538,7 @@ GetXftDPI(Display* dpy) xdefault_resource = X11_XGetDefault(dpy, "Xft", "dpi"); - if(!xdefault_resource) { + if (xdefault_resource == NULL) { return 0; } @@ -591,12 +591,12 @@ static int X11_InitModes_StdXlib(_THIS) mode.refresh_rate = 0; /* don't know it, sorry. */ displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata)); - if (!displaydata) { + if (displaydata == NULL) { return SDL_OutOfMemory(); } modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData)); - if (!modedata) { + if (modedata == NULL) { SDL_free(displaydata); return SDL_OutOfMemory(); } @@ -613,7 +613,7 @@ static int X11_InitModes_StdXlib(_THIS) displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.w, mode.h, ((float) display_mm_width) / 25.4f,((float) display_mm_height) / 25.4f); xft_dpi = GetXftDPI(dpy); - if(xft_dpi > 0) { + if (xft_dpi > 0) { displaydata->hdpi = (float)xft_dpi; displaydata->vdpi = (float)xft_dpi; } @@ -698,7 +698,7 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display) if (output_info && output_info->connection != RR_Disconnected) { for (i = 0; i < output_info->nmode; ++i) { modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData)); - if (!modedata) { + if (modedata == NULL) { continue; } mode.driverdata = modedata; @@ -767,18 +767,18 @@ X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode Status status; res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen)); - if (!res) { + if (res == NULL) { return SDL_SetError("Couldn't get XRandR screen resources"); } output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output); - if (!output_info || output_info->connection == RR_Disconnected) { + if (output_info == NULL || output_info->connection == RR_Disconnected) { X11_XRRFreeScreenResources(res); return SDL_SetError("Couldn't get XRandR output info"); } crtc = X11_XRRGetCrtcInfo(display, res, output_info->crtc); - if (!crtc) { + if (crtc == NULL) { X11_XRRFreeOutputInfo(output_info); X11_XRRFreeScreenResources(res); return SDL_SetError("Couldn't get XRandR crtc info"); diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c index 96a25a2b9e..2e6dd07f7d 100644 --- a/src/video/x11/SDL_x11mouse.c +++ b/src/video/x11/SDL_x11mouse.c @@ -94,7 +94,7 @@ X11_CreateXCursorCursor(SDL_Surface * surface, int hot_x, int hot_y) XcursorImage *image; image = X11_XcursorImageCreate(surface->w, surface->h); - if (!image) { + if (image == NULL) { SDL_OutOfMemory(); return None; } @@ -128,13 +128,13 @@ X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y) unsigned int width_bytes = ((surface->w + 7) & ~7) / 8; data_bits = SDL_calloc(1, surface->h * width_bytes); - if (!data_bits) { + if (data_bits == NULL) { SDL_OutOfMemory(); return None; } mask_bits = SDL_calloc(1, surface->h * width_bytes); - if (!mask_bits) { + if (mask_bits == NULL) { SDL_free(data_bits); SDL_OutOfMemory(); return None; @@ -175,15 +175,13 @@ X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y) fg.red = rfg * 257 / fgBits; fg.green = gfg * 257 / fgBits; fg.blue = bfg * 257 / fgBits; - } - else fg.red = fg.green = fg.blue = 0; + } else fg.red = fg.green = fg.blue = 0; if (bgBits) { bg.red = rbg * 257 / bgBits; bg.green = gbg * 257 / bgBits; bg.blue = bbg * 257 / bgBits; - } - else bg.red = bg.green = bg.blue = 0; + } else bg.red = bg.green = bg.blue = 0; data_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display), (char*)data_bits, @@ -360,8 +358,9 @@ static int X11_SetRelativeMouseMode(SDL_bool enabled) { #if SDL_VIDEO_DRIVER_X11_XINPUT2 - if(X11_Xinput2IsInitialized()) + if (X11_Xinput2IsInitialized()) { return 0; + } #else SDL_Unsupported(); #endif diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 0336798b91..3073e2ca20 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -303,13 +303,15 @@ HasExtension(const char *extension, const char *extensions) const char *start; const char *where, *terminator; - if (!extensions) + if (!extensions) { return SDL_FALSE; + } /* Extension names should not have spaces. */ where = SDL_strchr(extension, ' '); - if (where || *extension == '\0') + if (where || *extension == '\0') { return SDL_FALSE; + } /* It takes a bit of care to be fool-proof about parsing the * OpenGL extensions string. Don't be fooled by sub-strings, @@ -319,13 +321,16 @@ HasExtension(const char *extension, const char *extensions) for (;;) { where = SDL_strstr(start, extension); - if (!where) + if (!where) { break; + } terminator = where + SDL_strlen(extension); - if (where == start || *(where - 1) == ' ') - if (*terminator == ' ' || *terminator == '\0') + if (where == start || *(where - 1) == ' ') { + if (*terminator == ' ' || *terminator == '\0') { return SDL_TRUE; + } + } start = terminator; } @@ -496,7 +501,7 @@ X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int si SDL_assert(size >= MAX_ATTRIBUTES); /* Setup our GLX attributes according to the gl_config. */ - if( for_FBConfig ) { + if ( for_FBConfig ) { attribs[i++] = GLX_RENDER_TYPE; if (_this->gl_config.floatbuffers) { attribs[i++] = GLX_RGBA_FLOAT_BIT_ARB; @@ -520,7 +525,7 @@ X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int si if (_this->gl_config.double_buffer) { attribs[i++] = GLX_DOUBLEBUFFER; - if( for_FBConfig ) { + if ( for_FBConfig ) { attribs[i++] = True; } } @@ -555,7 +560,7 @@ X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int si if (_this->gl_config.stereo) { attribs[i++] = GLX_STEREO; - if( for_FBConfig ) { + if ( for_FBConfig ) { attribs[i++] = True; } } @@ -665,18 +670,14 @@ X11_GL_ErrorHandler(Display * d, XErrorEvent * e) char x11_error_locale[256]; errorCode = e->error_code; - if (X11_XGetErrorText(d, errorCode, x11_error_locale, sizeof(x11_error_locale)) == Success) - { + if (X11_XGetErrorText(d, errorCode, x11_error_locale, sizeof(x11_error_locale)) == Success) { x11_error = SDL_iconv_string("UTF-8", "", x11_error_locale, SDL_strlen(x11_error_locale)+1); } - if (x11_error) - { + if (x11_error) { SDL_SetError("Could not %s: %s", errorHandlerOperation, x11_error); SDL_free(x11_error); - } - else - { + } else { SDL_SetError("Could not %s: %i (Base %i)", errorHandlerOperation, errorCode, errorBase); } @@ -747,19 +748,19 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) int iattr = 4; /* SDL profile bits match GLX profile bits */ - if( _this->gl_config.profile_mask != 0 ) { + if ( _this->gl_config.profile_mask != 0 ) { attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB; attribs[iattr++] = _this->gl_config.profile_mask; } /* SDL flags match GLX flags */ - if( _this->gl_config.flags != 0 ) { + if ( _this->gl_config.flags != 0 ) { attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB; attribs[iattr++] = _this->gl_config.flags; } /* only set if glx extension is available */ - if( _this->gl_data->HAS_GLX_ARB_context_flush_control ) { + if ( _this->gl_data->HAS_GLX_ARB_context_flush_control ) { attribs[iattr++] = GLX_CONTEXT_RELEASE_BEHAVIOR_ARB; attribs[iattr++] = _this->gl_config.release_behavior ? @@ -768,7 +769,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) } /* only set if glx extension is available */ - if( _this->gl_data->HAS_GLX_ARB_create_context_robustness ) { + if ( _this->gl_data->HAS_GLX_ARB_create_context_robustness ) { attribs[iattr++] = GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB; attribs[iattr++] = _this->gl_config.reset_notification ? @@ -777,7 +778,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) } /* only set if glx extension is available */ - if( _this->gl_data->HAS_GLX_ARB_create_context_no_error ) { + if ( _this->gl_data->HAS_GLX_ARB_create_context_no_error ) { attribs[iattr++] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB; attribs[iattr++] = _this->gl_config.no_error; } diff --git a/src/video/x11/SDL_x11shape.c b/src/video/x11/SDL_x11shape.c index 7d4e32c22e..fe288454ef 100644 --- a/src/video/x11/SDL_x11shape.c +++ b/src/video/x11/SDL_x11shape.c @@ -35,7 +35,7 @@ X11_CreateShaper(SDL_Window* window) { #if SDL_VIDEO_DRIVER_X11_XSHAPE if (SDL_X11_HAVE_XSHAPE) { /* Make sure X server supports it. */ result = SDL_malloc(sizeof(SDL_WindowShaper)); - if (!result) { + if (result == NULL) { SDL_OutOfMemory(); return NULL; } @@ -44,7 +44,7 @@ X11_CreateShaper(SDL_Window* window) { result->mode.parameters.binarizationCutoff = 1; result->userx = result->usery = 0; data = SDL_malloc(sizeof(SDL_ShapeData)); - if (!data) { + if (data == NULL) { SDL_free(result); SDL_OutOfMemory(); return NULL; @@ -71,14 +71,15 @@ X11_ResizeWindowShape(SDL_Window* window) { unsigned int bitmapsize = window->w / 8; SDL_assert(data != NULL); - if(window->w % 8 > 0) + if (window->w % 8 > 0) { bitmapsize += 1; + } bitmapsize *= window->h; - if(data->bitmapsize != bitmapsize || data->bitmap == NULL) { + if (data->bitmapsize != bitmapsize || data->bitmap == NULL) { data->bitmapsize = bitmapsize; SDL_free(data->bitmap); data->bitmap = SDL_malloc(data->bitmapsize); - if(data->bitmap == NULL) { + if (data->bitmap == NULL) { return SDL_OutOfMemory(); } } @@ -97,14 +98,17 @@ X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMo SDL_WindowData *windowdata = NULL; Pixmap shapemask; - if(shaper == NULL || shape == NULL || shaper->driverdata == NULL) + if (shaper == NULL || shape == NULL || shaper->driverdata == NULL) { return -1; + } #if SDL_VIDEO_DRIVER_X11_XSHAPE - if(shape->format->Amask == 0 && SDL_SHAPEMODEALPHA(shape_mode->mode)) + if (shape->format->Amask == 0 && SDL_SHAPEMODEALPHA(shape_mode->mode)) { return -2; - if(shape->w != shaper->window->w || shape->h != shaper->window->h) + } + if (shape->w != shaper->window->w || shape->h != shaper->window->h) { return -3; + } data = shaper->driverdata; /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */ diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index aa4112a312..4cff63810d 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -163,19 +163,19 @@ X11_CreateDevice(void) /* Open the display first to be sure that X11 is available */ x11_display = X11_XOpenDisplay(display); - if (!x11_display) { + if (x11_display == NULL) { SDL_X11_UnloadSymbols(); return NULL; } /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { + if (device == NULL) { SDL_OutOfMemory(); return NULL; } data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - if (!data) { + if (data == NULL) { SDL_free(device); SDL_OutOfMemory(); return NULL; @@ -336,9 +336,9 @@ static int X11_CheckWindowManagerErrorHandler(Display * d, XErrorEvent * e) { if (e->error_code == BadWindow) { - return (0); + return 0; } else { - return (handler(d, e)); + return handler(d, e); } } diff --git a/src/video/x11/SDL_x11vulkan.c b/src/video/x11/SDL_x11vulkan.c index 19697f03dc..9ae231daee 100644 --- a/src/video/x11/SDL_x11vulkan.c +++ b/src/video/x11/SDL_x11vulkan.c @@ -50,73 +50,76 @@ int X11_Vulkan_LoadLibrary(_THIS, const char *path) SDL_bool hasXCBSurfaceExtension = SDL_FALSE; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; Uint32 i; - if(_this->vulkan_config.loader_handle) + if (_this->vulkan_config.loader_handle) { return SDL_SetError("Vulkan already loaded"); + } /* Load the Vulkan loader library */ - if(!path) + if (path == NULL) { path = SDL_getenv("SDL_VULKAN_LIBRARY"); - if(!path) + } + if (path == NULL) { path = DEFAULT_VULKAN; + } _this->vulkan_config.loader_handle = SDL_LoadObject(path); - if(!_this->vulkan_config.loader_handle) + if (!_this->vulkan_config.loader_handle) { return -1; + } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); - if(!vkGetInstanceProcAddr) + if (!vkGetInstanceProcAddr) { goto fail; + } _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr; _this->vulkan_config.vkEnumerateInstanceExtensionProperties = (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)( VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties"); - if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) + if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) { goto fail; + } extensions = SDL_Vulkan_CreateInstanceExtensionsList( (PFN_vkEnumerateInstanceExtensionProperties) _this->vulkan_config.vkEnumerateInstanceExtensionProperties, &extensionCount); - if(!extensions) + if (extensions == NULL) { goto fail; - for(i = 0; i < extensionCount; i++) + } + for (i = 0; i < extensionCount; i++) { - if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasSurfaceExtension = SDL_TRUE; - else if(SDL_strcmp(VK_KHR_XCB_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + } else if (SDL_strcmp(VK_KHR_XCB_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasXCBSurfaceExtension = SDL_TRUE; - else if(SDL_strcmp(VK_KHR_XLIB_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + } else if (SDL_strcmp(VK_KHR_XLIB_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) { hasXlibSurfaceExtension = SDL_TRUE; + } } SDL_free(extensions); - if(!hasSurfaceExtension) - { + if (!hasSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension"); goto fail; } - if(hasXlibSurfaceExtension) - { + if (hasXlibSurfaceExtension) { videoData->vulkan_xlib_xcb_library = NULL; - } - else if(!hasXCBSurfaceExtension) - { + } else if (!hasXCBSurfaceExtension) { SDL_SetError("Installed Vulkan doesn't implement either the " VK_KHR_XCB_SURFACE_EXTENSION_NAME "extension or the " VK_KHR_XLIB_SURFACE_EXTENSION_NAME " extension"); goto fail; - } - else - { + } else { const char *libX11XCBLibraryName = SDL_getenv("SDL_X11_XCB_LIBRARY"); - if(!libX11XCBLibraryName) + if (libX11XCBLibraryName == NULL) { libX11XCBLibraryName = "libX11-xcb.so"; + } videoData->vulkan_xlib_xcb_library = SDL_LoadObject(libX11XCBLibraryName); - if(!videoData->vulkan_xlib_xcb_library) + if (!videoData->vulkan_xlib_xcb_library) { goto fail; + } videoData->vulkan_XGetXCBConnection = SDL_LoadFunction(videoData->vulkan_xlib_xcb_library, "XGetXCBConnection"); - if(!videoData->vulkan_XGetXCBConnection) - { + if (!videoData->vulkan_XGetXCBConnection) { SDL_UnloadObject(videoData->vulkan_xlib_xcb_library); goto fail; } @@ -132,10 +135,10 @@ fail: void X11_Vulkan_UnloadLibrary(_THIS) { SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata; - if(_this->vulkan_config.loader_handle) - { - if(videoData->vulkan_xlib_xcb_library) + if (_this->vulkan_config.loader_handle) { + if (videoData->vulkan_xlib_xcb_library) { SDL_UnloadObject(videoData->vulkan_xlib_xcb_library); + } SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; } @@ -147,21 +150,17 @@ SDL_bool X11_Vulkan_GetInstanceExtensions(_THIS, const char **names) { SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } - if(videoData->vulkan_xlib_xcb_library) - { + if (videoData->vulkan_xlib_xcb_library) { static const char *const extensionsForXCB[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME, }; return SDL_Vulkan_GetInstanceExtensions_Helper( count, names, SDL_arraysize(extensionsForXCB), extensionsForXCB); - } - else - { + } else { static const char *const extensionsForXlib[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME, }; @@ -178,21 +177,18 @@ SDL_bool X11_Vulkan_CreateSurface(_THIS, SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata; SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; - if(!_this->vulkan_config.loader_handle) - { + if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; } vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr; - if(videoData->vulkan_xlib_xcb_library) - { + if (videoData->vulkan_xlib_xcb_library) { PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR)vkGetInstanceProcAddr(instance, "vkCreateXcbSurfaceKHR"); VkXcbSurfaceCreateInfoKHR createInfo; VkResult result; - if(!vkCreateXcbSurfaceKHR) - { + if (!vkCreateXcbSurfaceKHR) { SDL_SetError(VK_KHR_XCB_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); return SDL_FALSE; @@ -200,30 +196,25 @@ SDL_bool X11_Vulkan_CreateSurface(_THIS, SDL_zero(createInfo); createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; createInfo.connection = videoData->vulkan_XGetXCBConnection(videoData->display); - if(!createInfo.connection) - { + if (!createInfo.connection) { SDL_SetError("XGetXCBConnection failed"); return SDL_FALSE; } createInfo.window = (xcb_window_t)windowData->xwindow; result = vkCreateXcbSurfaceKHR(instance, &createInfo, NULL, surface); - if(result != VK_SUCCESS) - { + if (result != VK_SUCCESS) { SDL_SetError("vkCreateXcbSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); return SDL_FALSE; } return SDL_TRUE; - } - else - { + } else { PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR)vkGetInstanceProcAddr(instance, "vkCreateXlibSurfaceKHR"); VkXlibSurfaceCreateInfoKHR createInfo; VkResult result; - if(!vkCreateXlibSurfaceKHR) - { + if (!vkCreateXlibSurfaceKHR) { SDL_SetError(VK_KHR_XLIB_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); return SDL_FALSE; @@ -234,8 +225,7 @@ SDL_bool X11_Vulkan_CreateSurface(_THIS, createInfo.window = (xcb_window_t)windowData->xwindow; result = vkCreateXlibSurfaceKHR(instance, &createInfo, NULL, surface); - if(result != VK_SUCCESS) - { + if (result != VK_SUCCESS) { SDL_SetError("vkCreateXlibSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); return SDL_FALSE; } diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 14acec2d1d..1e41571bb1 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -102,10 +102,8 @@ X11_IsActionAllowed(SDL_Window *window, Atom action) Atom *list; SDL_bool ret = SDL_FALSE; - if (X11_XGetWindowProperty(display, data->xwindow, _NET_WM_ALLOWED_ACTIONS, 0, 1024, False, XA_ATOM, &type, &form, &len, &remain, (unsigned char **)&list) == Success) - { - for (i=0; ixwindow, _NET_WM_ALLOWED_ACTIONS, 0, 1024, False, XA_ATOM, &type, &form, &len, &remain, (unsigned char **)&list) == Success) { + for (i=0; iwindow = window; @@ -292,7 +290,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) (SDL_WindowData **) SDL_realloc(windowlist, (numwindows + 1) * sizeof(*windowlist)); - if (!windowlist) { + if (windowlist == NULL) { SDL_free(data); return SDL_OutOfMemory(); } @@ -326,8 +324,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) Window FocalWindow; int RevertTo=0; X11_XGetInputFocus(data->videodata->display, &FocalWindow, &RevertTo); - if (FocalWindow==w) - { + if (FocalWindow==w) { window->flags |= SDL_WINDOW_INPUT_FOCUS; } @@ -405,8 +402,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) #if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_EGL const char *forced_visual_id = SDL_GetHint(SDL_HINT_VIDEO_X11_WINDOW_VISUALID); - if (forced_visual_id != NULL && forced_visual_id[0] != '\0') - { + if (forced_visual_id != NULL && forced_visual_id[0] != '\0') { XVisualInfo *vi, template; int nvis; @@ -417,13 +413,10 @@ X11_CreateWindow(_THIS, SDL_Window * window) visual = vi->visual; depth = vi->depth; X11_XFree(vi); - } - else - { + } else { return -1; } - } - else if ((window->flags & SDL_WINDOW_OPENGL) && + } else if ((window->flags & SDL_WINDOW_OPENGL) && !SDL_getenv("SDL_VIDEO_X11_VISUALID")) { XVisualInfo *vinfo = NULL; @@ -443,7 +436,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) #endif } - if (!vinfo) { + if (vinfo == NULL) { return -1; } visual = vinfo->visual; @@ -480,7 +473,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) /* OK, we got a colormap, now fill it in as best as we can */ colorcells = SDL_malloc(visual->map_entries * sizeof(XColor)); - if (!colorcells) { + if (colorcells == NULL) { return SDL_OutOfMemory(); } ncolors = visual->map_entries; @@ -1031,7 +1024,7 @@ X11_SetWindowOpacity(_THIS, SDL_Window * window, float opacity) if (opacity == 1.0f) { X11_XDeleteProperty(display, data->xwindow, _NET_WM_WINDOW_OPACITY); - } else { + } else { const Uint32 FullyOpaque = 0xFFFFFFFF; const long alpha = (long) ((double)opacity * (double)FullyOpaque); X11_XChangeProperty(display, data->xwindow, _NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32, @@ -1180,8 +1173,9 @@ X11_ShowWindow(_THIS, SDL_Window * window) /* Blocking wait for "MapNotify" event. * We use X11_XIfEvent because pXWindowEvent takes a mask rather than a type, * and XCheckTypedWindowEvent doesn't block */ - if(!(window->flags & SDL_WINDOW_FOREIGN)) + if (!(window->flags & SDL_WINDOW_FOREIGN)) { X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow); + } X11_XFlush(display); } @@ -1204,8 +1198,9 @@ X11_HideWindow(_THIS, SDL_Window * window) if (X11_IsWindowMapped(_this, window)) { X11_XWithdrawWindow(display, data->xwindow, displaydata->screen); /* Blocking wait for "UnmapNotify" event */ - if(!(window->flags & SDL_WINDOW_FOREIGN)) + if (!(window->flags & SDL_WINDOW_FOREIGN)) { X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow); + } X11_XFlush(display); } } @@ -1495,7 +1490,9 @@ static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop) int bytes_fetch = 0; do { - if (ret != NULL) X11_XFree(ret); + if (ret != NULL) { + X11_XFree(ret); + } X11_XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret); bytes_fetch += bytes_left; } while (bytes_left != 0); @@ -1544,7 +1541,7 @@ X11_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size) } ret_icc_profile_data = SDL_malloc(real_nitems); - if (!ret_icc_profile_data) { + if (ret_icc_profile_data == NULL) { SDL_OutOfMemory(); return NULL; } @@ -1699,7 +1696,7 @@ X11_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; - if (!data) { + if (data == NULL) { /* This sometimes happens in SDL_IBus_UpdateTextRect() while creating the window */ return SDL_SetError("Window not initialized"); } @@ -1741,7 +1738,7 @@ X11_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation) XWMHints *wmhints; wmhints = X11_XGetWMHints(display, data->xwindow); - if (!wmhints) { + if (wmhints == NULL) { return SDL_SetError("Couldn't get WM hints"); } diff --git a/src/video/x11/SDL_x11xfixes.c b/src/video/x11/SDL_x11xfixes.c index 95027d46b2..dfe3a4c64c 100644 --- a/src/video/x11/SDL_x11xfixes.c +++ b/src/video/x11/SDL_x11xfixes.c @@ -35,13 +35,13 @@ query_xfixes_version(Display *display, int major, int minor) { /* We don't care if this fails, so long as it sets major/minor on it's way out the door. */ X11_XFixesQueryVersion(display, &major, &minor); - return ((major * 1000) + minor); + return (major * 1000) + minor; } static SDL_bool xfixes_version_atleast(const int version, const int wantmajor, const int wantminor) { - return (version >= ((wantmajor * 1000) + wantminor)); + return version >= ((wantmajor * 1000) + wantminor); } void diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index db3187b019..a23e58744b 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -46,8 +46,9 @@ static void parse_valuators(const double *input_values, const unsigned char *mas double *output_values,int output_values_len) { int i = 0,z = 0; int top = mask_len * 8; - if (top > MAX_AXIS) + if (top > MAX_AXIS) { top = MAX_AXIS; + } SDL_memset(output_values,0,output_values_len * sizeof(double)); for (; i < top && z < output_values_len; i++) { @@ -65,13 +66,13 @@ query_xinput2_version(Display *display, int major, int minor) { /* We don't care if this fails, so long as it sets major/minor on it's way out the door. */ X11_XIQueryVersion(display, &major, &minor); - return ((major * 1000) + minor); + return (major * 1000) + minor; } static SDL_bool xinput2_version_atleast(const int version, const int wantmajor, const int wantminor) { - return ( version >= ((wantmajor * 1000) + wantminor) ); + return version >= ((wantmajor * 1000) + wantminor); } #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH @@ -232,13 +233,13 @@ xinput2_get_device_info(SDL_VideoData *videodata, const int device_id) /* don't know about this device yet, query and cache it. */ devinfo = (SDL_XInput2DeviceInfo *) SDL_calloc(1, sizeof (SDL_XInput2DeviceInfo)); - if (!devinfo) { + if (devinfo == NULL) { SDL_OutOfMemory(); return NULL; } xidevinfo = X11_XIQueryDevice(videodata->display, device_id, &i); - if (!xidevinfo) { + if (xidevinfo == NULL) { SDL_free(devinfo); return NULL; } @@ -292,7 +293,7 @@ X11_HandleXinput2Event(SDL_VideoData *videodata, XGenericEventCookie *cookie) } devinfo = xinput2_get_device_info(videodata, rawev->deviceid); - if (!devinfo) { + if (devinfo == NULL) { return 0; /* oh well. */ } @@ -417,8 +418,9 @@ X11_InitXinput2Multitouch(_THIS) XITouchClassInfo *t = (XITouchClassInfo*)class; /* Only touch devices */ - if (class->type != XITouchClass) + if (class->type != XITouchClass) { continue; + } if (t->mode == XIDependentTouch) { touchType = SDL_TOUCH_DEVICE_INDIRECT_RELATIVE; diff --git a/test/checkkeys.c b/test/checkkeys.c index b6d9a3e68a..4afdb9b4c6 100644 --- a/test/checkkeys.c +++ b/test/checkkeys.c @@ -66,30 +66,42 @@ print_modifiers(char **text, size_t *maxlen) print_string(text, maxlen, " (none)"); return; } - if (mod & KMOD_LSHIFT) + if (mod & KMOD_LSHIFT) { print_string(text, maxlen, " LSHIFT"); - if (mod & KMOD_RSHIFT) + } + if (mod & KMOD_RSHIFT) { print_string(text, maxlen, " RSHIFT"); - if (mod & KMOD_LCTRL) + } + if (mod & KMOD_LCTRL) { print_string(text, maxlen, " LCTRL"); - if (mod & KMOD_RCTRL) + } + if (mod & KMOD_RCTRL) { print_string(text, maxlen, " RCTRL"); - if (mod & KMOD_LALT) + } + if (mod & KMOD_LALT) { print_string(text, maxlen, " LALT"); - if (mod & KMOD_RALT) + } + if (mod & KMOD_RALT) { print_string(text, maxlen, " RALT"); - if (mod & KMOD_LGUI) + } + if (mod & KMOD_LGUI) { print_string(text, maxlen, " LGUI"); - if (mod & KMOD_RGUI) + } + if (mod & KMOD_RGUI) { print_string(text, maxlen, " RGUI"); - if (mod & KMOD_NUM) + } + if (mod & KMOD_NUM) { print_string(text, maxlen, " NUM"); - if (mod & KMOD_CAPS) + } + if (mod & KMOD_CAPS) { print_string(text, maxlen, " CAPS"); - if (mod & KMOD_MODE) + } + if (mod & KMOD_MODE) { print_string(text, maxlen, " MODE"); - if (mod & KMOD_SCROLL) + } + if (mod & KMOD_SCROLL) { print_string(text, maxlen, " SCROLL"); + } } static void @@ -145,8 +157,7 @@ PrintText(const char *eventtype, const char *text) char expanded[1024]; expanded[0] = '\0'; - for ( spot = text; *spot; ++spot ) - { + for ( spot = text; *spot; ++spot ) { size_t length = SDL_strlen(expanded); SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot); } @@ -251,21 +262,21 @@ main(int argc, char *argv[]) /* Initialize SDL */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } /* Set 640x480 video mode */ window = SDL_CreateWindow("CheckKeys Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0); - if (!window) { + if (window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n", SDL_GetError()); quit(2); } renderer = SDL_CreateRenderer(window, -1, 0); - if (!renderer) { + if (renderer == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); quit(2); @@ -296,7 +307,7 @@ main(int argc, char *argv[]) #endif SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/checkkeysthreads.c b/test/checkkeysthreads.c index 728a1c54dc..3e28e64ccc 100644 --- a/test/checkkeysthreads.c +++ b/test/checkkeysthreads.c @@ -63,30 +63,42 @@ print_modifiers(char **text, size_t *maxlen) print_string(text, maxlen, " (none)"); return; } - if (mod & KMOD_LSHIFT) + if (mod & KMOD_LSHIFT) { print_string(text, maxlen, " LSHIFT"); - if (mod & KMOD_RSHIFT) + } + if (mod & KMOD_RSHIFT) { print_string(text, maxlen, " RSHIFT"); - if (mod & KMOD_LCTRL) + } + if (mod & KMOD_LCTRL) { print_string(text, maxlen, " LCTRL"); - if (mod & KMOD_RCTRL) + } + if (mod & KMOD_RCTRL) { print_string(text, maxlen, " RCTRL"); - if (mod & KMOD_LALT) + } + if (mod & KMOD_LALT) { print_string(text, maxlen, " LALT"); - if (mod & KMOD_RALT) + } + if (mod & KMOD_RALT) { print_string(text, maxlen, " RALT"); - if (mod & KMOD_LGUI) + } + if (mod & KMOD_LGUI) { print_string(text, maxlen, " LGUI"); - if (mod & KMOD_RGUI) + } + if (mod & KMOD_RGUI) { print_string(text, maxlen, " RGUI"); - if (mod & KMOD_NUM) + } + if (mod & KMOD_NUM) { print_string(text, maxlen, " NUM"); - if (mod & KMOD_CAPS) + } + if (mod & KMOD_CAPS) { print_string(text, maxlen, " CAPS"); - if (mod & KMOD_MODE) + } + if (mod & KMOD_MODE) { print_string(text, maxlen, " MODE"); - if (mod & KMOD_SCROLL) + } + if (mod & KMOD_SCROLL) { print_string(text, maxlen, " SCROLL"); + } } static void @@ -143,8 +155,7 @@ PrintText(const char *eventtype, const char *text) char expanded[1024]; expanded[0] = '\0'; - for ( spot = text; *spot; ++spot ) - { + for ( spot = text; *spot; ++spot ) { size_t length = SDL_strlen(expanded); SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot); } @@ -234,14 +245,14 @@ main(int argc, char *argv[]) /* Initialize SDL */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } /* Set 640x480 video mode */ window = SDL_CreateWindow("CheckKeys Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0); - if (!window) { + if (window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n", SDL_GetError()); quit(2); @@ -279,7 +290,7 @@ main(int argc, char *argv[]) SDL_WaitThread(thread, NULL); SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/controllermap.c b/test/controllermap.c index 9f5c7f34f3..81eb92cf3d 100644 --- a/test/controllermap.c +++ b/test/controllermap.c @@ -196,8 +196,7 @@ SetCurrentBinding(int iBinding) return; } - if (s_arrBindingOrder[iBinding] == -1) - { + if (s_arrBindingOrder[iBinding] == -1) { SetCurrentBinding(iBinding + 1); return; } @@ -224,8 +223,7 @@ SetCurrentBinding(int iBinding) static SDL_bool BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const SDL_GameControllerExtendedBind *pBindingB) { - if (pBindingA->bindType != pBindingB->bindType) - { + if (pBindingA->bindType != pBindingB->bindType) { return SDL_FALSE; } switch (pBindingA->bindType) @@ -242,7 +240,7 @@ BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const S int maxA = SDL_max(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max); int minB = SDL_min(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max); int maxB = SDL_max(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max); - return (minA <= minB && maxA >= maxB); + return minA <= minB && maxA >= maxB; } /* Not reached */ default: diff --git a/test/loopwave.c b/test/loopwave.c index e450225635..a0f7eacda8 100644 --- a/test/loopwave.c +++ b/test/loopwave.c @@ -104,8 +104,9 @@ static int done = 0; void loop() { - if(done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING)) + if (done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING)) { emscripten_cancel_main_loop(); + } } #endif @@ -121,7 +122,7 @@ main(int argc, char *argv[]) /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_EVENTS) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav"); @@ -175,7 +176,7 @@ main(int argc, char *argv[]) SDL_FreeWAV(wave.sound); SDL_free(filename); SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/loopwavequeue.c b/test/loopwavequeue.c index 6009a134fd..ab57504fff 100644 --- a/test/loopwavequeue.c +++ b/test/loopwavequeue.c @@ -55,8 +55,7 @@ loop() #ifdef __EMSCRIPTEN__ if (done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)) { emscripten_cancel_main_loop(); - } - else + } else #endif { /* The device from SDL_OpenAudio() is always device #1. */ @@ -83,7 +82,7 @@ main(int argc, char *argv[]) /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav"); @@ -134,8 +133,7 @@ main(int argc, char *argv[]) #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(loop, 0, 1); #else - while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) - { + while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) { loop(); SDL_Delay(100); /* let it play for awhile. */ diff --git a/test/testatomic.c b/test/testatomic.c index bcda24e041..8823ce15cf 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -23,8 +23,7 @@ tf(SDL_bool _tf) static const char *t = "TRUE"; static const char *f = "FALSE"; - if (_tf) - { + if (_tf) { return t; } @@ -140,11 +139,13 @@ void runAdder(void) SDL_AtomicSet(&threadsRunning, NThreads); - while (T--) + while (T--) { SDL_CreateThread(adder, "Adder", NULL); + } - while (SDL_AtomicGet(&threadsRunning) > 0) + while (SDL_AtomicGet(&threadsRunning) > 0) { SDL_SemWait(threadDone); + } SDL_DestroySemaphore(threadDone); diff --git a/test/testaudiocapture.c b/test/testaudiocapture.c index ae56d3535e..e26e1de333 100644 --- a/test/testaudiocapture.c +++ b/test/testaudiocapture.c @@ -102,7 +102,7 @@ main(int argc, char **argv) /* Load the SDL library */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } window = SDL_CreateWindow("testaudiocapture", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0); diff --git a/test/testaudiohotplug.c b/test/testaudiohotplug.c index 2ab0a0787d..17a7cb89ac 100644 --- a/test/testaudiohotplug.c +++ b/test/testaudiohotplug.c @@ -87,8 +87,9 @@ iteration() if (e.type == SDL_QUIT) { done = 1; } else if (e.type == SDL_KEYUP) { - if (e.key.keysym.sym == SDLK_ESCAPE) + if (e.key.keysym.sym == SDLK_ESCAPE) { done = 1; + } } else if (e.type == SDL_AUDIODEVICEADDED) { int index = e.adevice.which; int iscapture = e.adevice.iscapture; @@ -124,7 +125,7 @@ iteration() void loop() { - if(done) + if (done) emscripten_cancel_main_loop(); else iteration(); @@ -143,7 +144,7 @@ main(int argc, char *argv[]) /* Load the SDL library */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } /* Some targets (Mac CoreAudio) need an event queue for audio hotplug, so make and immediately hide a window. */ @@ -198,7 +199,7 @@ main(int argc, char *argv[]) SDL_FreeWAV(sound); SDL_free(filename); SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testaudioinfo.c b/test/testaudioinfo.c index 14ebb66235..30d2d40905 100644 --- a/test/testaudioinfo.c +++ b/test/testaudioinfo.c @@ -56,7 +56,7 @@ main(int argc, char **argv) /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } /* Print available audio drivers */ diff --git a/test/testautomation.c b/test/testautomation.c index 00f6bf6757..aab245dad0 100644 --- a/test/testautomation.c +++ b/test/testautomation.c @@ -40,7 +40,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } @@ -54,23 +54,22 @@ main(int argc, char *argv[]) if (SDL_strcasecmp(argv[i], "--iterations") == 0) { if (argv[i + 1]) { testIterations = SDL_atoi(argv[i + 1]); - if (testIterations < 1) testIterations = 1; + if (testIterations < 1) { + testIterations = 1; + } consumed = 2; } - } - else if (SDL_strcasecmp(argv[i], "--execKey") == 0) { + } else if (SDL_strcasecmp(argv[i], "--execKey") == 0) { if (argv[i + 1]) { SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, &userExecKey); consumed = 2; } - } - else if (SDL_strcasecmp(argv[i], "--seed") == 0) { + } else if (SDL_strcasecmp(argv[i], "--seed") == 0) { if (argv[i + 1]) { userRunSeed = SDL_strdup(argv[i + 1]); consumed = 2; } - } - else if (SDL_strcasecmp(argv[i], "--filter") == 0) { + } else if (SDL_strcasecmp(argv[i], "--filter") == 0) { if (argv[i + 1]) { filter = SDL_strdup(argv[i + 1]); consumed = 2; @@ -103,7 +102,7 @@ main(int argc, char *argv[]) /* Empty event queue */ done = 0; - for (i=0; i<100; i++) { + for (i=0; i<100; i++) { while (SDL_PollEvent(&event)) { SDLTest_CommonEvent(state, &event, &done); } @@ -116,7 +115,7 @@ main(int argc, char *argv[]) /* Shutdown everything */ quit(result); - return(result); + return result; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c index 535de074c5..a47886bc68 100644 --- a/test/testautomation_audio.c +++ b/test/testautomation_audio.c @@ -460,8 +460,7 @@ int audio_printAudioDrivers() SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n); /* List drivers. */ - if (n>0) - { + if (n>0) { for (i=0; i 0, "Verify that cvt.len_mult value; expected: >0, got: %i", cvt.len_mult); - if (cvt.len_mult < 1) return TEST_ABORTED; + if (cvt.len_mult < 1) { + return TEST_ABORTED; + } /* Create some random data to convert */ l = 64; @@ -886,7 +891,9 @@ int audio_convertAudio() cvt.len = l; cvt.buf = (Uint8 *)SDL_malloc(ll); SDLTest_AssertCheck(cvt.buf != NULL, "Check data buffer to convert is not NULL"); - if (cvt.buf == NULL) return TEST_ABORTED; + if (cvt.buf == NULL) { + return TEST_ABORTED; + } /* Convert the data */ result = SDL_ConvertAudio(&cvt); @@ -931,7 +938,9 @@ int audio_openCloseAudioDeviceConnected() device = SDL_GetAudioDeviceName(i, 0); SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i); SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL"); - if (device == NULL) return TEST_ABORTED; + if (device == NULL) { + return TEST_ABORTED; + } /* Set standard desired spec */ desired.freq=22050; diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index 9e96c02399..957f6588fb 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -228,7 +228,9 @@ mouse_createFreeColorCursor(void *arg) /* Get sample surface */ face = SDLTest_ImageFace(); SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL"); - if (face == NULL) return TEST_ABORTED; + if (face == NULL) { + return TEST_ABORTED; + } /* Create a color cursor from surface */ cursor = SDL_CreateColorCursor(face, 0, 0); @@ -464,7 +466,9 @@ mouse_warpMouseInWindow(void *arg) yPositions[5] = h+1; /* Create test window */ window = _createMouseSuiteTestWindow(); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } /* Mouse to random position inside window */ x = SDLTest_RandomIntegerInRange(1, w-1); @@ -516,7 +520,9 @@ mouse_getMouseFocus(void *arg) /* Create test window */ window = _createMouseSuiteTestWindow(); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } /* Mouse to random position inside window */ x = SDLTest_RandomIntegerInRange(1, w-1); diff --git a/test/testautomation_pixels.c b/test/testautomation_pixels.c index 31905eabef..a5fb79eec0 100644 --- a/test/testautomation_pixels.c +++ b/test/testautomation_pixels.c @@ -349,7 +349,7 @@ pixels_allocFreePalette(void *arg) if (result->ncolors > 0) { SDLTest_AssertCheck(result->colors != NULL, "Verify value of result.colors is not NULL"); if (result->colors != NULL) { - for(i = 0; i < result->ncolors; i++) { + for (i = 0; i < result->ncolors; i++) { SDLTest_AssertCheck(result->colors[i].r == 255, "Verify value of result.colors[%d].r; expected: 255, got %u", i, result->colors[i].r); SDLTest_AssertCheck(result->colors[i].g == 255, "Verify value of result.colors[%d].g; expected: 255, got %u", i, result->colors[i].g); SDLTest_AssertCheck(result->colors[i].b == 255, "Verify value of result.colors[%d].b; expected: 255, got %u", i, result->colors[i].b); diff --git a/test/testautomation_platform.c b/test/testautomation_platform.c index be38b098fb..e1d485b6e9 100644 --- a/test/testautomation_platform.c +++ b/test/testautomation_platform.c @@ -301,8 +301,7 @@ int platform_testGetSetClearError(void *arg) SDLTest_AssertPass("SDL_GetError()"); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); - if (lastError != NULL) - { + if (lastError != NULL) { len = SDL_strlen(lastError); SDLTest_AssertCheck(len == 0, "SDL_GetError(): no message expected, len: %i", (int) len); @@ -314,8 +313,7 @@ int platform_testGetSetClearError(void *arg) lastError = (char *)SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); - if (lastError != NULL) - { + if (lastError != NULL) { len = SDL_strlen(lastError); SDLTest_AssertCheck(len == SDL_strlen(testError), "SDL_GetError(): expected message len %i, was len: %i", @@ -352,8 +350,7 @@ int platform_testSetErrorEmptyInput(void *arg) lastError = (char *)SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); - if (lastError != NULL) - { + if (lastError != NULL) { len = SDL_strlen(lastError); SDLTest_AssertCheck(len == SDL_strlen(testError), "SDL_GetError(): expected message len %i, was len: %i", @@ -401,8 +398,7 @@ int platform_testSetErrorInvalidInput(void *arg) lastError = (char *)SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); - if (lastError != NULL) - { + if (lastError != NULL) { len = SDL_strlen(lastError); SDLTest_AssertCheck(len == 0 || SDL_strcmp(lastError, "(null)") == 0, "SDL_GetError(): expected message len 0, was len: %i", @@ -421,8 +417,7 @@ int platform_testSetErrorInvalidInput(void *arg) lastError = (char *)SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); - if (lastError != NULL) - { + if (lastError != NULL) { len = SDL_strlen(lastError); SDLTest_AssertCheck(len == 0 || SDL_strcmp( lastError, "(null)" ) == 0, "SDL_GetError(): expected message len 0, was len: %i", @@ -440,8 +435,7 @@ int platform_testSetErrorInvalidInput(void *arg) lastError = (char *)SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); - if (lastError != NULL) - { + if (lastError != NULL) { len = SDL_strlen(lastError); SDLTest_AssertCheck(len == SDL_strlen(probeError), "SDL_GetError(): expected message len %i, was len: %i", @@ -489,8 +483,7 @@ int platform_testGetPowerInfo(void *arg) "SDL_GetPowerInfo(): state %i is one of the expected values", (int)state); - if (state==SDL_POWERSTATE_ON_BATTERY) - { + if (state==SDL_POWERSTATE_ON_BATTERY) { SDLTest_AssertCheck( secs >= 0, "SDL_GetPowerInfo(): on battery, secs >= 0, was: %i", diff --git a/test/testautomation_rect.c b/test/testautomation_rect.c index b5fae942e5..10933e5942 100644 --- a/test/testautomation_rect.c +++ b/test/testautomation_rect.c @@ -1006,10 +1006,18 @@ int rect_testEnclosePoints(void *arg) miny = newy; maxy = newy; } else { - if (newx < minx) minx = newx; - if (newx > maxx) maxx = newx; - if (newy < miny) miny = newy; - if (newy > maxy) maxy = newy; + if (newx < minx) { + minx = newx; + } + if (newx > maxx) { + maxx = newx; + } + if (newy < miny) { + miny = newy; + } + if (newy > maxy) { + maxy = newy; + } } } @@ -1082,10 +1090,18 @@ int rect_testEnclosePointsRepeatedInput(void *arg) miny = newy; maxy = newy; } else { - if (newx < minx) minx = newx; - if (newx > maxx) maxx = newx; - if (newy < miny) miny = newy; - if (newy > maxy) maxy = newy; + if (newx < minx) { + minx = newx; + } + if (newx > maxx) { + maxx = newx; + } + if (newy < miny) { + miny = newy; + } + if (newy > maxy) { + maxy = newy; + } } } @@ -1162,10 +1178,18 @@ int rect_testEnclosePointsWithClipping(void *arg) miny = newy; maxy = newy; } else { - if (newx < minx) minx = newx; - if (newx > maxx) maxx = newx; - if (newy < miny) miny = newy; - if (newy > maxy) maxy = newy; + if (newx < minx) { + minx = newx; + } + if (newx > maxx) { + maxx = newx; + } + if (newy < miny) { + miny = newy; + } + if (newy > maxy) { + maxy = newy; + } } expectedEnclosed = SDL_TRUE; } @@ -1302,10 +1326,18 @@ int rect_testUnionRectOutside(void *arg) refRectB.w=refRectA.w - 2; refRectB.h=refRectA.h - 2; expectedResult = refRectA; - if (dx == -1) expectedResult.x--; - if (dy == -1) expectedResult.y--; - if ((dx == 1) || (dx == -1)) expectedResult.w++; - if ((dy == 1) || (dy == -1)) expectedResult.h++; + if (dx == -1) { + expectedResult.x--; + } + if (dy == -1) { + expectedResult.y--; + } + if ((dx == 1) || (dx == -1)) { + expectedResult.w++; + } + if ((dy == 1) || (dy == -1)) { + expectedResult.h++; + } rectA = refRectA; rectB = refRectB; SDL_UnionRect(&rectA, &rectB, &result); @@ -1430,10 +1462,18 @@ int rect_testUnionRectInside(void *arg) refRectA.w=SDLTest_RandomIntegerInRange(256, 1024); refRectA.h=SDLTest_RandomIntegerInRange(256, 1024); refRectB = refRectA; - if (dx == -1) refRectB.x++; - if ((dx == 1) || (dx == -1)) refRectB.w--; - if (dy == -1) refRectB.y++; - if ((dy == 1) || (dy == -1)) refRectB.h--; + if (dx == -1) { + refRectB.x++; + } + if ((dx == 1) || (dx == -1)) { + refRectB.w--; + } + if (dy == -1) { + refRectB.y++; + } + if ((dy == 1) || (dy == -1)) { + refRectB.h--; + } expectedResult = refRectA; rectA = refRectA; rectB = refRectB; diff --git a/test/testautomation_render.c b/test/testautomation_render.c index 1651b5757e..ec8e9789c5 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -148,10 +148,14 @@ int render_testPrimitives (void *arg) for (y=0; y<3; y++) { for (x = y % 2; xtype == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY, rw->type); @@ -272,7 +277,9 @@ rwops_testConstMem (void) SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL"); /* Bail out if NULL */ - if (rw == NULL) return TEST_ABORTED; + if (rw == NULL) { + return TEST_ABORTED; + } /* Check type */ SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY_RO, rw->type); @@ -308,7 +315,9 @@ rwops_testFileRead(void) SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL"); /* Bail out if NULL */ - if (rw == NULL) return TEST_ABORTED; + if (rw == NULL) { + return TEST_ABORTED; + } /* Check type */ #if defined(__ANDROID__) @@ -355,7 +364,9 @@ rwops_testFileWrite(void) SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL"); /* Bail out if NULL */ - if (rw == NULL) return TEST_ABORTED; + if (rw == NULL) { + return TEST_ABORTED; + } /* Check type */ #if defined(__ANDROID__) @@ -397,7 +408,9 @@ rwops_testAllocFree (void) SDL_RWops *rw = SDL_AllocRW(); SDLTest_AssertPass("Call to SDL_AllocRW() succeeded"); SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL"); - if (rw==NULL) return TEST_ABORTED; + if (rw == NULL) { + return TEST_ABORTED; + } /* Check type */ SDLTest_AssertCheck( @@ -433,8 +446,7 @@ rwops_testCompareRWFromMemWithRWFromFile(void) int result; - for (size=5; size<10; size++) - { + for (size=5; size<10; size++) { /* Terminate buffer */ buffer_file[slen] = 0; buffer_mem[slen] = 0; @@ -547,7 +559,9 @@ rwops_testFileWriteReadEndian(void) SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL"); /* Bail out if NULL */ - if (rw == NULL) return TEST_ABORTED; + if (rw == NULL) { + return TEST_ABORTED; + } /* Write test data */ objectsWritten = SDL_WriteBE16(rw, BE16value); diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c index e818a4fc14..84c18766de 100644 --- a/test/testautomation_stdlib.c +++ b/test/testautomation_stdlib.c @@ -188,7 +188,7 @@ stdlib_getsetenv(void *arg) /* Create a random name. This tests SDL_getenv, since we need to */ /* make sure the variable is not set yet (it shouldn't). */ do { - for(counter = 0; counter < nameLen; counter++) { + for (counter = 0; counter < nameLen; counter++) { name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90); } name[nameLen] = '\0'; diff --git a/test/testautomation_surface.c b/test/testautomation_surface.c index b74ee53610..f252539d65 100644 --- a/test/testautomation_surface.c +++ b/test/testautomation_surface.c @@ -110,12 +110,16 @@ void _testBlitBlendMode(int mode) /* Check test surface */ SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL"); - if (testSurface == NULL) return; + if (testSurface == NULL) { + return; + } /* Create sample surface */ face = SDLTest_ImageFace(); SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL"); - if (face == NULL) return; + if (face == NULL) { + return; + } /* Reset alpha modulation */ ret = SDL_SetSurfaceAlphaMod(face, 255); @@ -160,14 +164,16 @@ void _testBlitBlendMode(int mode) if (mode == -2) { /* Set color mod. */ ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j ); - if (ret != 0) checkFailCount2++; - } - else if (mode == -3) { + if (ret != 0) { + checkFailCount2++; + } + } else if (mode == -3) { /* Set alpha mod. */ ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i ); - if (ret != 0) checkFailCount3++; - } - else if (mode == -4) { + if (ret != 0) { + checkFailCount3++; + } + } else if (mode == -4) { /* Crazy blending mode magic. */ nmode = (i/4*j/4) % 4; if (nmode==0) { @@ -184,14 +190,18 @@ void _testBlitBlendMode(int mode) return; } ret = SDL_SetSurfaceBlendMode( face, bmode ); - if (ret != 0) checkFailCount4++; + if (ret != 0) { + checkFailCount4++; + } } /* Blitting. */ rect.x = i; rect.y = j; ret = SDL_BlitSurface( face, NULL, testSurface, &rect ); - if (ret != 0) checkFailCount1++; + if (ret != 0) { + checkFailCount1++; + } } } SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1); @@ -231,7 +241,9 @@ surface_testSaveLoadBitmap(void *arg) /* Create sample surface */ face = SDLTest_ImageFace(); SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL"); - if (face == NULL) return TEST_ABORTED; + if (face == NULL) { + return TEST_ABORTED; + } /* Delete test file; ignore errors */ unlink(sampleFilename); @@ -275,8 +287,9 @@ surface_testSurfaceConversion(void *arg) /* Create sample surface */ face = SDLTest_ImageFace(); SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL"); - if (face == NULL) + if (face == NULL) { return TEST_ABORTED; + } /* Set transparent pixel as the pixel at (0,0) */ if (face->format->palette) { @@ -346,8 +359,9 @@ surface_testCompleteSurfaceConversion(void *arg) /* Create sample surface */ face = SDLTest_ImageFace(); SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL"); - if (face == NULL) + if (face == NULL) { return TEST_ABORTED; + } /* Set transparent pixel as the pixel at (0,0) */ if (face->format->palette) { @@ -756,8 +770,7 @@ surface_testOverflow(void *arg) SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - } - else { + } else { SDLTest_Log("Can't easily overflow size_t on this platform"); } diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 75a196bcc5..94f62332bb 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -681,7 +681,9 @@ video_getSetWindowGrab(void *arg) /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } /* Get state */ originalMouseState = SDL_GetWindowMouseGrab(window); @@ -825,7 +827,9 @@ video_getWindowId(void *arg) /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } /* Get ID */ id = SDL_GetWindowID(window); @@ -879,7 +883,9 @@ video_getWindowPixelFormat(void *arg) /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } /* Get format */ format = SDL_GetWindowPixelFormat(window); @@ -917,7 +923,9 @@ video_getSetWindowPosition(void *arg) /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } for (xVariation = 0; xVariation < 4; xVariation++) { for (yVariation = 0; yVariation < 4; yVariation++) { @@ -1067,11 +1075,15 @@ video_getSetWindowSize(void *arg) result = SDL_GetDisplayBounds(0, &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) return TEST_ABORTED; + if (result != 0) { + return TEST_ABORTED; + } /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } #ifdef __WIN32__ /* Platform clips window size to screen size */ @@ -1231,11 +1243,15 @@ video_getSetWindowMinimumSize(void *arg) result = SDL_GetDisplayBounds(0, &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) return TEST_ABORTED; + if (result != 0) { + return TEST_ABORTED; + } /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } for (wVariation = 0; wVariation < 5; wVariation++) { for (hVariation = 0; hVariation < 5; hVariation++) { @@ -1370,11 +1386,15 @@ video_getSetWindowMaximumSize(void *arg) result = SDL_GetDisplayBounds(0, &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) return TEST_ABORTED; + if (result != 0) { + return TEST_ABORTED; + } /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } for (wVariation = 0; wVariation < 3; wVariation++) { for (hVariation = 0; hVariation < 3; hVariation++) { @@ -1512,7 +1532,9 @@ video_getSetWindowData(void *arg) /* Call against new test window */ window = _createVideoSuiteTestWindow(title); - if (window == NULL) return TEST_ABORTED; + if (window == NULL) { + return TEST_ABORTED; + } /* Create testdata */ datasize = SDLTest_RandomIntegerInRange(1, 32); @@ -1724,14 +1746,16 @@ video_setWindowCenteredOnDisplay(void *arg) result = SDL_GetDisplayBounds(0 % displayNum, &display0); SDLTest_AssertPass("SDL_GetDisplayBounds()"); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) + if (result != 0) { return TEST_ABORTED; + } result = SDL_GetDisplayBounds(1 % displayNum, &display1); SDLTest_AssertPass("SDL_GetDisplayBounds()"); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) + if (result != 0) { return TEST_ABORTED; + } for (xVariation = 0; xVariation < 2; xVariation++) { for (yVariation = 0; yVariation < 2; yVariation++) { diff --git a/test/testcustomcursor.c b/test/testcustomcursor.c index 23b502ce38..8bc28263f2 100644 --- a/test/testcustomcursor.c +++ b/test/testcustomcursor.c @@ -214,7 +214,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { @@ -291,7 +291,7 @@ main(int argc, char *argv[]) quit(0); /* keep the compiler happy ... */ - return(0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testdisplayinfo.c b/test/testdisplayinfo.c index 73b26695b0..789c9113f1 100644 --- a/test/testdisplayinfo.c +++ b/test/testdisplayinfo.c @@ -19,8 +19,9 @@ static void print_mode(const char *prefix, const SDL_DisplayMode *mode) { - if (!mode) + if (mode == NULL) { return; + } SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n", prefix, SDL_GetPixelFormatName(mode->format), diff --git a/test/testdraw2.c b/test/testdraw2.c index a89f1e5fe3..d337991092 100644 --- a/test/testdraw2.c +++ b/test/testdraw2.c @@ -189,8 +189,9 @@ loop() } for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); @@ -231,7 +232,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { diff --git a/test/testdrawchessboard.c b/test/testdrawchessboard.c index eefbe63689..e3380cbc5f 100644 --- a/test/testdrawchessboard.c +++ b/test/testdrawchessboard.c @@ -34,11 +34,11 @@ DrawChessBoard() /* Get the Size of drawing surface */ SDL_RenderGetViewport(renderer, &darea); - for( ; row < 8; row++) + for ( ; row < 8; row++) { column = row%2; x = column; - for( ; column < 4+(row%2); column++) + for ( ; column < 4+(row%2); column++) { SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF); @@ -101,8 +101,7 @@ main(int argc, char *argv[]) SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Initialize SDL */ - if(SDL_Init(SDL_INIT_VIDEO) != 0) - { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError()); return 1; } @@ -110,15 +109,13 @@ main(int argc, char *argv[]) /* Create window and renderer for given surface */ window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE); - if(!window) - { + if (window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError()); return 1; } surface = SDL_GetWindowSurface(window); renderer = SDL_CreateSoftwareRenderer(surface); - if(!renderer) - { + if (renderer == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError()); return 1; } diff --git a/test/testdropfile.c b/test/testdropfile.c index 3f2051e338..1aa72b10f1 100644 --- a/test/testdropfile.c +++ b/test/testdropfile.c @@ -35,7 +35,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } @@ -92,7 +92,7 @@ main(int argc, char *argv[]) quit(0); /* keep the compiler happy ... */ - return(0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testerror.c b/test/testerror.c index 9c9875c209..bcc24288bc 100644 --- a/test/testerror.c +++ b/test/testerror.c @@ -37,7 +37,7 @@ ThreadFunc(void *data) SDL_Delay(1 * 1000); } SDL_Log("Child thread error string: %s\n", SDL_GetError()); - return (0); + return 0; } int @@ -51,7 +51,7 @@ main(int argc, char *argv[]) /* Load the SDL library */ if (SDL_Init(0) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } /* Set the error value for the main thread */ @@ -77,7 +77,7 @@ main(int argc, char *argv[]) SDL_Log("Main thread error string: %s\n", SDL_GetError()); SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testevdev.c b/test/testevdev.c index f7dad14e63..c08cce0fe8 100644 --- a/test/testevdev.c +++ b/test/testevdev.c @@ -997,8 +997,7 @@ run_test(void) if (actual == t->expected) { printf("\tOK\n"); - } - else { + } else { printf("\tExpected 0x%08x\n", t->expected); for (j = 0; device_classes[j].code != 0; j++) { diff --git a/test/testfile.c b/test/testfile.c index 38a04fe62b..4ab2e8e471 100644 --- a/test/testfile.c +++ b/test/testfile.c @@ -75,20 +75,25 @@ main(int argc, char *argv[]) /* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */ rwops = SDL_RWFromFile(NULL, NULL); - if (rwops) + if (rwops) { RWOP_ERR_QUIT(rwops); + } rwops = SDL_RWFromFile(NULL, "ab+"); - if (rwops) + if (rwops) { RWOP_ERR_QUIT(rwops); + } rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj"); - if (rwops) + if (rwops) { RWOP_ERR_QUIT(rwops); + } rwops = SDL_RWFromFile("something", ""); - if (rwops) + if (rwops) { RWOP_ERR_QUIT(rwops); + } rwops = SDL_RWFromFile("something", NULL); - if (rwops) + if (rwops) { RWOP_ERR_QUIT(rwops); + } SDL_Log("test1 OK\n"); /* test 2 : check that inexistent file is not successfully opened/created when required */ @@ -97,29 +102,35 @@ main(int argc, char *argv[]) */ rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */ - if (rwops) + if (rwops) { RWOP_ERR_QUIT(rwops); + } rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */ - if (rwops) + if (rwops) { RWOP_ERR_QUIT(rwops); + } rwops = SDL_RWFromFile(FBASENAME2, "wb"); - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); + } rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2, "wb+"); - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); + } rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2, "ab"); - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); + } rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2, "ab+"); - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); + } rwops->close(rwops); unlink(FBASENAME2); SDL_Log("test2 OK\n"); @@ -128,153 +139,220 @@ main(int argc, char *argv[]) test : w mode, r mode, w+ mode */ rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */ - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); - if (1 != rwops->write(rwops, "1234567890", 10, 1)) + } + if (1 != rwops->write(rwops, "1234567890", 10, 1)) { RWOP_ERR_QUIT(rwops); - if (10 != rwops->write(rwops, "1234567890", 1, 10)) + } + if (10 != rwops->write(rwops, "1234567890", 1, 10)) { RWOP_ERR_QUIT(rwops); - if (7 != rwops->write(rwops, "1234567", 1, 7)) + } + if (7 != rwops->write(rwops, "1234567", 1, 7)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + } + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 1, 1)) - RWOP_ERR_QUIT(rwops); /* we are in write only mode */ + } + if (0 != rwops->read(rwops, test_buf, 1, 1)) { + RWOP_ERR_QUIT(rwops); /* we are in write only mode */ + } + rwops->close(rwops); rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */ - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + } + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); - if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) + } + if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) { RWOP_ERR_QUIT(rwops); - if (7 != rwops->read(rwops, test_buf, 1, 7)) + } + if (7 != rwops->read(rwops, test_buf, 1, 7)) { RWOP_ERR_QUIT(rwops); - if (SDL_memcmp(test_buf, "1234567", 7)) + } + if (SDL_memcmp(test_buf, "1234567", 7)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 1, 1)) + } + if (0 != rwops->read(rwops, test_buf, 1, 1)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 10, 100)) + } + if (0 != rwops->read(rwops, test_buf, 10, 100)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) + } + if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) { RWOP_ERR_QUIT(rwops); - if (2 != rwops->read(rwops, test_buf, 10, 3)) + } + if (2 != rwops->read(rwops, test_buf, 10, 3)) { RWOP_ERR_QUIT(rwops); - if (SDL_memcmp(test_buf, "12345678901234567890", 20)) + } + if (SDL_memcmp(test_buf, "12345678901234567890", 20)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->write(rwops, test_buf, 1, 1)) - RWOP_ERR_QUIT(rwops); /* readonly mode */ + } + if (0 != rwops->write(rwops, test_buf, 1, 1)) { + RWOP_ERR_QUIT(rwops); /* readonly mode */ + } + rwops->close(rwops); /* test 3: same with w+ mode */ rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */ - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); - if (1 != rwops->write(rwops, "1234567890", 10, 1)) + } + if (1 != rwops->write(rwops, "1234567890", 10, 1)) { RWOP_ERR_QUIT(rwops); - if (10 != rwops->write(rwops, "1234567890", 1, 10)) + } + if (10 != rwops->write(rwops, "1234567890", 1, 10)) { RWOP_ERR_QUIT(rwops); - if (7 != rwops->write(rwops, "1234567", 1, 7)) + } + if (7 != rwops->write(rwops, "1234567", 1, 7)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + } + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); - if (1 != rwops->read(rwops, test_buf, 1, 1)) - RWOP_ERR_QUIT(rwops); /* we are in read/write mode */ - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + } + if (1 != rwops->read(rwops, test_buf, 1, 1)) { + RWOP_ERR_QUIT(rwops); /* we are in read/write mode */ + } + + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); - if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) + } + if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) { RWOP_ERR_QUIT(rwops); - if (7 != rwops->read(rwops, test_buf, 1, 7)) + } + if (7 != rwops->read(rwops, test_buf, 1, 7)) { RWOP_ERR_QUIT(rwops); - if (SDL_memcmp(test_buf, "1234567", 7)) + } + if (SDL_memcmp(test_buf, "1234567", 7)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 1, 1)) + } + if (0 != rwops->read(rwops, test_buf, 1, 1)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 10, 100)) + } + if (0 != rwops->read(rwops, test_buf, 10, 100)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) + } + if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) { RWOP_ERR_QUIT(rwops); - if (2 != rwops->read(rwops, test_buf, 10, 3)) + } + if (2 != rwops->read(rwops, test_buf, 10, 3)) { RWOP_ERR_QUIT(rwops); - if (SDL_memcmp(test_buf, "12345678901234567890", 20)) + } + if (SDL_memcmp(test_buf, "12345678901234567890", 20)) { RWOP_ERR_QUIT(rwops); + } rwops->close(rwops); SDL_Log("test3 OK\n"); /* test 4: same in r+ mode */ rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */ - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); - if (1 != rwops->write(rwops, "1234567890", 10, 1)) + } + if (1 != rwops->write(rwops, "1234567890", 10, 1)) { RWOP_ERR_QUIT(rwops); - if (10 != rwops->write(rwops, "1234567890", 1, 10)) + } + if (10 != rwops->write(rwops, "1234567890", 1, 10)) { RWOP_ERR_QUIT(rwops); - if (7 != rwops->write(rwops, "1234567", 1, 7)) + } + if (7 != rwops->write(rwops, "1234567", 1, 7)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + } + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); - if (1 != rwops->read(rwops, test_buf, 1, 1)) - RWOP_ERR_QUIT(rwops); /* we are in read/write mode */ - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + } + if (1 != rwops->read(rwops, test_buf, 1, 1)) { + RWOP_ERR_QUIT(rwops); /* we are in read/write mode */ + } + + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); - if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) + } + if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) { RWOP_ERR_QUIT(rwops); - if (7 != rwops->read(rwops, test_buf, 1, 7)) + } + if (7 != rwops->read(rwops, test_buf, 1, 7)) { RWOP_ERR_QUIT(rwops); - if (SDL_memcmp(test_buf, "1234567", 7)) + } + if (SDL_memcmp(test_buf, "1234567", 7)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 1, 1)) + } + if (0 != rwops->read(rwops, test_buf, 1, 1)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 10, 100)) + } + if (0 != rwops->read(rwops, test_buf, 10, 100)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) + } + if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) { RWOP_ERR_QUIT(rwops); - if (2 != rwops->read(rwops, test_buf, 10, 3)) + } + if (2 != rwops->read(rwops, test_buf, 10, 3)) { RWOP_ERR_QUIT(rwops); - if (SDL_memcmp(test_buf, "12345678901234567890", 20)) + } + if (SDL_memcmp(test_buf, "12345678901234567890", 20)) { RWOP_ERR_QUIT(rwops); + } rwops->close(rwops); SDL_Log("test4 OK\n"); /* test5 : append mode */ rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */ - if (!rwops) + if (rwops == NULL) { RWOP_ERR_QUIT(rwops); - if (1 != rwops->write(rwops, "1234567890", 10, 1)) + } + if (1 != rwops->write(rwops, "1234567890", 10, 1)) { RWOP_ERR_QUIT(rwops); - if (10 != rwops->write(rwops, "1234567890", 1, 10)) + } + if (10 != rwops->write(rwops, "1234567890", 1, 10)) { RWOP_ERR_QUIT(rwops); - if (7 != rwops->write(rwops, "1234567", 1, 7)) + } + if (7 != rwops->write(rwops, "1234567", 1, 7)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + } + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); + } - if (1 != rwops->read(rwops, test_buf, 1, 1)) + if (1 != rwops->read(rwops, test_buf, 1, 1)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + } + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); + } - if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END)) + if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END)) { RWOP_ERR_QUIT(rwops); - if (7 != rwops->read(rwops, test_buf, 1, 7)) + } + if (7 != rwops->read(rwops, test_buf, 1, 7)) { RWOP_ERR_QUIT(rwops); - if (SDL_memcmp(test_buf, "1234567", 7)) + } + if (SDL_memcmp(test_buf, "1234567", 7)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 1, 1)) + } + if (0 != rwops->read(rwops, test_buf, 1, 1)) { RWOP_ERR_QUIT(rwops); - if (0 != rwops->read(rwops, test_buf, 10, 100)) + } + if (0 != rwops->read(rwops, test_buf, 10, 100)) { RWOP_ERR_QUIT(rwops); + } - if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR)) + if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR)) { RWOP_ERR_QUIT(rwops); + } - if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) + if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) { RWOP_ERR_QUIT(rwops); - if (3 != rwops->read(rwops, test_buf, 10, 3)) + } + if (3 != rwops->read(rwops, test_buf, 10, 3)) { RWOP_ERR_QUIT(rwops); - if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30)) + } + if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30)) { RWOP_ERR_QUIT(rwops); + } rwops->close(rwops); SDL_Log("test5 OK\n"); cleanup(); diff --git a/test/testfilesystem.c b/test/testfilesystem.c index 9ea9dd10e1..84eac495ea 100644 --- a/test/testfilesystem.c +++ b/test/testfilesystem.c @@ -28,7 +28,7 @@ main(int argc, char *argv[]) } base_path = SDL_GetBasePath(); - if(base_path == NULL){ + if (base_path == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n", SDL_GetError()); } else { @@ -37,7 +37,7 @@ main(int argc, char *argv[]) } pref_path = SDL_GetPrefPath("libsdl", "test_filesystem"); - if(pref_path == NULL){ + if (pref_path == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n", SDL_GetError()); } else { @@ -46,7 +46,7 @@ main(int argc, char *argv[]) } pref_path = SDL_GetPrefPath(NULL, "test_filesystem"); - if(pref_path == NULL){ + if (pref_path == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n", SDL_GetError()); } else { diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index 5b8ee8b90d..63afdd735f 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -92,7 +92,7 @@ static SDL_GameControllerButton virtual_button_active = SDL_CONTROLLER_BUTTON_IN static void UpdateWindowTitle() { - if (!window) { + if (window == NULL) { return; } @@ -184,13 +184,13 @@ static void AddController(int device_index, SDL_bool verbose) } controller = SDL_GameControllerOpen(device_index); - if (!controller) { + if (controller == NULL) { SDL_Log("Couldn't open controller: %s\n", SDL_GetError()); return; } controllers = (SDL_GameController **)SDL_realloc(gamecontrollers, (num_controllers + 1) * sizeof(*controllers)); - if (!controllers) { + if (controllers == NULL) { SDL_GameControllerClose(controller); return; } @@ -397,7 +397,7 @@ static void OpenVirtualController() SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError()); } else { virtual_joystick = SDL_JoystickOpen(virtual_index); - if (!virtual_joystick) { + if (virtual_joystick == NULL) { SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError()); } } @@ -906,7 +906,7 @@ main(int argc, char *argv[]) button_texture = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL); axis_texture = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL); - if (!background_front || !background_back || !button_texture || !axis_texture) { + if (background_front == NULL || background_back == NULL || button_texture == NULL || axis_texture == NULL) { SDL_DestroyRenderer(screen); SDL_DestroyWindow(window); return 2; diff --git a/test/testgeometry.c b/test/testgeometry.c index d7465f59cb..83610c3353 100644 --- a/test/testgeometry.c +++ b/test/testgeometry.c @@ -49,17 +49,17 @@ LoadSprite(const char *file) /* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */ sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h); if (!sprites[i]) { - return (-1); + return -1; } if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError()); SDL_DestroyTexture(sprites[i]); - return (-1); + return -1; } } /* We're ready to roll. :) */ - return (0); + return 0; } @@ -98,8 +98,9 @@ loop() for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); @@ -174,7 +175,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { @@ -218,7 +219,7 @@ main(int argc, char *argv[]) /* Create the windows, initialize the renderers, and load the textures */ sprites = (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites)); - if (!sprites) { + if (sprites == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } diff --git a/test/testgesture.c b/test/testgesture.c index 6feecad4be..a1514e3857 100644 --- a/test/testgesture.c +++ b/test/testgesture.c @@ -109,7 +109,7 @@ drawCircle(SDL_Surface *screen, float x, float y, float r, unsigned int c) for (ty = (float) -SDL_fabs(r); ty <= (float) SDL_fabs((int) r); ty++) { xr = (float) SDL_sqrt(r * r - ty * ty); if (r > 0) { /* r > 0 ==> filled circle */ - for(tx = -xr + 0.5f; tx <= xr - 0.5f; tx++) { + for (tx = -xr + 0.5f; tx <= xr - 0.5f; tx++) { setpix(screen, x + tx, y + ty, c); } } else { @@ -133,7 +133,7 @@ DrawScreen(SDL_Window *window) SDL_Surface *screen = SDL_GetWindowSurface(window); int i; - if (!screen) { + if (screen == NULL) { return; } @@ -273,7 +273,7 @@ loop(void) int main(int argc, char* argv[]) { state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } diff --git a/test/testgl2.c b/test/testgl2.c index 7d0719b9da..e9c95c0716 100644 --- a/test/testgl2.c +++ b/test/testgl2.c @@ -220,7 +220,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { @@ -396,8 +396,9 @@ main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { int w, h; - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } SDL_GL_MakeCurrent(state->windows[i], context); if (update_swap_interval) { SDL_GL_SetSwapInterval(swap_interval); diff --git a/test/testgles.c b/test/testgles.c index d40b54d4fb..445ac92b8d 100644 --- a/test/testgles.c +++ b/test/testgles.c @@ -116,7 +116,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { @@ -312,8 +312,9 @@ main(int argc, char *argv[]) SDLTest_CommonEvent(state, &event, &done); } for (i = 0; i < state->num_windows; ++i) { - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } status = SDL_GL_MakeCurrent(state->windows[i], context[i]); if (status) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); diff --git a/test/testgles2.c b/test/testgles2.c index 0d5caa74e0..117cc2af66 100644 --- a/test/testgles2.c +++ b/test/testgles2.c @@ -106,7 +106,7 @@ quit(int rc) x; \ { \ GLenum glError = ctx.glGetError(); \ - if(glError != GL_NO_ERROR) { \ + if (glError != GL_NO_ERROR) { \ SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \ quit(1); \ } \ @@ -231,7 +231,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type) GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); /* Dump debug info (source and log) if compilation failed. */ - if(status != GL_TRUE) { + if (status != GL_TRUE) { ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]); buffer[length] = '\0'; SDL_Log("Shader compilation failed: %s", buffer); @@ -251,7 +251,7 @@ link_program(struct shader_data *data) GL_CHECK(ctx.glLinkProgram(data->shader_program)); GL_CHECK(ctx.glGetProgramiv(data->shader_program, GL_LINK_STATUS, &status)); - if(status != GL_TRUE) { + if (status != GL_TRUE) { ctx.glGetProgramInfoLog(data->shader_program, sizeof(buffer), &length, &buffer[0]); buffer[length] = '\0'; SDL_Log("Program linking failed: %s", buffer); @@ -424,12 +424,24 @@ Render(unsigned int width, unsigned int height, shader_data* data) data->angle_y += 2; data->angle_z += 1; - if(data->angle_x >= 360) data->angle_x -= 360; - if(data->angle_x < 0) data->angle_x += 360; - if(data->angle_y >= 360) data->angle_y -= 360; - if(data->angle_y < 0) data->angle_y += 360; - if(data->angle_z >= 360) data->angle_z -= 360; - if(data->angle_z < 0) data->angle_z += 360; + if (data->angle_x >= 360) { + data->angle_x -= 360; + } + if (data->angle_x < 0) { + data->angle_x += 360; + } + if (data->angle_y >= 360) { + data->angle_y -= 360; + } + if (data->angle_y < 0) { + data->angle_y += 360; + } + if (data->angle_z >= 360) { + data->angle_z -= 360; + } + if (data->angle_z < 0) { + data->angle_z += 360; + } GL_CHECK(ctx.glViewport(0, 0, width, height)); GL_CHECK(ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)); @@ -545,7 +557,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c index 42154bf5b1..e97704348b 100644 --- a/test/testgles2_sdf.c +++ b/test/testgles2_sdf.c @@ -111,7 +111,7 @@ quit(int rc) x; \ { \ GLenum glError = ctx.glGetError(); \ - if(glError != GL_NO_ERROR) { \ + if (glError != GL_NO_ERROR) { \ SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \ quit(1); \ } \ @@ -148,7 +148,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type) GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); /* Dump debug info (source and log) if compilation failed. */ - if(status != GL_TRUE) { + if (status != GL_TRUE) { ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]); buffer[length] = '\0'; SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr); @@ -351,10 +351,18 @@ void loop() } - if (sym == SDLK_LEFT) g_val -= 0.05; - if (sym == SDLK_RIGHT) g_val += 0.05; - if (sym == SDLK_UP) g_angle -= 1; - if (sym == SDLK_DOWN) g_angle += 1; + if (sym == SDLK_LEFT) { + g_val -= 0.05; + } + if (sym == SDLK_RIGHT) { + g_val += 0.05; + } + if (sym == SDLK_UP) { + g_angle -= 1; + } + if (sym == SDLK_DOWN) { + g_angle += 1; + } break; @@ -396,8 +404,7 @@ void loop() matrix_mvp[1][1] = -2.0f / 480.0; matrix_mvp[3][1] = 1.0f; - if (0) - { + if (0) { float *f = (float *) matrix_mvp; SDL_Log("-----------------------------------"); SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++); @@ -460,7 +467,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { @@ -558,8 +565,9 @@ main(int argc, char *argv[]) #if 1 path = GetNearbyFilename(f); - if (path == NULL) + if (path == NULL) { path = SDL_strdup(f); + } if (path == NULL) { SDL_Log("out of memory\n"); @@ -567,7 +575,7 @@ main(int argc, char *argv[]) } tmp = SDL_LoadBMP(path); - if (tmp == NULL) { + if (tmp == NULL) { SDL_Log("missing image file: %s", path); exit(-1); } else { diff --git a/test/testhaptic.c b/test/testhaptic.c index 6c585990e9..4b68f83035 100644 --- a/test/testhaptic.c +++ b/test/testhaptic.c @@ -78,8 +78,9 @@ main(int argc, char **argv) /* Try to find matching device */ else { for (i = 0; i < SDL_NumHaptics(); i++) { - if (SDL_strstr(SDL_HapticName(i), name) != NULL) + if (SDL_strstr(SDL_HapticName(i), name) != NULL) { break; + } } if (i >= SDL_NumHaptics()) { @@ -283,8 +284,9 @@ main(int argc, char **argv) } /* Quit */ - if (haptic != NULL) + if (haptic != NULL) { SDL_HapticClose(haptic); + } SDL_Quit(); return 0; @@ -317,40 +319,55 @@ HapticPrintSupported(SDL_Haptic * ptr) supported = SDL_HapticQuery(ptr); SDL_Log(" Supported effects [%d effects, %d playing]:\n", SDL_HapticNumEffects(ptr), SDL_HapticNumEffectsPlaying(ptr)); - if (supported & SDL_HAPTIC_CONSTANT) + if (supported & SDL_HAPTIC_CONSTANT) { SDL_Log(" constant\n"); - if (supported & SDL_HAPTIC_SINE) + } + if (supported & SDL_HAPTIC_SINE) { SDL_Log(" sine\n"); + } /* !!! FIXME: put this back when we have more bits in 2.1 */ /* if (supported & SDL_HAPTIC_SQUARE) SDL_Log(" square\n"); */ - if (supported & SDL_HAPTIC_TRIANGLE) + if (supported & SDL_HAPTIC_TRIANGLE) { SDL_Log(" triangle\n"); - if (supported & SDL_HAPTIC_SAWTOOTHUP) + } + if (supported & SDL_HAPTIC_SAWTOOTHUP) { SDL_Log(" sawtoothup\n"); - if (supported & SDL_HAPTIC_SAWTOOTHDOWN) + } + if (supported & SDL_HAPTIC_SAWTOOTHDOWN) { SDL_Log(" sawtoothdown\n"); - if (supported & SDL_HAPTIC_RAMP) + } + if (supported & SDL_HAPTIC_RAMP) { SDL_Log(" ramp\n"); - if (supported & SDL_HAPTIC_FRICTION) + } + if (supported & SDL_HAPTIC_FRICTION) { SDL_Log(" friction\n"); - if (supported & SDL_HAPTIC_SPRING) + } + if (supported & SDL_HAPTIC_SPRING) { SDL_Log(" spring\n"); - if (supported & SDL_HAPTIC_DAMPER) + } + if (supported & SDL_HAPTIC_DAMPER) { SDL_Log(" damper\n"); - if (supported & SDL_HAPTIC_INERTIA) + } + if (supported & SDL_HAPTIC_INERTIA) { SDL_Log(" inertia\n"); - if (supported & SDL_HAPTIC_CUSTOM) + } + if (supported & SDL_HAPTIC_CUSTOM) { SDL_Log(" custom\n"); - if (supported & SDL_HAPTIC_LEFTRIGHT) + } + if (supported & SDL_HAPTIC_LEFTRIGHT) { SDL_Log(" left/right\n"); + } SDL_Log(" Supported capabilities:\n"); - if (supported & SDL_HAPTIC_GAIN) + if (supported & SDL_HAPTIC_GAIN) { SDL_Log(" gain\n"); - if (supported & SDL_HAPTIC_AUTOCENTER) + } + if (supported & SDL_HAPTIC_AUTOCENTER) { SDL_Log(" autocenter\n"); - if (supported & SDL_HAPTIC_STATUS) + } + if (supported & SDL_HAPTIC_STATUS) { SDL_Log(" status\n"); + } } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testhittesting.c b/test/testhittesting.c index b4b8af3cc1..730280c55e 100644 --- a/test/testhittesting.c +++ b/test/testhittesting.c @@ -84,8 +84,7 @@ int main(int argc, char **argv) return 1; } - while (!done) - { + while (!done) { SDL_Event e; int nothing_to_do = 1; @@ -118,7 +117,7 @@ int main(int argc, char **argv) if (e.key.keysym.sym == SDLK_ESCAPE) { done = 1; } else if (e.key.keysym.sym == SDLK_x) { - if (!areas) { + if (areas == NULL) { areas = drag_areas; numareas = SDL_arraysize(drag_areas); } else { diff --git a/test/testhotplug.c b/test/testhotplug.c index b154f75721..403ba9fd64 100644 --- a/test/testhotplug.c +++ b/test/testhotplug.c @@ -33,7 +33,7 @@ main(int argc, char *argv[]) } } - if(enable_haptic) { + if (enable_haptic) { init_subsystems |= SDL_INIT_HAPTIC; } @@ -53,39 +53,31 @@ main(int argc, char *argv[]) */ SDL_Log("There are %d joysticks at startup\n", SDL_NumJoysticks()); - if (enable_haptic) + if (enable_haptic) { SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics()); + } - while(keepGoing) - { + while (keepGoing) { SDL_Event event; - while(SDL_PollEvent(&event)) - { + while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: keepGoing = SDL_FALSE; break; case SDL_JOYDEVICEADDED: - if (joystick != NULL) - { + if (joystick != NULL) { SDL_Log("Only one joystick supported by this test\n"); - } - else - { + } else { joystick = SDL_JoystickOpen(event.jdevice.which); instance = SDL_JoystickInstanceID(joystick); SDL_Log("Joy Added : %" SDL_PRIs32 " : %s\n", event.jdevice.which, SDL_JoystickName(joystick)); - if (enable_haptic) - { - if (SDL_JoystickIsHaptic(joystick)) - { + if (enable_haptic) { + if (SDL_JoystickIsHaptic(joystick)) { haptic = SDL_HapticOpenFromJoystick(joystick); - if (haptic) - { + if (haptic) { SDL_Log("Joy Haptic Opened\n"); - if (SDL_HapticRumbleInit( haptic ) != 0) - { + if (SDL_HapticRumbleInit( haptic ) != 0) { SDL_Log("Could not init Rumble!: %s\n", SDL_GetError()); SDL_HapticClose(haptic); haptic = NULL; @@ -93,21 +85,17 @@ main(int argc, char *argv[]) } else { SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError()); } - } - else - { + } else { SDL_Log("No haptic found\n"); } } } break; case SDL_JOYDEVICEREMOVED: - if (instance == event.jdevice.which) - { + if (instance == event.jdevice.which) { SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which); instance = -1; - if(enable_haptic && haptic) - { + if (enable_haptic && haptic) { SDL_HapticClose(haptic); haptic = NULL; } @@ -121,13 +109,13 @@ main(int argc, char *argv[]) /* // SDL_Log("Axis Move: %d\n", event.jaxis.axis); */ - if (enable_haptic) + if (enable_haptic) { SDL_HapticRumblePlay(haptic, 0.25, 250); + } break; case SDL_JOYBUTTONDOWN: SDL_Log("Button Press: %d\n", event.jbutton.button); - if(enable_haptic && haptic) - { + if (enable_haptic && haptic) { SDL_HapticRumblePlay(haptic, 0.25, 250); } if (event.jbutton.button == 0) { diff --git a/test/testiconv.c b/test/testiconv.c index bbf7214a86..9032556069 100644 --- a/test/testiconv.c +++ b/test/testiconv.c @@ -62,9 +62,9 @@ main(int argc, char *argv[]) fname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "utf8.txt"); file = fopen(fname, "rb"); - if (!file) { + if (file == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", fname); - return (1); + return 1; } SDL_free(fname); @@ -93,7 +93,7 @@ main(int argc, char *argv[]) fclose(file); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Total errors: %d\n", errors); - return (errors ? errors + 1 : 0); + return errors ? errors + 1 : 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testime.c b/test/testime.c index 66d887659d..f23c57622c 100644 --- a/test/testime.c +++ b/test/testime.c @@ -67,12 +67,13 @@ static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES] = {0}; static Uint8 dehex(char c) { - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { return c - '0'; - else if (c >= 'a' && c <= 'f') + } else if (c >= 'a' && c <= 'f') { return c - 'a' + 10; - else if (c >= 'A' && c <= 'F') + } else if (c >= 'A' && c <= 'F') { return c - 'A' + 10; + } return 255; } @@ -84,15 +85,16 @@ static Uint8 dehex2(char c1, char c2) static Uint8 validate_hex(const char *cp, size_t len, Uint32 *np) { Uint32 n = 0; - for (; len > 0; cp++, len--) - { + for (; len > 0; cp++, len--) { Uint8 c = dehex(*cp); - if (c == 255) + if (c == 255) { return 0; + } n = (n << 4) | c; } - if (np != NULL) + if (np != NULL) { *np = n; + } return 1; } @@ -109,8 +111,7 @@ static int unifont_init(const char *fontname) /* Allocate memory for the glyph data so the file can be closed after initialization. */ unifontGlyph = (struct UnifontGlyph *)SDL_malloc(unifontGlyphSize); - if (unifontGlyph == NULL) - { + if (unifontGlyph == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for glyph data.\n", (int)(unifontGlyphSize + 1023) / 1024); return -1; } @@ -118,8 +119,7 @@ static int unifont_init(const char *fontname) /* Allocate memory for texture pointers for all renderers. */ unifontTexture = (SDL_Texture **)SDL_malloc(unifontTextureSize); - if (unifontTexture == NULL) - { + if (unifontTexture == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for texture pointer data.\n", (int)(unifontTextureSize + 1023) / 1024); return -1; } @@ -132,8 +132,7 @@ static int unifont_init(const char *fontname) } hexFile = SDL_RWFromFile(filename, "rb"); SDL_free(filename); - if (hexFile == NULL) - { + if (hexFile == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to open font file: %s\n", fontname); return -1; } @@ -146,10 +145,10 @@ static int unifont_init(const char *fontname) Uint32 codepoint; bytesRead = SDL_RWread(hexFile, hexBuffer, 1, 9); - if (numGlyphs > 0 && bytesRead == 0) + if (numGlyphs > 0 && bytesRead == 0) { break; /* EOF */ - if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9)) - { + } + if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n"); return -1; } @@ -163,59 +162,54 @@ static int unifont_init(const char *fontname) codepointHexSize = 6; else if (hexBuffer[8] == ':') codepointHexSize = 8; - else - { + else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Could not find codepoint and glyph data separator symbol in hex file on line %d.\n", lineNumber); return -1; } - if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint)) - { + if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal number in hex file on line %d.\n", lineNumber); return -1; } - if (codepoint > UNIFONT_MAX_CODEPOINT) + if (codepoint > UNIFONT_MAX_CODEPOINT) { SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Codepoint on line %d exceeded limit of 0x%x.\n", lineNumber, UNIFONT_MAX_CODEPOINT); + } /* If there was glyph data read in the last file read, move it to the front of the buffer. */ bytesOverread = 8 - codepointHexSize; - if (codepointHexSize < 8) + if (codepointHexSize < 8) { SDL_memmove(hexBuffer, hexBuffer + codepointHexSize + 1, bytesOverread); + } bytesRead = SDL_RWread(hexFile, hexBuffer + bytesOverread, 1, 33 - bytesOverread); - if (bytesRead < (33 - bytesOverread)) - { + if (bytesRead < (33 - bytesOverread)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n"); return -1; } if (hexBuffer[32] == '\n') glyphWidth = 8; - else - { + else { glyphWidth = 16; bytesRead = SDL_RWread(hexFile, hexBuffer + 33, 1, 32); - if (bytesRead < 32) - { + if (bytesRead < 32) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n"); return -1; } } - if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL)) - { + if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal glyph data in hex file on line %d.\n", lineNumber); return -1; } - if (codepoint <= UNIFONT_MAX_CODEPOINT) - { + if (codepoint <= UNIFONT_MAX_CODEPOINT) { if (unifontGlyph[codepoint].width > 0) SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Ignoring duplicate codepoint 0x%08" SDL_PRIx32 " in hex file on line %d.\n", codepoint, lineNumber); - else - { + else { unifontGlyph[codepoint].width = glyphWidth; /* Pack the hex data into a more compact form. */ - for (i = 0; i < glyphWidth * 2; i++) + for (i = 0; i < glyphWidth * 2; i++) { unifontGlyph[codepoint].data[i] = dehex2(hexBuffer[i * 2], hexBuffer[i * 2 + 1]); + } numGlyphs++; } } @@ -233,20 +227,15 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width) int i, j; Uint8 *row = dst; - for (i = 0; i < width * 2; i++) - { + for (i = 0; i < width * 2; i++) { Uint8 data = src[i]; - for (j = 0; j < 8; j++) - { - if (data & 0x80) - { + for (j = 0; j < 8; j++) { + if (data & 0x80) { row[0] = textColor.r; row[1] = textColor.g; row[2] = textColor.b; row[3] = textColor.a; - } - else - { + } else { row[0] = 0; row[1] = 0; row[2] = 0; @@ -256,8 +245,7 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width) row += 4; } - if (width == 8 || (width == 16 && i % 2 == 1)) - { + if (width == 8 || (width == 16 && i % 2 == 1)) { dst += UNIFONT_TEXTURE_PITCH; row = dst; } @@ -269,26 +257,22 @@ static int unifont_load_texture(Uint32 textureID) int i; Uint8 * textureRGBA; - if (textureID >= UNIFONT_NUM_TEXTURES) - { + if (textureID >= UNIFONT_NUM_TEXTURES) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Tried to load out of range texture %" SDL_PRIu32 "\n", textureID); return -1; } textureRGBA = (Uint8 *)SDL_malloc(UNIFONT_TEXTURE_SIZE); - if (textureRGBA == NULL) - { + if (textureRGBA == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d MiB for a texture.\n", UNIFONT_TEXTURE_SIZE / 1024 / 1024); return -1; } SDL_memset(textureRGBA, 0, UNIFONT_TEXTURE_SIZE); /* Copy the glyphs into memory in RGBA format. */ - for (i = 0; i < UNIFONT_GLYPHS_IN_TEXTURE; i++) - { + for (i = 0; i < UNIFONT_GLYPHS_IN_TEXTURE; i++) { Uint32 codepoint = UNIFONT_GLYPHS_IN_TEXTURE * textureID + i; - if (unifontGlyph[codepoint].width > 0) - { + if (unifontGlyph[codepoint].width > 0) { const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE; const size_t offset = (cInTex / UNIFONT_GLYPHS_IN_ROW) * UNIFONT_TEXTURE_PITCH * 16 + (cInTex % UNIFONT_GLYPHS_IN_ROW) * 16 * 4; unifont_make_rgba(unifontGlyph[codepoint].data, textureRGBA + offset, unifontGlyph[codepoint].width); @@ -296,22 +280,20 @@ static int unifont_load_texture(Uint32 textureID) } /* Create textures and upload the RGBA data from above. */ - for (i = 0; i < state->num_windows; ++i) - { + for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID]; - if (state->windows[i] == NULL || renderer == NULL || tex != NULL) + if (state->windows[i] == NULL || renderer == NULL || tex != NULL) { continue; + } tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, UNIFONT_TEXTURE_WIDTH, UNIFONT_TEXTURE_WIDTH); - if (tex == NULL) - { + if (tex == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to create texture %" SDL_PRIu32 " for renderer %d.\n", textureID, i); return -1; } unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID] = tex; SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND); - if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) != 0) - { + if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) != 0) { SDL_Log("unifont error: Failed to update texture %" SDL_PRIu32 " data for renderer %d.\n", textureID, i); } } @@ -336,8 +318,7 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst } } texture = unifontTexture[UNIFONT_NUM_TEXTURES * rendererID + textureID]; - if (texture != NULL) - { + if (texture != NULL) { const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE; srcrect.x = cInTex % UNIFONT_GLYPHS_IN_ROW * 16; srcrect.y = cInTex / UNIFONT_GLYPHS_IN_ROW * 16; @@ -349,21 +330,22 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst static void unifont_cleanup() { int i, j; - for (i = 0; i < state->num_windows; ++i) - { + for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; - if (state->windows[i] == NULL || renderer == NULL) + if (state->windows[i] == NULL || renderer == NULL) { continue; - for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) - { + } + for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) { SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + j]; - if (tex != NULL) + if (tex != NULL) { SDL_DestroyTexture(tex); + } } } - for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) - unifontTextureLoaded[j] = 0; + for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) { + unifontTextureLoaded[j] = 0; + } SDL_free(unifontTexture); SDL_free(unifontGlyph); @@ -391,14 +373,15 @@ char *utf8_next(char *p) { size_t len = utf8_length(*p); size_t i = 0; - if (!len) + if (!len) { return 0; + } - for (; i < len; ++i) - { + for (; i < len; ++i) { ++p; - if (!*p) + if (!*p) { return 0; + } } return p; } @@ -406,8 +389,7 @@ char *utf8_next(char *p) char *utf8_advance(char *p, size_t distance) { size_t i = 0; - for (; i < distance && p; ++i) - { + for (; i < distance && p; ++i) { p = utf8_next(p); } return p; @@ -417,20 +399,20 @@ Uint32 utf8_decode(char *p, size_t len) { Uint32 codepoint = 0; size_t i = 0; - if (!len) + if (!len) { return 0; + } - for (; i < len; ++i) - { + for (; i < len; ++i) { if (i == 0) codepoint = (0xff >> len) & *p; - else - { + else { codepoint <<= 6; codepoint |= 0x3f & *p; } - if (!*p) + if (!*p) { return 0; + } p++; } @@ -477,8 +459,7 @@ void _Redraw(int rendererID) SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a); SDL_RenderFillRect(renderer,&textRect); - if (*text) - { + if (*text) { #ifdef HAVE_SDL_TTF SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, textColor); SDL_Texture *texture; @@ -506,8 +487,7 @@ void _Redraw(int rendererID) drawnTextRect.y = dstrect.y; drawnTextRect.h = dstrect.h; - while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) - { + while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) { Sint32 advance = unifont_draw_glyph(codepoint, rendererID, &dstrect) * UNIFONT_DRAW_SCALE; dstrect.x += advance; drawnTextRect.w += advance; @@ -518,14 +498,11 @@ void _Redraw(int rendererID) markedRect.x = textRect.x + drawnTextRect.w; markedRect.w = textRect.w - drawnTextRect.w; - if (markedRect.w < 0) - { + if (markedRect.w < 0) { /* Stop text input because we cannot hold any more characters */ SDL_StopTextInput(); return; - } - else - { + } else { SDL_StartTextInput(); } @@ -540,17 +517,16 @@ void _Redraw(int rendererID) SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a); SDL_RenderFillRect(renderer,&markedRect); - if (markedText[0]) - { + if (markedText[0]) { #ifdef HAVE_SDL_TTF SDL_Surface *textSur; SDL_Texture *texture; - if (cursor) - { + if (cursor) { char *p = utf8_advance(markedText, cursor); char c = 0; - if (!p) + if (p == NULL) { p = &markedText[SDL_strlen(markedText)]; + } c = *p; *p = 0; @@ -583,20 +559,19 @@ void _Redraw(int rendererID) drawnTextRect.y = dstrect.y; drawnTextRect.h = dstrect.h; - while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) - { + while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) { Sint32 advance = unifont_draw_glyph(codepoint, rendererID, &dstrect) * UNIFONT_DRAW_SCALE; dstrect.x += advance; drawnTextRect.w += advance; - if (i < cursor) + if (i < cursor) { cursorRect.x += advance; + } i++; utext += len; } #endif - if (cursor > 0) - { + if (cursor > 0) { cursorRect.y = drawnTextRect.y; cursorRect.h = drawnTextRect.h; } @@ -621,8 +596,9 @@ void Redraw() int i; for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); @@ -644,21 +620,19 @@ int main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;i++) { SDLTest_CommonArg(state, i); } - for (argc--, argv++; argc > 0; argc--, argv++) - { + for (argc--, argv++; argc > 0; argc--, argv++) { if (SDL_strcmp(argv[0], "--help") == 0) { usage(); return 0; } - else if (SDL_strcmp(argv[0], "--font") == 0) - { + else if (SDL_strcmp(argv[0], "--font") == 0) { argc--; argv++; @@ -681,8 +655,7 @@ int main(int argc, char *argv[]) TTF_Init(); font = TTF_OpenFont(fontname, DEFAULT_PTSIZE); - if (! font) - { + if (font == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError()); return -1; } @@ -719,42 +692,36 @@ int main(int argc, char *argv[]) break; case SDLK_BACKSPACE: /* Only delete text if not in editing mode. */ - if (!markedText[0]) - { + if (!markedText[0]) { size_t textlen = SDL_strlen(text); do { - if (textlen==0) - { + if (textlen==0) { break; } - if ((text[textlen-1] & 0x80) == 0x00) - { + if ((text[textlen-1] & 0x80) == 0x00) { /* One byte */ text[textlen-1]=0x00; break; } - if ((text[textlen-1] & 0xC0) == 0x80) - { + if ((text[textlen-1] & 0xC0) == 0x80) { /* Byte from the multibyte sequence */ text[textlen-1]=0x00; textlen--; } - if ((text[textlen-1] & 0xC0) == 0xC0) - { + if ((text[textlen-1] & 0xC0) == 0xC0) { /* First byte of multibyte sequence */ text[textlen-1]=0x00; break; } - } while(1); + } while (1); Redraw(); } break; } - if (done) - { + if (done) { break; } @@ -766,14 +733,15 @@ int main(int argc, char *argv[]) break; case SDL_TEXTINPUT: - if (event.text.text[0] == '\0' || event.text.text[0] == '\n' || - markedRect.w < 0) + if (event.text.text[0] == '\0' || event.text.text[0] == '\n' || markedRect.w < 0) { break; + } SDL_Log("Keyboard: text input \"%s\"\n", event.text.text); - if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) + if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) { SDL_strlcat(text, event.text.text, sizeof(text)); + } SDL_Log("text inputed: %s\n", text); diff --git a/test/testintersections.c b/test/testintersections.c index d1b3074a50..32f691cc71 100644 --- a/test/testintersections.c +++ b/test/testintersections.c @@ -21,7 +21,7 @@ #include -#define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while(0) +#define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while (0) #define NUM_OBJECTS 100 static SDLTest_CommonState *state; @@ -85,10 +85,12 @@ SDL_Rect lines[MAX_LINES]; static int add_line(int x1, int y1, int x2, int y2) { - if (num_lines >= MAX_LINES) + if (num_lines >= MAX_LINES) { return 0; - if ((x1 == x2) && (y1 == y2)) + } + if ((x1 == x2) && (y1 == y2)) { return 0; + } SDL_Log("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2); lines[num_lines].x = x1; @@ -129,15 +131,19 @@ SDL_Rect rects[MAX_RECTS]; static int add_rect(int x1, int y1, int x2, int y2) { - if (num_rects >= MAX_RECTS) + if (num_rects >= MAX_RECTS) { return 0; - if ((x1 == x2) || (y1 == y2)) + } + if ((x1 == x2) || (y1 == y2)) { return 0; + } - if (x1 > x2) + if (x1 > x2) { SWAP(int, x1, x2); - if (y1 > y2) + } + if (y1 > y2) { SWAP(int, y1, y2); + } SDL_Log("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, x2 - x1, y2 - y1); @@ -212,12 +218,12 @@ loop() mouse_begin_y = event.button.y; break; case SDL_MOUSEBUTTONUP: - if (event.button.button == 3) - add_line(mouse_begin_x, mouse_begin_y, event.button.x, - event.button.y); - if (event.button.button == 1) - add_rect(mouse_begin_x, mouse_begin_y, event.button.x, - event.button.y); + if (event.button.button == 3) { + add_line(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y); + } + if (event.button.button == 1) { + add_rect(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y); + } break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { @@ -243,8 +249,9 @@ loop() } for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); @@ -277,7 +284,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { diff --git a/test/testjoystick.c b/test/testjoystick.c index f3a5f9841c..dae9fce7d6 100644 --- a/test/testjoystick.c +++ b/test/testjoystick.c @@ -114,7 +114,7 @@ loop(void *arg) case SDL_JOYDEVICEADDED: SDL_Log("Joystick device %d added.\n", (int) event.jdevice.which); - if (!joystick) { + if (joystick == NULL) { joystick = SDL_JoystickOpen(event.jdevice.which); if (joystick) { PrintJoystick(joystick); @@ -140,16 +140,21 @@ loop(void *arg) case SDL_JOYHATMOTION: SDL_Log("Joystick %" SDL_PRIs32 " hat %d value:", event.jhat.which, event.jhat.hat); - if (event.jhat.value == SDL_HAT_CENTERED) + if (event.jhat.value == SDL_HAT_CENTERED) { SDL_Log(" centered"); - if (event.jhat.value & SDL_HAT_UP) + } + if (event.jhat.value & SDL_HAT_UP) { SDL_Log(" up"); - if (event.jhat.value & SDL_HAT_RIGHT) + } + if (event.jhat.value & SDL_HAT_RIGHT) { SDL_Log(" right"); - if (event.jhat.value & SDL_HAT_DOWN) + } + if (event.jhat.value & SDL_HAT_DOWN) { SDL_Log(" down"); - if (event.jhat.value & SDL_HAT_LEFT) + } + if (event.jhat.value & SDL_HAT_LEFT) { SDL_Log(" left"); + } SDL_Log("\n"); break; case SDL_JOYBALLMOTION: diff --git a/test/testkeys.c b/test/testkeys.c index 736fe9c298..e1c82b211f 100644 --- a/test/testkeys.c +++ b/test/testkeys.c @@ -33,7 +33,7 @@ main(int argc, char *argv[]) SDL_GetScancodeName(scancode)); } SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testlock.c b/test/testlock.c index 3207a64c07..b730e4c644 100644 --- a/test/testlock.c +++ b/test/testlock.c @@ -54,8 +54,9 @@ closemutex(int sig) int i; SDL_Log("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id); SDL_AtomicSet(&doterminate, 1); - for (i = 0; i < 6; ++i) + for (i = 0; i < 6; ++i) { SDL_WaitThread(threads[i], NULL); + } SDL_DestroyMutex(mutex); exit(sig); } @@ -63,8 +64,9 @@ closemutex(int sig) int SDLCALL Run(void *data) { - if (SDL_ThreadID() == mainthread) + if (SDL_ThreadID() == mainthread) { signal(SIGTERM, closemutex); + } while (!SDL_AtomicGet(&doterminate)) { SDL_Log("Process %lu ready to work\n", SDL_ThreadID()); if (SDL_LockMutex(mutex) < 0) { @@ -85,7 +87,7 @@ Run(void *data) SDL_Log("Process %lu: raising SIGTERM\n", SDL_ThreadID()); raise(SIGTERM); } - return (0); + return 0; } int @@ -117,13 +119,14 @@ main(int argc, char *argv[]) for (i = 0; i < maxproc; ++i) { char name[64]; SDL_snprintf(name, sizeof (name), "Worker%d", i); - if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL) + if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n"); + } } signal(SIGINT, terminate); Run(NULL); - return (0); /* Never reached */ + return 0; /* Never reached */ } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testmessage.c b/test/testmessage.c index 7822ea18f9..d2a6310941 100644 --- a/test/testmessage.c +++ b/test/testmessage.c @@ -163,7 +163,7 @@ main(int argc, char *argv[]) */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError()); - return (1); + return 1; } { int status = 0; @@ -171,8 +171,7 @@ main(int argc, char *argv[]) intptr_t eventNumber = SDL_RegisterEvents(1); SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber); - while (SDL_WaitEvent(&event)) - { + while (SDL_WaitEvent(&event)) { if (event.type == eventNumber) { break; } @@ -203,8 +202,7 @@ main(int argc, char *argv[]) quit(1); } - while (SDL_WaitEvent(&event)) - { + while (SDL_WaitEvent(&event)) { if (event.type == SDL_QUIT || event.type == SDL_KEYUP) { break; } @@ -212,7 +210,7 @@ main(int argc, char *argv[]) } SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testmouse.c b/test/testmouse.c index 08fbff4ca5..72e24f39ab 100644 --- a/test/testmouse.c +++ b/test/testmouse.c @@ -133,15 +133,16 @@ loop(void *arg) break; case SDL_MOUSEMOTION: - if (!active) + if (active == NULL) { break; + } active->x2 = event.motion.x; active->y2 = event.motion.y; break; case SDL_MOUSEBUTTONDOWN: - if (!active) { + if (active == NULL) { active = SDL_calloc(1, sizeof(*active)); active->x1 = active->x2 = event.button.x; active->y1 = active->y2 = event.button.y; @@ -158,8 +159,9 @@ loop(void *arg) break; case SDL_MOUSEBUTTONUP: - if (!active) + if (active == NULL) { break; + } switch (event.button.button) { case SDL_BUTTON_LEFT: buttons &= ~SDL_BUTTON_LMASK; break; @@ -210,8 +212,9 @@ loop(void *arg) /* Objects from mouse clicks */ DrawObjects(renderer); - if (active) + if (active) { DrawObject(renderer, active); + } SDL_RenderPresent(renderer); diff --git a/test/testmultiaudio.c b/test/testmultiaudio.c index 06f6b0a72b..cce960f1cf 100644 --- a/test/testmultiaudio.c +++ b/test/testmultiaudio.c @@ -39,8 +39,9 @@ play_through_once(void *arg, Uint8 * stream, int len) Uint8 *waveptr = sound + cbdata->soundpos; int waveleft = soundlen - cbdata->soundpos; int cpy = len; - if (cpy > waveleft) + if (cpy > waveleft) { cpy = waveleft; + } SDL_memcpy(stream, waveptr, cpy); len -= cpy; @@ -105,7 +106,7 @@ test_multi_audio(int devcount) while (!SDL_AtomicGet(&cbd[0].done)) { #ifdef __ANDROID__ /* Empty queue, some application events would prevent pause. */ - while (SDL_PollEvent(&event)){} + while (SDL_PollEvent(&event)) {} #endif SDL_Delay(100); } @@ -143,7 +144,7 @@ test_multi_audio(int devcount) } #ifdef __ANDROID__ /* Empty queue, some application events would prevent pause. */ - while (SDL_PollEvent(&event)){} + while (SDL_PollEvent(&event)) {} #endif SDL_Delay(100); @@ -173,7 +174,7 @@ main(int argc, char **argv) /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); diff --git a/test/testnative.c b/test/testnative.c index a7073448b4..85ba3b5340 100644 --- a/test/testnative.c +++ b/test/testnative.c @@ -117,19 +117,19 @@ main(int argc, char *argv[]) break; } } - if (!factory) { + if (factory == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n", driver); quit(2); } SDL_Log("Creating native window for %s driver\n", driver); native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H); - if (!native_window) { + if (native_window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n"); quit(3); } window = SDL_CreateWindowFrom(native_window); - if (!window) { + if (window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError()); quit(4); } @@ -137,7 +137,7 @@ main(int argc, char *argv[]) /* Create the renderer */ renderer = SDL_CreateRenderer(window, -1, 0); - if (!renderer) { + if (renderer == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); quit(5); } @@ -147,7 +147,7 @@ main(int argc, char *argv[]) SDL_RenderClear(renderer); sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, NULL, NULL); - if (!sprite) { + if (sprite == NULL) { quit(6); } @@ -156,7 +156,7 @@ main(int argc, char *argv[]) SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h); positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect)); - if (!positions || !velocities) { + if (positions == NULL || velocities == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } diff --git a/test/testoffscreen.c b/test/testoffscreen.c index 93192106d2..ba11c86c17 100644 --- a/test/testoffscreen.c +++ b/test/testoffscreen.c @@ -117,7 +117,7 @@ main(int argc, char *argv[]) SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); - if (!window) { + if (window == NULL) { SDL_Log("Couldn't create window: %s\n", SDL_GetError()); return SDL_FALSE; @@ -125,7 +125,7 @@ main(int argc, char *argv[]) renderer = SDL_CreateRenderer(window, -1, 0); - if (!renderer) { + if (renderer == NULL) { SDL_Log("Couldn't create renderer: %s\n", SDL_GetError()); return SDL_FALSE; diff --git a/test/testoverlay2.c b/test/testoverlay2.c index c655248b09..6cc5f8f6fe 100644 --- a/test/testoverlay2.c +++ b/test/testoverlay2.c @@ -342,21 +342,21 @@ main(int argc, char **argv) SDL_WINDOWPOS_UNDEFINED, window_w, window_h, SDL_WINDOW_RESIZABLE); - if (!window) { + if (window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError()); SDL_free(RawMooseData); quit(4); } renderer = SDL_CreateRenderer(window, -1, 0); - if (!renderer) { + if (renderer == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError()); SDL_free(RawMooseData); quit(4); } MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H); - if (!MooseTexture) { + if (MooseTexture == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError()); SDL_free(RawMooseData); quit(5); diff --git a/test/testplatform.c b/test/testplatform.c index 1ef2b85fed..67cb442a84 100644 --- a/test/testplatform.c +++ b/test/testplatform.c @@ -48,33 +48,34 @@ TestTypes(SDL_bool verbose) int error = 0; if (badsize(sizeof(Uint8), 1)) { - if (verbose) - SDL_Log("sizeof(Uint8) != 1, instead = %u\n", - (unsigned int)sizeof(Uint8)); + if (verbose) { + SDL_Log("sizeof(Uint8) != 1, instead = %u\n", (unsigned int)sizeof(Uint8)); + } ++error; } if (badsize(sizeof(Uint16), 2)) { - if (verbose) - SDL_Log("sizeof(Uint16) != 2, instead = %u\n", - (unsigned int)sizeof(Uint16)); + if (verbose) { + SDL_Log("sizeof(Uint16) != 2, instead = %u\n", (unsigned int)sizeof(Uint16)); + } ++error; } if (badsize(sizeof(Uint32), 4)) { - if (verbose) - SDL_Log("sizeof(Uint32) != 4, instead = %u\n", - (unsigned int)sizeof(Uint32)); + if (verbose) { + SDL_Log("sizeof(Uint32) != 4, instead = %u\n", (unsigned int)sizeof(Uint32)); + } ++error; } if (badsize(sizeof(Uint64), 8)) { - if (verbose) - SDL_Log("sizeof(Uint64) != 8, instead = %u\n", - (unsigned int)sizeof(Uint64)); + if (verbose) { + SDL_Log("sizeof(Uint64) != 8, instead = %u\n", (unsigned int)sizeof(Uint64)); + } ++error; } - if (verbose && !error) + if (verbose && !error) { SDL_Log("All data types are the expected size.\n"); + } - return (error ? 1 : 0); + return error ? 1 : 0; } int @@ -166,7 +167,7 @@ TestEndian(SDL_bool verbose) } ++error; } - return (error ? 1 : 0); + return error ? 1 : 0; } static int TST_allmul (void *a, void *b, int arg, void *result, void *expected) @@ -373,15 +374,17 @@ Test64Bit (SDL_bool verbose) unsigned int *rl = (unsigned int *)&result; if (!t->routine(&t->a, &t->b, t->arg, &result, &t->expected_result)) { - if (verbose) - SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n", - t->operation, al[1], al[0], bl[1], bl[0], t->arg, rl[1], rl[0], el[1], el[0]); + if (verbose) { + SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n", t->operation, al[1], al[0], bl[1], bl[0], + t->arg, rl[1], rl[0], el[1], el[0]); + } ++failed; } } - if (verbose && (failed == 0)) + if (verbose && (failed == 0)) { SDL_Log("All 64bit instrinsic tests passed\n"); - return (failed ? 1 : 0); + } + return failed ? 1 : 0; } int @@ -408,7 +411,7 @@ TestCPUInfo(SDL_bool verbose) SDL_Log("LASX %s\n", SDL_HasLASX()? "detected" : "not detected"); SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM()); } - return (0); + return 0; } int @@ -437,7 +440,7 @@ TestAssertions(SDL_bool verbose) item = item->next; } } - return (0); + return 0; } int diff --git a/test/testqsort.c b/test/testqsort.c index fafbf86793..c35e4494c7 100644 --- a/test/testqsort.c +++ b/test/testqsort.c @@ -49,8 +49,7 @@ main(int argc, char *argv[]) int iteration; SDLTest_RandomContext rndctx; - if (argc > 1) - { + if (argc > 1) { int success; Uint64 seed = 0; if (argv[1][0] == '0' && argv[1][1] == 'x') @@ -66,9 +65,7 @@ main(int argc, char *argv[]) return 1; } SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff)); - } - else - { + } else { SDLTest_RandomInitTime(&rndctx); } SDL_Log("Using random seed 0x%08x%08x\n", rndctx.x, rndctx.c); diff --git a/test/testrelative.c b/test/testrelative.c index 13fb04f29f..859f428856 100644 --- a/test/testrelative.c +++ b/test/testrelative.c @@ -34,7 +34,7 @@ DrawRects(SDL_Renderer * renderer) } static void -loop(){ +loop() { /* Check for events */ while (SDL_PollEvent(&event)) { SDLTest_CommonEvent(state, &event, &done); @@ -50,17 +50,26 @@ loop(){ for (i = 0; i < state->num_windows; ++i) { SDL_Rect viewport; SDL_Renderer *renderer = state->renderers[i]; - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); SDL_RenderClear(renderer); /* Wrap the cursor rectangle at the screen edges to keep it visible */ SDL_RenderGetViewport(renderer, &viewport); - if (rect.x < viewport.x) rect.x += viewport.w; - if (rect.y < viewport.y) rect.y += viewport.h; - if (rect.x > viewport.x + viewport.w) rect.x -= viewport.w; - if (rect.y > viewport.y + viewport.h) rect.y -= viewport.h; + if (rect.x < viewport.x) { + rect.x += viewport.w; + } + if (rect.y < viewport.y) { + rect.y += viewport.h; + } + if (rect.x > viewport.x + viewport.w) { + rect.x -= viewport.w; + } + if (rect.y > viewport.y + viewport.h) { + rect.y -= viewport.h; + } DrawRects(renderer); @@ -82,7 +91,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc; ++i) { @@ -101,7 +110,7 @@ main(int argc, char *argv[]) } srand((unsigned int)time(NULL)); - if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) { + if (SDL_SetRelativeMouseMode(SDL_TRUE) < 0) { return 3; } diff --git a/test/testrendercopyex.c b/test/testrendercopyex.c index 750accbae8..e09a3029e8 100644 --- a/test/testrendercopyex.c +++ b/test/testrendercopyex.c @@ -96,8 +96,9 @@ void loop() SDLTest_CommonEvent(state, &event, &done); } for (i = 0; i < state->num_windows; ++i) { - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } Draw(&drawstates[i]); } #ifdef __EMSCRIPTEN__ @@ -119,7 +120,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } diff --git a/test/testrendertarget.c b/test/testrendertarget.c index 53f3eee1da..479e0d9b88 100644 --- a/test/testrendertarget.c +++ b/test/testrendertarget.c @@ -135,7 +135,7 @@ Draw(DrawState *s) SDL_RenderGetViewport(s->renderer, &viewport); target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h); - if (!target) { + if (target == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create render target texture: %s\n", SDL_GetError()); return SDL_FALSE; } @@ -181,12 +181,17 @@ loop() SDLTest_CommonEvent(state, &event, &done); } for (i = 0; i < state->num_windows; ++i) { - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } if (test_composite) { - if (!DrawComposite(&drawstates[i])) done = 1; + if (!DrawComposite(&drawstates[i])) { + done = 1; + } } else { - if (!Draw(&drawstates[i])) done = 1; + if (!Draw(&drawstates[i])) { + done = 1; + } } } #ifdef __EMSCRIPTEN__ @@ -208,7 +213,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } for (i = 1; i < argc;) { diff --git a/test/testrumble.c b/test/testrumble.c index c20a34dba6..ead33b1f5d 100644 --- a/test/testrumble.c +++ b/test/testrumble.c @@ -78,8 +78,9 @@ main(int argc, char **argv) /* Try to find matching device */ else { for (i = 0; i < SDL_NumHaptics(); i++) { - if (SDL_strstr(SDL_HapticName(i), name) != NULL) + if (SDL_strstr(SDL_HapticName(i), name) != NULL) { break; + } } if (i >= SDL_NumHaptics()) { @@ -129,8 +130,9 @@ main(int argc, char **argv) SDL_Delay(2000); /* Quit */ - if (haptic != NULL) + if (haptic != NULL) { SDL_HapticClose(haptic); + } SDL_Quit(); return 0; diff --git a/test/testscale.c b/test/testscale.c index 39a633f2c5..510d81524b 100644 --- a/test/testscale.c +++ b/test/testscale.c @@ -87,8 +87,9 @@ loop() SDLTest_CommonEvent(state, &event, &done); } for (i = 0; i < state->num_windows; ++i) { - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } Draw(&drawstates[i]); } #ifdef __EMSCRIPTEN__ @@ -110,7 +111,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } diff --git a/test/testsem.c b/test/testsem.c index 1e444ced52..978ad5ae24 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -115,8 +115,9 @@ TestWaitTimeout(void) SDL_Log("Wait took %" SDL_PRIu32 " milliseconds\n\n", duration); /* Check to make sure the return value indicates timed out */ - if (retval != SDL_MUTEX_TIMEDOUT) + if (retval != SDL_MUTEX_TIMEDOUT) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n\n", retval, SDL_MUTEX_TIMEDOUT); + } SDL_DestroySemaphore(sem); } @@ -133,7 +134,7 @@ TestOverheadUncontended(void) SDL_Log("Doing %d uncontended Post/Wait operations on semaphore\n", NUM_OVERHEAD_OPS * NUM_OVERHEAD_OPS_MULT); start_ticks = SDL_GetTicks(); - for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++){ + for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++) { for (j = 0; j < NUM_OVERHEAD_OPS; j++) { SDL_SemPost(sem); } @@ -155,14 +156,14 @@ ThreadFuncOverheadContended(void *data) Thread_State *state = (Thread_State *) data; if (state->flag) { - while(alive) { + while (alive) { if (SDL_SemTryWait(sem) == SDL_MUTEX_TIMEDOUT) { ++state->content_count; } ++state->loop_count; } } else { - while(alive) { + while (alive) { /* Timeout needed to allow check on alive flag */ if (SDL_SemWaitTimeout(sem, 50) == SDL_MUTEX_TIMEDOUT) { ++state->content_count; @@ -249,13 +250,13 @@ main(int argc, char **argv) if (argc < 2) { SDL_Log("Usage: %s init_value\n", argv[0]); - return (1); + return 1; } /* Load the SDL library */ if (SDL_Init(0) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } signal(SIGTERM, killed); signal(SIGINT, killed); @@ -274,7 +275,7 @@ main(int argc, char **argv) TestOverheadContended(SDL_TRUE); SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testsensor.c b/test/testsensor.c index 3f150b1567..f77eec86a5 100644 --- a/test/testsensor.c +++ b/test/testsensor.c @@ -37,7 +37,7 @@ static const char *GetSensorTypeString(SDL_SensorType type) static void HandleSensorEvent(SDL_SensorEvent *event) { SDL_Sensor *sensor = SDL_SensorFromInstanceID(event->which); - if (!sensor) { + if (sensor == NULL) { SDL_Log("Couldn't get sensor for sensor event\n"); return; } @@ -64,7 +64,7 @@ main(int argc, char **argv) /* Load the SDL library */ if (SDL_Init(SDL_INIT_SENSOR) < 0) { SDL_Log("Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } num_sensors = SDL_NumSensors(); @@ -117,7 +117,7 @@ main(int argc, char **argv) } SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testshader.c b/test/testshader.c index 15df2f9750..b4ecb8e3c3 100644 --- a/test/testshader.c +++ b/test/testshader.c @@ -139,7 +139,7 @@ static SDL_bool CompileShader(GLhandleARB shader, const char *source) glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); info = (char *) SDL_malloc(length + 1); - if (!info) { + if (info == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!"); } else { glGetInfoLogARB(shader, length, NULL, info); @@ -167,7 +167,7 @@ static SDL_bool LinkProgram(ShaderData *data) glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); info = (char *) SDL_malloc(length + 1); - if (!info) { + if (info == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!"); } else { glGetInfoLogARB(data->program, length, NULL, info); @@ -465,7 +465,7 @@ int main(int argc, char **argv) /* Create a 640x480 OpenGL screen */ window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL ); - if ( !window ) { + if (window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError()); SDL_Quit(); exit(2); @@ -478,7 +478,7 @@ int main(int argc, char **argv) } surface = SDL_LoadBMP("icon.bmp"); - if ( ! surface ) { + if (surface == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError()); SDL_Quit(); exit(3); diff --git a/test/testshape.c b/test/testshape.c index 4ac6ff2602..4778cf5814 100644 --- a/test/testshape.c +++ b/test/testshape.c @@ -56,30 +56,32 @@ int main(int argc,char** argv) /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); - if(argc < 2) { + if (argc < 2) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Shape requires at least one bitmap file as argument."); exit(-1); } - if(SDL_VideoInit(NULL) == -1) { + if (SDL_VideoInit(NULL) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL video."); exit(-2); } num_pictures = argc - 1; pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture)*num_pictures); - if (!pictures) { + if (pictures == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate memory."); exit(1); } - for(i=0;iformat; - if(SDL_ISPIXELFORMAT_ALPHA(format->format)) { + if (SDL_ISPIXELFORMAT_ALPHA(format->format)) { pictures[i].mode.mode = ShapeModeBinarizeAlpha; pictures[i].mode.parameters.binarizationCutoff = 255; - } - else { + } else { pictures[i].mode.mode = ShapeModeColorKey; pictures[i].mode.parameters.colorKey = black; } @@ -102,35 +103,41 @@ int main(int argc,char** argv) SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION, 0); SDL_SetWindowPosition(window, SHAPED_WINDOW_X, SHAPED_WINDOW_Y); - if(window == NULL) { - for(i=0;i= num_pictures) + if (current_picture >= num_pictures) { current_picture = 0; + } SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name); SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h); SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); @@ -180,14 +188,16 @@ int main(int argc,char** argv) } /* Free the textures. */ - for(i=0;irenderers[i], file, SDL_TRUE, &sprite_w, &sprite_h); if (!sprites[i]) { - return (-1); + return -1; } if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError()); SDL_DestroyTexture(sprites[i]); - return (-1); + return -1; } } /* We're ready to roll. :) */ - return (0); + return 0; } void @@ -406,8 +406,9 @@ loop() SDLTest_CommonEvent(state, &event, &done); } for (i = 0; i < state->num_windows; ++i) { - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } MoveSprites(state->renderers[i], sprites[i]); } #ifdef __EMSCRIPTEN__ @@ -441,7 +442,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } @@ -473,7 +474,9 @@ main(int argc, char *argv[]) } else if (SDL_strcasecmp(argv[i], "--iterations") == 0) { if (argv[i + 1]) { iterations = SDL_atoi(argv[i + 1]); - if (iterations < -1) iterations = -1; + if (iterations < -1) { + iterations = -1; + } consumed = 2; } } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { @@ -526,7 +529,7 @@ main(int argc, char *argv[]) /* Create the windows, initialize the renderers, and load the textures */ sprites = (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites)); - if (!sprites) { + if (sprites == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } @@ -542,7 +545,7 @@ main(int argc, char *argv[]) /* Allocate memory for the sprite info */ positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); - if (!positions || !velocities) { + if (positions == NULL || velocities == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); quit(2); } diff --git a/test/teststreaming.c b/test/teststreaming.c index ddec10b906..9e44d75d66 100644 --- a/test/teststreaming.c +++ b/test/teststreaming.c @@ -160,19 +160,19 @@ main(int argc, char **argv) SDL_WINDOWPOS_UNDEFINED, MOOSEPIC_W*4, MOOSEPIC_H*4, SDL_WINDOW_RESIZABLE); - if (!window) { + if (window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError()); quit(3); } renderer = SDL_CreateRenderer(window, -1, 0); - if (!renderer) { + if (renderer == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError()); quit(4); } MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H); - if (!MooseTexture) { + if (MooseTexture == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError()); quit(5); } diff --git a/test/testthread.c b/test/testthread.c index 287122d785..62ddaaba0e 100644 --- a/test/testthread.c +++ b/test/testthread.c @@ -56,14 +56,15 @@ ThreadFunc(void *data) if (testprio) { SDL_Log("SDL_SetThreadPriority(%s):%d\n", getprioritystr(prio), SDL_SetThreadPriority(prio)); - if (++prio > SDL_THREAD_PRIORITY_TIME_CRITICAL) + if (++prio > SDL_THREAD_PRIORITY_TIME_CRITICAL) { prio = SDL_THREAD_PRIORITY_LOW; + } } SDL_Delay(1 * 1000); } SDL_Log("Thread '%s' exiting!\n", (char *) data); - return (0); + return 0; } static void @@ -87,7 +88,7 @@ main(int argc, char *argv[]) /* Load the SDL library */ if (SDL_Init(0) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } if (SDL_getenv("SDL_TESTS_QUICK") != NULL) { @@ -131,7 +132,7 @@ main(int argc, char *argv[]) raise(SIGTERM); SDL_Quit(); /* Never reached */ - return (0); /* Never reached */ + return 0; /* Never reached */ } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testtimer.c b/test/testtimer.c index 72392bed6a..8063f0cfec 100644 --- a/test/testtimer.c +++ b/test/testtimer.c @@ -23,7 +23,7 @@ static Uint32 SDLCALL ticktock(Uint32 interval, void *param) { ++ticks; - return (interval); + return interval; } static Uint32 SDLCALL @@ -47,7 +47,7 @@ main(int argc, char *argv[]) if (SDL_Init(SDL_INIT_TIMER) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } if (SDL_getenv("SDL_TESTS_QUICK") != NULL) { @@ -97,14 +97,17 @@ main(int argc, char *argv[]) /* Test multiple timers */ SDL_Log("Testing multiple timers...\n"); t1 = SDL_AddTimer(100, callback, (void *) 1); - if (!t1) - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 1: %s\n", SDL_GetError()); + if (!t1) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 1: %s\n", SDL_GetError()); + } t2 = SDL_AddTimer(50, callback, (void *) 2); - if (!t2) - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 2: %s\n", SDL_GetError()); + if (!t2) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 2: %s\n", SDL_GetError()); + } t3 = SDL_AddTimer(233, callback, (void *) 3); - if (!t3) - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 3: %s\n", SDL_GetError()); + if (!t3) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 3: %s\n", SDL_GetError()); + } /* Wait 10 seconds */ SDL_Log("Waiting 10 seconds\n"); @@ -136,7 +139,7 @@ main(int argc, char *argv[]) SDL_Log("Delay 1 second = %d ms in ticks, %d ms in ticks64, %f ms according to performance counter\n", (int) (now32-start32), (int) (now64-start64), (double)((now - start)*1000) / SDL_GetPerformanceFrequency()); SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testutils.c b/test/testutils.c index f64055ec39..21ceee275c 100644 --- a/test/testutils.c +++ b/test/testutils.c @@ -139,7 +139,7 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent, } texture = SDL_CreateTextureFromSurface(renderer, temp); - if (!texture) { + if (texture == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError()); } } diff --git a/test/testver.c b/test/testver.c index f1881ba1c5..4936576eb3 100644 --- a/test/testver.c +++ b/test/testver.c @@ -38,7 +38,7 @@ main(int argc, char *argv[]) linked.major, linked.minor, linked.patch, SDL_GetRevision()); SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testviewport.c b/test/testviewport.c index b27509cd22..ec07848644 100644 --- a/test/testviewport.c +++ b/test/testviewport.c @@ -101,8 +101,9 @@ loop() int i; #ifdef __EMSCRIPTEN__ /* Avoid using delays */ - if(SDL_GetTicks() - wait_start < 1000) + if (SDL_GetTicks() - wait_start < 1000) { return; + } wait_start = SDL_GetTicks(); #endif /* Check for events */ @@ -119,8 +120,9 @@ loop() SDL_Log("Current Viewport x=%i y=%i w=%i h=%i", viewport.x, viewport.y, viewport.w, viewport.h); for (i = 0; i < state->num_windows; ++i) { - if (state->windows[i] == NULL) + if (state->windows[i] == NULL) { continue; + } /* Draw using viewport */ DrawOnViewport(state->renderers[i]); @@ -151,7 +153,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } diff --git a/test/testvulkan.c b/test/testvulkan.c index 8074ae8401..d23f77d703 100644 --- a/test/testvulkan.c +++ b/test/testvulkan.c @@ -230,7 +230,7 @@ static void createInstance(void) quit(2); } extensions = (const char **) SDL_malloc(sizeof(const char *) * extensionCount); - if (!extensions) { + if (extensions == NULL) { SDL_OutOfMemory(); quit(2); } @@ -306,7 +306,7 @@ static void findPhysicalDevice(void) quit(2); } physicalDevices = (VkPhysicalDevice *) SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount); - if (!physicalDevices) { + if (physicalDevices == NULL) { SDL_OutOfMemory(); quit(2); } @@ -328,7 +328,7 @@ static void findPhysicalDevice(void) VkPhysicalDevice physicalDevice = physicalDevices[physicalDeviceIndex]; vkGetPhysicalDeviceProperties(physicalDevice, &vulkanContext->physicalDeviceProperties); - if(VK_VERSION_MAJOR(vulkanContext->physicalDeviceProperties.apiVersion) < 1) { + if (VK_VERSION_MAJOR(vulkanContext->physicalDeviceProperties.apiVersion) < 1) { continue; } vkGetPhysicalDeviceFeatures(physicalDevice, &vulkanContext->physicalDeviceFeatures); @@ -340,7 +340,7 @@ static void findPhysicalDevice(void) SDL_free(queueFamiliesProperties); queueFamiliesPropertiesAllocatedSize = queueFamiliesCount; queueFamiliesProperties = (VkQueueFamilyProperties *) SDL_malloc(sizeof(VkQueueFamilyProperties) * queueFamiliesPropertiesAllocatedSize); - if (!queueFamiliesProperties) { + if (queueFamiliesProperties == NULL) { SDL_free(physicalDevices); SDL_free(deviceExtensions); SDL_OutOfMemory(); @@ -386,8 +386,7 @@ static void findPhysicalDevice(void) continue; } result = vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &deviceExtensionCount, NULL); - if (result != VK_SUCCESS) - { + if (result != VK_SUCCESS) { SDL_free(physicalDevices); SDL_free(queueFamiliesProperties); SDL_free(deviceExtensions); @@ -403,7 +402,7 @@ static void findPhysicalDevice(void) SDL_free(deviceExtensions); deviceExtensionsAllocatedSize = deviceExtensionCount; deviceExtensions = SDL_malloc(sizeof(VkExtensionProperties) * deviceExtensionsAllocatedSize); - if (!deviceExtensions) { + if (deviceExtensions == NULL) { SDL_free(physicalDevices); SDL_free(queueFamiliesProperties); SDL_OutOfMemory(); @@ -421,7 +420,7 @@ static void findPhysicalDevice(void) quit(2); } for (i = 0; i < deviceExtensionCount; i++) { - if(SDL_strcmp(deviceExtensions[i].extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) { + if (SDL_strcmp(deviceExtensions[i].extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) { hasSwapchainExtension = SDL_TRUE; break; } @@ -638,7 +637,7 @@ static SDL_bool createSwapchain(void) } else { vulkanContext->surfaceFormat = vulkanContext->surfaceFormats[0]; for (i = 0; i < vulkanContext->surfaceFormatsCount; i++) { - if(vulkanContext->surfaceFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM) { + if (vulkanContext->surfaceFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM) { vulkanContext->surfaceFormat = vulkanContext->surfaceFormats[i]; break; } @@ -684,7 +683,7 @@ static SDL_bool createSwapchain(void) vkDestroySwapchainKHR(vulkanContext->device, createInfo.oldSwapchain, NULL); } - if(result != VK_SUCCESS) { + if (result != VK_SUCCESS) { vulkanContext->swapchain = VK_NULL_HANDLE; SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkCreateSwapchainKHR(): %s\n", @@ -753,7 +752,7 @@ static void createCommandBuffers(void) allocateInfo.commandBufferCount = vulkanContext->swapchainImageCount; vulkanContext->commandBuffers = (VkCommandBuffer *) SDL_malloc(sizeof(VkCommandBuffer) * vulkanContext->swapchainImageCount); result = vkAllocateCommandBuffers(vulkanContext->device, &allocateInfo, vulkanContext->commandBuffers); - if(result != VK_SUCCESS) { + if (result != VK_SUCCESS) { SDL_free(vulkanContext->commandBuffers); vulkanContext->commandBuffers = NULL; SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, @@ -778,8 +777,8 @@ static void createFences(void) createInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; createInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; result = vkCreateFence(vulkanContext->device, &createInfo, NULL, &vulkanContext->fences[i]); - if(result != VK_SUCCESS) { - for(; i > 0; i--) { + if (result != VK_SUCCESS) { + for (; i > 0; i--) { vkDestroyFence(vulkanContext->device, vulkanContext->fences[i - 1], NULL); } SDL_free(vulkanContext->fences); @@ -848,7 +847,7 @@ static void rerecordCommandBuffer(uint32_t frameIndex, const VkClearColorValue * VkImageSubresourceRange clearRange = {0}; VkResult result = vkResetCommandBuffer(commandBuffer, 0); - if(result != VK_SUCCESS) { + if (result != VK_SUCCESS) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkResetCommandBuffer(): %s\n", getVulkanResultString(result)); @@ -906,7 +905,7 @@ static SDL_bool createNewSwapchainAndSwapchainSpecificStuff(void) destroySwapchainAndSwapchainSpecificStuff(SDL_FALSE); getSurfaceCaps(); getSurfaceFormats(); - if(!createSwapchain()) { + if (!createSwapchain()) { return SDL_FALSE; } createCommandPool(); @@ -922,7 +921,7 @@ static void initVulkan(void) SDL_Vulkan_LoadLibrary(NULL); vulkanContexts = (VulkanContext *) SDL_calloc(state->num_windows, sizeof (VulkanContext)); - if (!vulkanContexts) { + if (vulkanContexts == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!"); quit(2); } @@ -997,8 +996,9 @@ static SDL_bool render(void) if (!vulkanContext->swapchain) { SDL_bool retval = createNewSwapchainAndSwapchainSpecificStuff(); - if(!retval) + if (!retval) { SDL_Delay(100); + } return retval; } result = vkAcquireNextImageKHR(vulkanContext->device, @@ -1065,7 +1065,7 @@ static SDL_bool render(void) quit(2); } SDL_Vulkan_GetDrawableSize(vulkanContext->window, &w, &h); - if(w != (int)vulkanContext->swapchainSize.width || h != (int)vulkanContext->swapchainSize.height) { + if (w != (int)vulkanContext->swapchainSize.width || h != (int)vulkanContext->swapchainSize.height) { return createNewSwapchainAndSwapchainSpecificStuff(); } return SDL_TRUE; @@ -1084,7 +1084,7 @@ int main(int argc, char **argv) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if(!state) { + if (state == NULL) { return 1; } @@ -1114,7 +1114,7 @@ int main(int argc, char **argv) while (!done) { /* Check for events */ frames++; - while(SDL_PollEvent(&event)) { + while (SDL_PollEvent(&event)) { /* Need to destroy the swapchain before the window created * by SDL. */ diff --git a/test/testwm2.c b/test/testwm2.c index 693a3d30e6..d790f148ff 100644 --- a/test/testwm2.c +++ b/test/testwm2.c @@ -263,7 +263,7 @@ main(int argc, char *argv[]) /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); - if (!state) { + if (state == NULL) { return 1; } @@ -294,7 +294,7 @@ main(int argc, char *argv[]) quit(0); /* keep the compiler happy ... */ - return(0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testyuv.c b/test/testyuv.c index b82c0b5d72..1b8df2c854 100644 --- a/test/testyuv.c +++ b/test/testyuv.c @@ -21,9 +21,7 @@ /* Return true if the YUV format is packed pixels */ static SDL_bool is_packed_yuv_format(Uint32 format) { - return (format == SDL_PIXELFORMAT_YUY2 || - format == SDL_PIXELFORMAT_UYVY || - format == SDL_PIXELFORMAT_YVYU); + return format == SDL_PIXELFORMAT_YUY2 || format == SDL_PIXELFORMAT_UYVY || format == SDL_PIXELFORMAT_YVYU; } /* Create a surface with a good pattern for verifying YUV conversion */ @@ -75,7 +73,7 @@ static SDL_bool verify_yuv_data(Uint32 format, const Uint8 *yuv, int yuv_pitch, SDL_bool result = SDL_FALSE; rgb = (Uint8 *)SDL_malloc(size); - if (!rgb) { + if (rgb == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory"); return SDL_FALSE; } @@ -126,7 +124,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch) int yuv1_pitch, yuv2_pitch; int result = -1; - if (!pattern || !yuv1 || !yuv2) { + if (pattern == NULL || yuv1 == NULL || yuv2 == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't allocate test surfaces"); goto done; } @@ -328,7 +326,7 @@ main(int argc, char **argv) filename = "testyuv.bmp"; } original = SDL_ConvertSurfaceFormat(SDL_LoadBMP(filename), SDL_PIXELFORMAT_RGB24, 0); - if (!original) { + if (original == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); return 3; } @@ -340,7 +338,7 @@ main(int argc, char **argv) pitch = CalculateYUVPitch(yuv_format, original->w); converted = SDL_CreateRGBSurfaceWithFormat(0, original->w, original->h, 0, rgb_format); - if (!converted) { + if (converted == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create converted surface: %s\n", SDL_GetError()); return 3; } @@ -357,13 +355,13 @@ main(int argc, char **argv) SDL_WINDOWPOS_UNDEFINED, original->w, original->h, 0); - if (!window) { + if (window == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError()); return 4; } renderer = SDL_CreateRenderer(window, -1, 0); - if (!renderer) { + if (renderer == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); return 4; } @@ -398,8 +396,7 @@ main(int argc, char **argv) } { int done = 0; - while ( !done ) - { + while ( !done ) { SDL_Event event; while (SDL_PollEvent(&event) > 0) { if (event.type == SDL_QUIT) { diff --git a/test/testyuv_cvt.c b/test/testyuv_cvt.c index 2e9853043d..a5e2730b44 100644 --- a/test/testyuv_cvt.c +++ b/test/testyuv_cvt.c @@ -17,7 +17,7 @@ static float clip3(float x, float y, float z) { - return ((z < x) ? x : ((z > y) ? y : z)); + return (z < x) ? x : ((z > y) ? y : z); } static void RGBtoYUV(Uint8 * rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance) @@ -68,8 +68,9 @@ static void RGBtoYUV(Uint8 * rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int mo if (luminance != 100) { yuv[0] = yuv[0] * luminance / 100; - if (yuv[0] > 255) + if (yuv[0] > 255) { yuv[0] = 255; + } } } @@ -291,7 +292,7 @@ int CalculateYUVPitch(Uint32 format, int width) case SDL_PIXELFORMAT_YUY2: case SDL_PIXELFORMAT_UYVY: case SDL_PIXELFORMAT_YVYU: - return 4*((width + 1)/2); + return 4 * ((width + 1) / 2); default: return 0; } diff --git a/test/torturethread.c b/test/torturethread.c index 19574012a8..86f0c89ef7 100644 --- a/test/torturethread.c +++ b/test/torturethread.c @@ -83,7 +83,7 @@ main(int argc, char *argv[]) /* Load the SDL library */ if (SDL_Init(0) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); - return (1); + return 1; } signal(SIGSEGV, SIG_DFL); @@ -107,7 +107,7 @@ main(int argc, char *argv[]) SDL_WaitThread(threads[i], NULL); } SDL_Quit(); - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */