Skip to content

Commit 5f36f3d

Browse files
Make ZoneNameF() less error-prone by checking format against args
`ZoneNameF(fmt, ...)` was error-prone: if the format is inconsistent with arguments, the code compiled fine without errors or warnings. Use gcc/clang `__attribute__((format(printf, fmt_idx, arg_idx)))` function attribute, so that `ZoneNameF(fmt, ...)` can now check at compilation time the consistency between the format and the arguments. See https://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Function-Attributes.html
1 parent 6e214ca commit 5f36f3d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

‎public/client/TracyScoped.hpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#include "TracyProfiler.hpp"
1313
#include "TracyCallstack.hpp"
1414

15+
#if (defined(__GNUC__) || defined(__clang__))
16+
# define TRACY_ATTRIBUTE_FORMAT_PRINTF(fmt_idx, arg_idx) \
17+
__attribute__((format(printf, fmt_idx, arg_idx)))
18+
#else
19+
# define TRACY_ATTRIBUTE_FORMAT_PRINTF(fmt_idx, arg_idx)
20+
#endif
1521
namespace tracy
1622
{
1723

@@ -99,7 +105,7 @@ class ScopedZone
99105
TracyQueueCommit( zoneTextFatThread );
100106
}
101107

102-
void TextFmt( const char* fmt, ... )
108+
void TextFmt( const char* fmt, ... ) TRACY_ATTRIBUTE_FORMAT_PRINTF(2, 3)
103109
{
104110
if( !m_active ) return;
105111
#ifdef TRACY_ON_DEMAND
@@ -138,7 +144,7 @@ class ScopedZone
138144
TracyQueueCommit( zoneTextFatThread );
139145
}
140146

141-
void NameFmt( const char* fmt, ... )
147+
void NameFmt( const char* fmt, ... ) TRACY_ATTRIBUTE_FORMAT_PRINTF(2, 3)
142148
{
143149
if( !m_active ) return;
144150
#ifdef TRACY_ON_DEMAND

0 commit comments

Comments
 (0)