Skip to content

Commit

Permalink
Pointer as boolean, 2nd part:
Browse files Browse the repository at this point in the history
automatic and manual changes for SDL2
  • Loading branch information
1bsyl committed Nov 10, 2023
1 parent 1f01efb commit bd94f95
Show file tree
Hide file tree
Showing 213 changed files with 957 additions and 955 deletions.
10 changes: 5 additions & 5 deletions Xcode-iOS/Demos/src/accelerometer.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ initializeTextures(SDL_Renderer *renderer)

/* load the ship */
bmp_surface = SDL_LoadBMP("ship.bmp");
if (bmp_surface == NULL) {
if (!bmp_surface) {
fatalError("could not ship.bmp");
}
/* set blue to transparent on the ship */
Expand All @@ -127,7 +127,7 @@ initializeTextures(SDL_Renderer *renderer)

/* create ship texture from surface */
ship = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (ship == NULL) {
if (!ship) {
fatalError("could not create ship texture");
}
SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND);
Expand All @@ -140,12 +140,12 @@ initializeTextures(SDL_Renderer *renderer)

/* load the space background */
bmp_surface = SDL_LoadBMP("space.bmp");
if (bmp_surface == NULL) {
if (!bmp_surface) {
fatalError("could not load space.bmp");
}
/* create space texture from surface */
space = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (space == NULL) {
if (!space) {
fatalError("could not create space texture");
}
SDL_FreeSurface(bmp_surface);
Expand Down Expand Up @@ -179,7 +179,7 @@ main(int argc, char *argv[])
printf("There are %d joysticks available\n", SDL_NumJoysticks());
printf("Default joystick (index 0) is %s\n", SDL_JoystickName(0));
accelerometer = SDL_JoystickOpen(0);
if (accelerometer == NULL) {
if (!accelerometer) {
fatalError("Could not open joystick (accelerometer)");
}
printf("joystick number of axis = %d\n",
Expand Down
2 changes: 1 addition & 1 deletion Xcode-iOS/Demos/src/fireworks.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ initializeTexture()
to format passed into OpenGL */

bmp_surface = SDL_LoadBMP("stroke.bmp");
if (bmp_surface == NULL) {
if (!bmp_surface) {
fatalError("could not load stroke.bmp");
}

Expand Down
4 changes: 2 additions & 2 deletions Xcode-iOS/Demos/src/happy.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ initializeTexture(SDL_Renderer *renderer)
SDL_Surface *bmp_surface;
/* load the bmp */
bmp_surface = SDL_LoadBMP("icon.bmp");
if (bmp_surface == NULL) {
if (!bmp_surface) {
fatalError("could not load bmp");
}
/* set white to transparent on the happyface */
Expand All @@ -117,7 +117,7 @@ initializeTexture(SDL_Renderer *renderer)

/* convert RGBA surface to texture */
texture = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (texture == NULL) {
if (!texture) {
fatalError("could not create texture");
}
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
Expand Down
4 changes: 2 additions & 2 deletions Xcode-iOS/Demos/src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ loadFont(void)
{
SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp");

if (surface == NULL) {
if (!surface) {
printf("Error loading bitmap: %s\n", SDL_GetError());
return 0;
} else {
Expand All @@ -183,7 +183,7 @@ loadFont(void)
SDL_BlitSurface(surface, NULL, converted, NULL);
/* create our texture */
texture = SDL_CreateTextureFromSurface(renderer, converted);
if (texture == NULL) {
if (!texture) {
printf("texture creation failed: %s\n", SDL_GetError());
} else {
/* set blend mode for our texture */
Expand Down
4 changes: 2 additions & 2 deletions Xcode-iOS/Demos/src/rectangles.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 == NULL) {
if (!window) {
fatalError("Could not initialize Window");
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
if (!renderer) {
fatalError("Could not create renderer");
}

Expand Down
4 changes: 2 additions & 2 deletions Xcode-iOS/Demos/src/touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ initializeTexture(SDL_Renderer *renderer)
{
SDL_Surface *bmp_surface;
bmp_surface = SDL_LoadBMP("stroke.bmp");
if (bmp_surface == NULL) {
if (!bmp_surface) {
fatalError("could not load stroke.bmp");
}
brush =
SDL_CreateTextureFromSurface(renderer, bmp_surface);
SDL_FreeSurface(bmp_surface);
if (brush == NULL) {
if (!brush) {
fatalError("could not create brush texture");
}
/* additive blending -- laying strokes on top of eachother makes them brighter */
Expand Down
2 changes: 1 addition & 1 deletion cmake/test/main_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) {
640, 480,
SDL_WINDOW_SHOWN
);
if (window == NULL) {
if (!window) {
fprintf(stderr, "could not create window: %s\n", SDL_GetError());
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void SDL_GetVersion(SDL_version *ver)
static SDL_bool check_hint = SDL_TRUE;
static SDL_bool legacy_version = SDL_FALSE;

if (ver == NULL) {
if (!ver) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/SDL_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void SDL_ResetAssertionReport(void)
{
SDL_assert_data *next = NULL;
SDL_assert_data *item;
for (item = triggered_assertions; item != NULL; item = next) {
for (item = triggered_assertions; item; item = next) {
next = (SDL_assert_data *)item->next;
item->always_ignore = SDL_FALSE;
item->trigger_count = 0;
Expand Down
34 changes: 17 additions & 17 deletions src/SDL_dataqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SDL_DataQueue *SDL_NewDataQueue(const size_t _packetlen, const size_t initialsla
{
SDL_DataQueue *queue = (SDL_DataQueue *)SDL_calloc(1, sizeof(SDL_DataQueue));

if (queue == NULL) {
if (!queue) {
SDL_OutOfMemory();
} else {
const size_t packetlen = _packetlen ? _packetlen : 1024;
Expand Down Expand Up @@ -101,7 +101,7 @@ void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
SDL_DataQueuePacket *prev = NULL;
size_t i;

if (queue == NULL) {
if (!queue) {
return;
}

Expand Down Expand Up @@ -144,16 +144,16 @@ static SDL_DataQueuePacket *AllocateDataQueuePacket(SDL_DataQueue *queue)
{
SDL_DataQueuePacket *packet;

SDL_assert(queue != NULL);
SDL_assert(queue);

packet = queue->pool;
if (packet != NULL) {
if (packet) {
/* we have one available in the pool. */
queue->pool = packet->next;
} else {
/* Have to allocate a new one! */
packet = (SDL_DataQueuePacket *)SDL_malloc(sizeof(SDL_DataQueuePacket) + queue->packet_size);
if (packet == NULL) {
if (!packet) {
return NULL;
}
}
Expand All @@ -162,8 +162,8 @@ static SDL_DataQueuePacket *AllocateDataQueuePacket(SDL_DataQueue *queue)
packet->startpos = 0;
packet->next = NULL;

SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0));
if (queue->tail == NULL) {
SDL_assert((queue->head) == (queue->queued_bytes != 0));
if (!queue->tail) {
queue->head = packet;
} else {
queue->tail->next = packet;
Expand All @@ -182,7 +182,7 @@ int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _
size_t origlen;
size_t datalen;

if (queue == NULL) {
if (!queue) {
return SDL_InvalidParamError("queue");
}

Expand All @@ -194,13 +194,13 @@ int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _

while (len > 0) {
SDL_DataQueuePacket *packet = queue->tail;
SDL_assert(packet == NULL || (packet->datalen <= packet_size));
if (packet == NULL || (packet->datalen >= packet_size)) {
SDL_assert(!packet || (packet->datalen <= packet_size));
if (!packet || (packet->datalen >= packet_size)) {
/* tail packet missing or completely full; we need a new packet. */
packet = AllocateDataQueuePacket(queue);
if (packet == NULL) {
if (!packet) {
/* uhoh, reset so we've queued nothing new, free what we can. */
if (origtail == NULL) {
if (!origtail) {
packet = queue->head; /* whole queue. */
} else {
packet = origtail->next; /* what we added to existing queue. */
Expand Down Expand Up @@ -238,7 +238,7 @@ SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
Uint8 *ptr = buf;
SDL_DataQueuePacket *packet;

if (queue == NULL) {
if (!queue) {
return 0;
}

Expand Down Expand Up @@ -267,7 +267,7 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
Uint8 *ptr = buf;
SDL_DataQueuePacket *packet;

if (queue == NULL) {
if (!queue) {
return 0;
}

Expand All @@ -286,15 +286,15 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)

if (packet->startpos == packet->datalen) { /* packet is done, put it in the pool. */
queue->head = packet->next;
SDL_assert((packet->next != NULL) || (packet == queue->tail));
SDL_assert((packet->next) || (packet == queue->tail));
packet->next = queue->pool;
queue->pool = packet;
}
}

SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0));
SDL_assert((queue->head) == (queue->queued_bytes != 0));

if (queue->head == NULL) {
if (!queue->head) {
queue->tail = NULL; /* in case we drained the queue entirely. */
}

Expand Down
2 changes: 1 addition & 1 deletion src/SDL_guid.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i;

if ((pszGUID == NULL) || (cbGUID <= 0)) {
if ((!pszGUID) || (cbGUID <= 0)) {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/SDL_hints.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
return SDL_FALSE;
}
if (hint->value != value &&
(value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
(!value || !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;
Expand Down Expand Up @@ -196,7 +196,7 @@ void SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *user
SDL_HintWatch *entry;
const char *value;

if (name == NULL || !*name) {
if (!name || !*name) {
SDL_InvalidParamError("name");
return;
}
Expand All @@ -208,7 +208,7 @@ void SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *user
SDL_DelHintCallback(name, callback, userdata);

entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
if (entry == NULL) {
if (!entry) {
SDL_OutOfMemory();
return;
}
Expand All @@ -220,10 +220,10 @@ void SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *user
break;
}
}
if (hint == NULL) {
if (!hint) {
/* Need to add a hint entry for this watcher */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (hint == NULL) {
if (!hint) {
SDL_OutOfMemory();
SDL_free(entry);
return;
Expand Down
Loading

0 comments on commit bd94f95

Please sign in to comment.