From 0c121ad6a7bae08c2caa1728edce276f316b410a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Max=20Seidenst=C3=BCcker?= <[EMAIL REDACTED]>
Date: Sun, 8 Feb 2026 11:59:55 +0100
Subject: [PATCH] conditional expression is constant
MSVC: C4127: conditional expression is constant
---
test/testautomation_math.c | 3 ++-
test/testautomation_stdlib.c | 12 ++++++++----
test/testautomation_surface.c | 3 ++-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/test/testautomation_math.c b/test/testautomation_math.c
index 9ba3ca447ebce..8b1972939eb58 100644
--- a/test/testautomation_math.c
+++ b/test/testautomation_math.c
@@ -1060,7 +1060,8 @@ exp_overflowCase(void *args)
{
double result;
- if (sizeof(double) > 8) {
+ const bool double_is_larger_than_64bit = sizeof(double) > 8;
+ if (double_is_larger_than_64bit) {
return TEST_SKIPPED;
}
diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c
index ae12c893384d9..4d1c6ea5db774 100644
--- a/test/testautomation_stdlib.c
+++ b/test/testautomation_stdlib.c
@@ -365,7 +365,8 @@ static int SDLCALL stdlib_snprintf(void *arg)
result == SDL_strlen(expected5),
"Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
- if (sizeof(void *) >= 8) {
+ const bool is_at_least_64bit_system = sizeof(void *) >= 8;
+ if (is_at_least_64bit_system) {
result = SDL_snprintf(text, sizeof(text), "%p", (void *)SDL_SINT64_C(0x1ba07bddf60));
expected = "0x1ba07bddf60";
expected2 = "000001BA07BDDF60";
@@ -1324,7 +1325,8 @@ static int SDLCALL stdlib_wcstol(void *arg)
WCSTOL_TEST_CASE(L" - 1", 0, 0, 0); // invalid input
// values near the bounds of the type
- if (sizeof(long) == 4) {
+ const bool long_is_32bit = sizeof(long) == 4;
+ if (long_is_32bit) {
WCSTOL_TEST_CASE(L"2147483647", 10, 2147483647, 10);
WCSTOL_TEST_CASE(L"2147483648", 10, 2147483647, 10);
WCSTOL_TEST_CASE(L"-2147483648", 10, -2147483647L - 1, 11);
@@ -1383,7 +1385,8 @@ static int SDLCALL stdlib_strtox(void *arg)
// Suppressing warnings would be difficult otherwise.
// Since the CI runs the tests against a variety of targets, this should be fine in practice.
- if (sizeof(long) == 4) {
+ const bool long_is_32bit = sizeof(long) == 4;
+ if (long_is_32bit) {
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "0", 0, 0, 1);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "0", 10, 0, 1);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-0", 0, 0, 2);
@@ -1399,7 +1402,8 @@ static int SDLCALL stdlib_strtox(void *arg)
STRTOX_TEST_CASE(SDL_strtoul, unsigned long, "%lu", "-4294967295", 10, 1, 11);
}
- if (sizeof(long long) == 8) {
+ const bool long_long_is_64bit = sizeof(long long) == 8;
+ if (long_long_is_64bit) {
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "0", 0, 0LL, 1);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "0", 10, 0LL, 1);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-0", 0, 0LL, 2);
diff --git a/test/testautomation_surface.c b/test/testautomation_surface.c
index 3c7dc92cea2d7..227a86aee603b 100644
--- a/test/testautomation_surface.c
+++ b/test/testautomation_surface.c
@@ -1570,7 +1570,8 @@ static int SDLCALL surface_testOverflow(void *arg)
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
+ const bool is_32bit_system_with_int_larger_32bit = sizeof(size_t) == 4 && sizeof(int) >= 4;
+ if (is_32bit_system_with_int_larger_32bit) {
SDL_ClearError();
expectedError = "aligning pitch would overflow";
/* 0x5555'5555 * 3bpp = 0xffff'ffff which fits in size_t, but adding