Check standard error code return values as < 0 instead of == -1

This commit is contained in:
Sam Lantinga
2024-08-22 06:53:25 -07:00
parent 46d9066a69
commit 037541a0e0
29 changed files with 59 additions and 59 deletions

View File

@@ -93,7 +93,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == -1) {
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
SDL_free(filename);
return SDL_APP_FAILURE;

View File

@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == -1) {
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
quit(1);
}

View File

@@ -113,7 +113,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv)
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError());
SDL_free(devices);
return SDL_APP_FAILURE;
} else if (SDL_BindAudioStream(device, stream_out) == -1) {
} else if (SDL_BindAudioStream(device, stream_out) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for playback: %s!\n", SDL_GetError());
SDL_free(devices);
return SDL_APP_FAILURE;
@@ -137,7 +137,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv)
if (!stream_in) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for recording: %s!\n", SDL_GetError());
return SDL_APP_FAILURE;
} else if (SDL_BindAudioStream(device, stream_in) == -1) {
} else if (SDL_BindAudioStream(device, stream_in) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for recording: %s!\n", SDL_GetError());
return SDL_APP_FAILURE;
}

View File

@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
return 1;
}
if (SDL_Init(0) == -1) {
if (SDL_Init(0) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
return 1;
}
@@ -130,19 +130,19 @@ int main(int argc, char *argv[])
}
/* !!! FIXME: put this in a subroutine and make it test more thoroughly (and put it in testautomation). */
if (SDL_CreateDirectory("testfilesystem-test") == -1) {
if (SDL_CreateDirectory("testfilesystem-test") < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateDirectory('testfilesystem-test') failed: %s", SDL_GetError());
} else if (SDL_CreateDirectory("testfilesystem-test/1") == -1) {
} else if (SDL_CreateDirectory("testfilesystem-test/1") < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateDirectory('testfilesystem-test/1') failed: %s", SDL_GetError());
} else if (SDL_CreateDirectory("testfilesystem-test/1") == -1) { /* THIS SHOULD NOT FAIL! Making a directory that already exists should succeed here. */
} else if (SDL_CreateDirectory("testfilesystem-test/1") < 0) { /* THIS SHOULD NOT FAIL! Making a directory that already exists should succeed here. */
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateDirectory('testfilesystem-test/1') failed: %s", SDL_GetError());
} else if (SDL_RenamePath("testfilesystem-test/1", "testfilesystem-test/2") == -1) {
} else if (SDL_RenamePath("testfilesystem-test/1", "testfilesystem-test/2") < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RenamePath('testfilesystem-test/1', 'testfilesystem-test/2') failed: %s", SDL_GetError());
} else if (SDL_RemovePath("testfilesystem-test/2") == -1) {
} else if (SDL_RemovePath("testfilesystem-test/2") < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RemovePath('testfilesystem-test/2') failed: %s", SDL_GetError());
} else if (SDL_RemovePath("testfilesystem-test") == -1) {
} else if (SDL_RemovePath("testfilesystem-test") < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RemovePath('testfilesystem-test') failed: %s", SDL_GetError());
} else if (SDL_RemovePath("testfilesystem-test") == -1) { /* THIS SHOULD NOT FAIL! Removing a directory that is already gone should succeed here. */
} else if (SDL_RemovePath("testfilesystem-test") < 0) { /* THIS SHOULD NOT FAIL! Removing a directory that is already gone should succeed here. */
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RemovePath('testfilesystem-test') failed: %s", SDL_GetError());
}

View File

@@ -99,7 +99,7 @@ int main(int argc, char **argv)
}
for (i = 0; i < state->num_windows; i++) {
if (SDL_SetWindowHitTest(state->windows[i], hitTest, NULL) == -1) {
if (SDL_SetWindowHitTest(state->windows[i], hitTest, NULL) < 0) {
SDL_Log("Enabling hit-testing failed for window %d: %s", i, SDL_GetError());
SDL_Quit();
return 1;

View File

@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
haptic = SDL_OpenHapticFromJoystick(joystick);
if (haptic) {
SDL_Log("Joy Haptic Opened\n");
if (SDL_InitHapticRumble(haptic) != 0) {
if (SDL_InitHapticRumble(haptic) < 0) {
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
SDL_CloseHaptic(haptic);
haptic = NULL;

View File

@@ -361,7 +361,7 @@ static int unifont_load_texture(Uint32 textureID)
}
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);
}
}

View File

@@ -185,7 +185,7 @@ int main(int argc, char **argv)
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio playback devices!");
} else {
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == -1) {
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename,
SDL_GetError());
} else {

View File

@@ -95,13 +95,13 @@ int main(int argc, char **argv)
goto end;
}
if (SDL_Init(SDL_INIT_AUDIO) == -1) {
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
ret = 2;
goto end;
}
if (SDL_LoadWAV(file_in, &spec, &data, &len) == -1) {
if (SDL_LoadWAV(file_in, &spec, &data, &len) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", file_in, SDL_GetError());
ret = 3;
goto end;
@@ -141,7 +141,7 @@ int main(int argc, char **argv)
SDL_WriteU32LE(io, dst_len); /* size */
SDL_WriteIO(io, dst_buf, dst_len);
if (SDL_CloseIO(io) == -1) {
if (SDL_CloseIO(io) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "closing '%s' failed: %s\n", file_out, SDL_GetError());
ret = 6;
goto end;

View File

@@ -136,12 +136,12 @@ int main(int argc, char **argv)
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n");
return 1;
}
if (SDL_InitHapticRumble(haptic) != 0) {
if (SDL_InitHapticRumble(haptic) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError());
return 1;
}
SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
if (SDL_PlayHapticRumble(haptic, 0.5, 5000) != 0) {
if (SDL_PlayHapticRumble(haptic, 0.5, 5000) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError());
return 1;
}
@@ -150,7 +150,7 @@ int main(int argc, char **argv)
SDL_StopHapticRumble(haptic);
SDL_Delay(2000);
SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
if (SDL_PlayHapticRumble(haptic, 0.3f, 5000) != 0) {
if (SDL_PlayHapticRumble(haptic, 0.3f, 5000) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError());
return 1;
}

View File

@@ -196,7 +196,7 @@ int main(int argc, char *argv[])
SDL_Log("Testing audio device: %s\n", devname);
if (SDL_GetAudioDeviceFormat(devices[i], &spec, NULL) != 0) {
if (SDL_GetAudioDeviceFormat(devices[i], &spec, NULL) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioDeviceFormat() failed: %s\n", SDL_GetError());
continue;
}

View File

@@ -25,7 +25,7 @@ static void tryOpenURL(const char *url)
int main(int argc, char **argv)
{
int i;
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_Log("SDL_Init failed: %s\n", SDL_GetError());
return 1;
}