testautomation: avoid format related warnings by using a few pragma's ci: enable -Werror to a few platforms
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 133c797..d7c19f1 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -160,6 +160,25 @@ add_executable(controllermap controllermap.c testutils.c)
add_executable(testvulkan testvulkan.c)
add_executable(testoffscreen testoffscreen.c)
+cmake_push_check_state(RESET)
+
+check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
+if(HAVE_WFORMAT_OVERFLOW)
+ target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW)
+endif()
+
+check_c_compiler_flag(-Wformat HAVE_WFORMAT)
+if(HAVE_WFORMAT)
+ target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT)
+endif()
+
+check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS)
+if(HAVE_WFORMAT_EXTRA_ARGS)
+ target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS)
+endif()
+
+cmake_pop_check_state()
+
SET(ALL_TESTS
checkkeys
checkkeysthreads
diff --git a/test/configure b/test/configure
index 9c1e90a..8b7afb0 100755
--- a/test/configure
+++ b/test/configure
@@ -4664,6 +4664,90 @@ if test x$have_opengl = xyes; then
OPENGL_TARGETS="TARGETS"
fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat" >&5
+printf %s "checking for GCC -Wformat... " >&6; }
+have_wformat=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+int x = 0;
+int
+main (void)
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+ have_wformat=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat" >&5
+printf "%s\n" "$have_wformat" >&6; }
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat = xyes; then
+ CFLAGS="$CFLAGS -DHAVE_WFORMAT"
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat-overflow" >&5
+printf %s "checking for GCC -Wformat-overflow... " >&6; }
+have_wformat_overflow=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat-overflow"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+int x = 0;
+int
+main (void)
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+ have_wformat_overflow=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat_overflow" >&5
+printf "%s\n" "$have_wformat_overflow" >&6; }
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat_overflow = xyes; then
+ CFLAGS="$CFLAGS -DHAVE_WFORMAT_OVERFLOW"
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GCC -Wformat-extra-args" >&5
+printf %s "checking for GCC -Wformat-extra-args... " >&6; }
+have_wformat_extra_args=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat-extra-args"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+int x = 0;
+int
+main (void)
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+ have_wformat_extra_args=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_wformat_extra_args" >&5
+printf "%s\n" "$have_wformat_extra_args" >&6; }
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat_extra_args = xyes; then
+ CFLAGS="$CFLAGS -DHAVE_WFORMAT_EXTRA_ARGS"
+fi
+
# Check whether --enable-werror was given.
if test ${enable_werror+y}
then :
diff --git a/test/configure.ac b/test/configure.ac
index d31565d..e0dd1c4 100644
--- a/test/configure.ac
+++ b/test/configure.ac
@@ -184,6 +184,42 @@ if test x$have_opengl = xyes; then
OPENGL_TARGETS="TARGETS"
fi
+AC_MSG_CHECKING(for GCC -Wformat)
+have_wformat=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
+ [have_wformat=yes], [])
+AC_MSG_RESULT($have_wformat)
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat = xyes; then
+ CFLAGS="$CFLAGS -DHAVE_WFORMAT"
+fi
+
+AC_MSG_CHECKING(for GCC -Wformat-overflow)
+have_wformat_overflow=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat-overflow"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
+ [have_wformat_overflow=yes], [])
+AC_MSG_RESULT($have_wformat_overflow)
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat_overflow = xyes; then
+ CFLAGS="$CFLAGS -DHAVE_WFORMAT_OVERFLOW"
+fi
+
+AC_MSG_CHECKING(for GCC -Wformat-extra-args)
+have_wformat_extra_args=no
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Wformat-extra-args"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
+ [have_wformat_extra_args=yes], [])
+AC_MSG_RESULT($have_wformat_extra_args)
+CFLAGS="$save_CFLAGS"
+if test x$have_wformat_extra_args = xyes; then
+ CFLAGS="$CFLAGS -DHAVE_WFORMAT_EXTRA_ARGS"
+fi
+
AC_ARG_ENABLE(werror,
[AS_HELP_STRING([--enable-werror], [treat warnings as errors [default=no]])],
enable_werror=$enableval, enable_werror=no)
diff --git a/test/testautomation_platform.c b/test/testautomation_platform.c
index 5eb37b3..0b37dd9 100644
--- a/test/testautomation_platform.c
+++ b/test/testautomation_platform.c
@@ -376,6 +376,11 @@ int platform_testSetErrorEmptyInput(void *arg)
return TEST_COMPLETED;
}
+#if defined(HAVE_WFORMAT_OVERFLOW)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-overflow"
+#endif
+
/* !
* \brief Tests SDL_SetError with invalid input
* \sa
@@ -451,7 +456,7 @@ int platform_testSetErrorInvalidInput(void *arg)
probeError,
lastError);
}
-
+
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
@@ -459,6 +464,10 @@ int platform_testSetErrorInvalidInput(void *arg)
return TEST_COMPLETED;
}
+#if defined(HAVE_WFORMAT_OVERFLOW)
+#pragma GCC diagnostic pop
+#endif
+
/* !
* \brief Tests SDL_GetPowerInfo
* \sa
diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c
index a89ec1e..7abad36 100644
--- a/test/testautomation_stdlib.c
+++ b/test/testautomation_stdlib.c
@@ -7,7 +7,6 @@
#include "SDL.h"
#include "SDL_test.h"
-
/* Test case functions */
/**
@@ -36,6 +35,16 @@ stdlib_strlcpy(void *arg)
return TEST_COMPLETED;
}
+#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic push
+#if defined(HAVE_WFORMAT)
+#pragma GCC diagnostic ignored "-Wformat"
+#endif
+#if defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic ignored "-Wformat-extra-args"
+#endif
+#endif
+
/**
* @brief Call to SDL_snprintf
*/
@@ -159,6 +168,10 @@ stdlib_snprintf(void *arg)
return TEST_COMPLETED;
}
+#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic pop
+#endif
+
/**
* @brief Call to SDL_getenv and SDL_setenv
*/
@@ -293,6 +306,16 @@ stdlib_getsetenv(void *arg)
return TEST_COMPLETED;
}
+#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic push
+#if defined(HAVE_WFORMAT)
+#pragma GCC diagnostic ignored "-Wformat"
+#endif
+#if defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic ignored "-Wformat-extra-args"
+#endif
+#endif
+
/**
* @brief Call to SDL_sscanf
*/
@@ -375,6 +398,10 @@ stdlib_sscanf(void *arg)
return TEST_COMPLETED;
}
+#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
+#pragma GCC diagnostic pop
+#endif
+
#if defined(_WIN64)
# define SIZE_FORMAT "I64u"
#elif defined(__WIN32__)