Add format string annotations to all printf style functions

This should help to catch most if not all printf mistakes since those
can then be caught by our CI.
This commit is contained in:
asarium committed 2017-03-15 19:34:11 +01:00
1 parent caaaf3213d
commit 2a4795596f
9 files changed
+20 -18

No files matched your search

+1 -1
View File
@@ -268,7 +268,7 @@ bool dc_pause_output(void);
* @brief Prints the given char string to the debug console
* @details See the doc for std::printf() for formating and more details
*/
void dc_printf(const char *format, ...);
void dc_printf(SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(1, 2);
/**
* @brief Opens and processes the debug console. (Blocking call)
+1 -1
View File
@@ -34,6 +34,7 @@
#include "playerman/player.h"
#include "popup/popup.h"
#include "osapi/osapi.h"
#include "hud/hudmessage.h"
#ifndef WIN32
#include <cstdio>
@@ -53,7 +54,6 @@
extern int Multi_debrief_stats_accept_code;
extern void HUD_printf(const char *format, ...);
extern int game_hacked_data();
+4 -4
View File
@@ -876,13 +876,13 @@ bool gr_resize_screen_posf(float *x, float *y, float *w = NULL, float *h = NULL,
// Does formatted printing. This calls gr_string after formatting,
// so if you don't need to format the string, then call gr_string
// directly.
extern void gr_printf( int x, int y, const char * format, ... );
extern void gr_printf( int x, int y, const char * format, SCP_FORMAT_STRING ... ) SCP_FORMAT_STRING_ARGS(3, 4);
// same as gr_printf but positions text correctly in menus
extern void gr_printf_menu( int x, int y, const char * format, ... );
extern void gr_printf_menu( int x, int y, const char * format, SCP_FORMAT_STRING ... ) SCP_FORMAT_STRING_ARGS(3, 4);
// same as gr_printf_menu but accounts for menu zooming
extern void gr_printf_menu_zoomed( int x, int y, const char * format, ... );
extern void gr_printf_menu_zoomed( int x, int y, const char * format, SCP_FORMAT_STRING ... ) SCP_FORMAT_STRING_ARGS(3, 4);
// same as gr_printf but doesn't resize for non-standard resolutions
extern void gr_printf_no_resize( int x, int y, const char * format, ... );
extern void gr_printf_no_resize( int x, int y, const char * format, SCP_FORMAT_STRING ... ) SCP_FORMAT_STRING_ARGS(3, 4);
// Returns the size of the string in pixels in w and h
extern void gr_get_string_size( int *w, int *h, const char * text, int len = 9999 );
+2 -2
View File
@@ -311,8 +311,8 @@ public:
void renderString(int x, int y, const char *str);
void renderString(int x, int y, int gauge_id, const char *str);
void renderStringAlignCenter(int x, int y, int area_width, const char *s);
void renderPrintf(int x, int y, const char* format, ...);
void renderPrintf(int x, int y, int gauge_id, const char* format, ...);
void renderPrintf(int x, int y, SCP_FORMAT_STRING const char* format, ...) SCP_FORMAT_STRING_ARGS(4, 5);
void renderPrintf(int x, int y, int gauge_id, SCP_FORMAT_STRING const char* format, ...) SCP_FORMAT_STRING_ARGS(5, 6);
void renderLine(int x1, int y1, int x2, int y2);
void renderGradientLine(int x1, int y1, int x2, int y2);
void renderRect(int x, int y, int w, int h);
+4 -4
View File
@@ -65,11 +65,11 @@ void hud_init_msg_window();
void hud_clear_msg_buffer();
int HUD_team_get_source(int team);
int HUD_source_get_team(int team);
void HUD_printf(const char *format, ...);
void HUD_printf(SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(1, 2);
void hud_sourced_print(int source, const char *msg);
void HUD_sourced_printf(int source, const char *format, ...); // send hud message from specified source
void HUD_ship_sent_printf(int sh, const char *format, ...); // send hud message from a specific ship
void HUD_fixed_printf(float duration, color col, const char *format, ...); // Display a single message for duration seconds.
void HUD_sourced_printf(int source, SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(2, 3); // send hud message from specified source
void HUD_ship_sent_printf(int sh, SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(2, 3); // send hud message from a specific ship
void HUD_fixed_printf(float duration, color col, SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(3, 4); // Display a single message for duration seconds.
void HUD_init_fixed_text(); // Clear all pending fixed text.
void HUD_add_to_scrollback(const char *text, int source);
+3 -1
View File
@@ -12,6 +12,8 @@
#ifndef _FREESPACE_MULTIPLAYER_LOGFILE_HEADER_FILE
#define _FREESPACE_MULTIPLAYER_LOGFILE_HEADER_FILE
#include "globalincs/pstypes.h"
// ----------------------------------------------------------------------------------------------------
// MULTI LOGFILE DEFINES/VARS
//
@@ -31,7 +33,7 @@ void multi_log_close();
void multi_log_process();
// printf function itself called by the ml_printf macro
void ml_printf(const char *format, ...);
void ml_printf(SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(1, 2);
// string print function
void ml_string(const char *string, int add_time = 1);
+1 -1
View File
@@ -30,7 +30,7 @@ bool logfile_init(int logfile_type);
void logfile_close(int logfile_type);
// printf function itself called by the log_printf macro
void log_printf(int logfile_type, const char *format, ...);
void log_printf(int logfile_type, SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(2, 3);
// string print function
void log_string(int logfile_type, const char *string, int add_time = 0);
+3 -3
View File
@@ -91,8 +91,8 @@ extern void ignore_gray_space();
// error
extern int get_line_num();
extern char *next_tokens();
extern void diag_printf(const char *format, ...);
extern void error_display(int error_level, const char *format, ...);
extern void diag_printf(SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(1, 2);
extern void error_display(int error_level, SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(2, 3);
// skip
extern int skip_to_string(const char *pstr, const char *end = NULL);
@@ -289,7 +289,7 @@ extern bool can_construe_as_integer(const char *text);
// Goober5000 (ditto for C++)
extern void vsprintf(SCP_string &dest, const char *format, va_list ap);
extern void sprintf(SCP_string &dest, const char *format, ...);
extern void sprintf(SCP_string &dest, SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(2, 3);
// Goober5000
extern int subsystem_stricmp(const char *str1, const char *str2);
+1 -1
View File
@@ -105,7 +105,7 @@ int emp_should_blit_gauge();
void emp_hud_string(int x, int y, int gauge_id, const char *str, int resize_mode);
// emp hud printf
void emp_hud_printf(int x, int y, int gauge_id, const char *format, ...);
void emp_hud_printf(int x, int y, int gauge_id, SCP_FORMAT_STRING const char *format, ...) SCP_FORMAT_STRING_ARGS(4, 5);
// throw some jitter into HUD x and y coords
void emp_hud_jitter(int *x, int *y);