Browse Source

Enable compiler checks for printf-like functions

pull/1484/head
Gleb Mazovetskiy 5 years ago committed by Anders Jenbo
parent
commit
77d0bb6690
  1. 6
      Source/appfat.h
  2. 6
      SourceS/console.h
  3. 3
      SourceS/sdl2_to_1_2_backports.h
  4. 7
      defs.h

6
Source/appfat.h

@ -7,10 +7,12 @@
#include <SDL.h>
#include "../defs.h"
namespace devilution {
[[noreturn]] void app_fatal(const char *pszFmt, ...);
void DrawDlg(const char *pszFmt, ...);
[[noreturn]] void app_fatal(const char *pszFmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2);
void DrawDlg(const char *pszFmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2);
#ifdef _DEBUG
[[noreturn]] void assert_fail(int nLineNo, const char *pszFile, const char *pszFail);
#endif

6
SourceS/console.h

@ -1,6 +1,8 @@
#pragma once
#if defined(_WIN64) || defined(_WIN32)
#include "../defs.h"
// Suppress definitions of `min` and `max` macros by <windows.h>:
#define NOMINMAX 1
#define WIN32_LEAN_AND_MEAN
@ -8,7 +10,9 @@
namespace devilution {
void printInConsole(const char *fmt, ...)
void printInConsole(const char *fmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2);
inline void printInConsole(const char *fmt, ...)
{
static HANDLE stderrHandle = NULL;
if (stderrHandle == NULL) {

3
SourceS/sdl2_to_1_2_backports.h

@ -10,6 +10,7 @@
#include <cstddef>
#include "console.h"
#include "../defs.h"
#include "../SourceX/stubs.h"
#define WINDOW_ICON_NAME 0
@ -54,6 +55,8 @@
#define SDL_JoystickID Sint32
#define SDL_JoystickNameForIndex SDL_JoystickName
void SDL_Log(const char *fmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2);
inline void SDL_Log(const char *fmt, ...)
{
char message[256];

7
defs.h

@ -203,3 +203,10 @@
#else
#define DVL_ATTRIBUTE_ALWAYS_INLINE
#endif
#if DVL_HAVE_ATTRIBUTE(format) || (defined(__GNUC__) && !defined(__clang__))
#define DVL_PRINTF_ATTRIBUTE(fmtargnum, firstarg) \
__attribute__((__format__(__printf__, fmtargnum, firstarg)))
#else
#define DVL_PRINTF_ATTRIBUTE(fmtargnum)
#endif

Loading…
Cancel
Save