Skip to content

Add __attribute__((format(printf, fmt, va))) on TraceLog and TextFormat#5627

Closed
AntoinePerrin25 wants to merge 3 commits intoraysan5:masterfrom
AntoinePerrin25:add-printf-format-attribute
Closed

Add __attribute__((format(printf, fmt, va))) on TraceLog and TextFormat#5627
AntoinePerrin25 wants to merge 3 commits intoraysan5:masterfrom
AntoinePerrin25:add-printf-format-attribute

Conversation

@AntoinePerrin25
Copy link

Added this attribute to raylib.h, and fixed warning caused by using the functions with the wrong format

Copy link
Contributor

@maiconpintoabreu maiconpintoabreu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you commit errors.txt by mistake.

@AntoinePerrin25 AntoinePerrin25 force-pushed the add-printf-format-attribute branch from 3181b46 to dc3e711 Compare March 6, 2026 10:47
@AntoinePerrin25
Copy link
Author

It was to show the errors caused after adding the attribute but removed it, ty

@maiconpintoabreu
Copy link
Contributor

You can add the error on the description

@AntoinePerrin25
Copy link
Author

Went to the examples, compiled them, 2 warnings, fixed them :

core/core_storage_values.c:136:165: warning: format specifies type 'unsigned int' but the argument has type 'unsigned long' [-Wformat]
136 | TraceLog(LOG_WARNING, "FILEIO: [%s] Failed to realloc data (%u), position in bytes (%u) bigger than actual file size", STORAGE_DATA_FILE, dataSize, position*sizeof(int));
| ~~ ^~~~~~~~~~~~~~~~~~~~
| %lu

models/models_loading_vox.c:70:28: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
70 | TraceLog(LOG_INFO, TextFormat("[%s] Model file loaded in %.3f ms", voxFileNames[i], t1 - t0));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
models/models_loading_vox.c:70:28: note: treat the string as an argument to avoid this
70 | TraceLog(LOG_INFO, TextFormat("[%s] Model file loaded in %.3f ms", voxFileNames[i], t1 - t0));
| ^
| "%s",

@AntoinePerrin25
Copy link
Author

You can add the error on the description

clang -c rcore.c -Wall -D_GNU_SOURCE -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_33 -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing -std=c99 -O1 -Werror=implicit-function-declaration -I. -Iexternal/glfw/include
In file included from rcore.c:120:
./rlgl.h:1782:103: warning: data argument not used by format string [-Wformat-extra-args]
1782 | TRACELOG(RL_LOG_WARNING, "GL: Maximum anisotropic filter level supported is %iX", id, (int)RLGL.ExtSupported.maxAnisotropyLevel);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
In file included from rcore.c:120:
./rlgl.h:1825:103: warning: data argument not used by format string [-Wformat-extra-args]
1825 | TRACELOG(RL_LOG_WARNING, "GL: Maximum anisotropic filter level supported is %iX", id, (int)RLGL.ExtSupported.maxAnisotropyLevel);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
In file included from rcore.c:120:
./rlgl.h:4283:132: warning: data argument not used by format string [-Wformat-extra-args]
4283 | case GL_COMPUTE_SHADER: TRACELOG(RL_LOG_WARNING, "SHADER: Compute shaders not enabled. Define GRAPHICS_API_OPENGL_43", shaderId); break;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
In file included from rcore.c:120:
./rlgl.h:4315:132: warning: data argument not used by format string [-Wformat-extra-args]
4315 | case GL_COMPUTE_SHADER: TRACELOG(RL_LOG_WARNING, "SHADER: Compute shaders not enabled. Define GRAPHICS_API_OPENGL_43", shaderId); break;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rcore.c:1992:141: warning: format specifies type 'int' but the argument has type 'int *' [-Wformat]
1992 | if ((*dataSize) != size) TRACELOG(LOG_WARNING, "FILEIO: [%s] File partially loaded (%i bytes out of %i)", fileName, dataSize, count);
| ~~ ^~~~~~~~
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rcore.c:1992:151: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
1992 | if ((*dataSize) != size) TRACELOG(LOG_WARNING, "FILEIO: [%s] File partially loaded (%i bytes out of %i)", fileName, dataSize, count);
| ~~ ^~~~~
| %zu
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
6 warnings generated.
clang -c rshapes.c -Wall -D_GNU_SOURCE -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_33 -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing -std=c99 -O1 -Werror=implicit-function-declaration -I. -Iexternal/glfw/include
clang -c rtextures.c -Wall -D_GNU_SOURCE -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_33 -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing -std=c99 -O1 -Werror=implicit-function-declaration -I. -Iexternal/glfw/include
rtextures.c:2419:140: warning: format specifies type 'unsigned int' but the argument has type 'unsigned char *' [-Wformat]
2419 | TRACELOG(LOG_DEBUG, "IMAGE: Generating mipmap level: %i (%i x %i) - size: %i - offset: 0x%x", i, mipWidth, mipHeight, mipSize, nextmip);
| ~~ ^~~~~~~
| %s
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
1 warning generated.
clang -c rtext.c -Wall -D_GNU_SOURCE -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_33 -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing -std=c99 -O1 -Werror=implicit-function-declaration -I. -Iexternal/glfw/include
clang -c rmodels.c -Wall -D_GNU_SOURCE -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_33 -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing -std=c99 -O1 -Werror=implicit-function-declaration -I. -Iexternal/glfw/include
rmodels.c:5370:87: warning: data argument not used by format string [-Wformat-extra-args]
5370 | else TRACELOG(LOG_WARNING, "MODEL: glTF image data MIME type not recognized", TextFormat("%s/%s", texPath, cgltfImage->uri));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rmodels.c:5478:54: warning: format specifies type 'int' but the argument has type 'cgltf_size' (aka 'unsigned long') [-Wformat]
5478 | TRACELOG(LOG_INFO, " > Meshes count: %i", data->meshes_count);
| ~~ ^~~~~~~~~~~~~~~~~~
| %zu
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rmodels.c:5479:70: warning: format specifies type 'int' but the argument has type 'cgltf_size' (aka 'unsigned long') [-Wformat]
5479 | TRACELOG(LOG_INFO, " > Materials count: %i (+1 default)", data->materials_count);
| ~~ ^~~~~~~~~~~~~~~~~~~~~
| %zu
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rmodels.c:5480:56: warning: format specifies type 'int' but the argument has type 'cgltf_size' (aka 'unsigned long') [-Wformat]
5480 | TRACELOG(LOG_DEBUG, " > Buffers count: %i", data->buffers_count);
| ~~ ^~~~~~~~~~~~~~~~~~~
| %zu
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rmodels.c:5481:55: warning: format specifies type 'int' but the argument has type 'cgltf_size' (aka 'unsigned long') [-Wformat]
5481 | TRACELOG(LOG_DEBUG, " > Images count: %i", data->images_count);
| ~~ ^~~~~~~~~~~~~~~~~~
| %zu
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rmodels.c:5482:57: warning: format specifies type 'int' but the argument has type 'cgltf_size' (aka 'unsigned long') [-Wformat]
5482 | TRACELOG(LOG_DEBUG, " > Textures count: %i", data->textures_count);
| ~~ ^~~~~~~~~~~~~~~~~~~~
| %zu
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rmodels.c:6168:159: warning: format specifies type 'int' but the argument has type 'cgltf_size' (aka 'unsigned long') [-Wformat]
6168 | if (data->skins_count > 1) TRACELOG(LOG_WARNING, "MODEL: [%s] can only load one skin (armature) per model, but gltf skins_count == %i", fileName, data->skins_count);
| ~~ ^~~~~~~~~~~~~~~~~
| %zu
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rmodels.c:6665:127: warning: format specifies type 'int' but the argument has type 'cgltf_size' (aka 'unsigned long') [-Wformat]
6665 | TRACELOG(LOG_WARNING, "MODEL: [%s] Expected one unique skin to load animation data from, but found %i", fileName, data->skins_count);
| ~~ ^~~~~~~~~~~~~~~~~
| %zu
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
rmodels.c:7198:156: warning: format specifies type 'double' but the argument has type 'uint32_t' (aka 'unsigned int') [-Wformat]
7198 | TRACELOG(LOG_INFO, "MODEL: [%s] Loaded animation: %s | Frames: %d | Duration: %fs", fileName, animations[a].name, animations[a].keyframeCount, m3d->action[a].durationmsec);
| ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~
| %u
./config.h:367:50: note: expanded from macro 'TRACELOG'
367 | #define TRACELOG(level, ...) TraceLog(level, VA_ARGS)
| ^~~~~~~~~~~
9 warnings generated.

@maiconpintoabreu
Copy link
Contributor

@AntoinePerrin25 Just tested the 2 examples and I could not see any Warning, I am stopping here as I do not get the propose of the change.

@AntoinePerrin25
Copy link
Author

AntoinePerrin25 commented Mar 6, 2026

@AntoinePerrin25 Just tested the 2 examples and I could not see any Warning, I am stopping here as I do not get the propose of the change.

The millions of warnings were from the first commit for raylib-master/src

@raysan5
Copy link
Owner

raysan5 commented Mar 6, 2026

@AntoinePerrin25 Thanks but I really can't see the need for this change and it adds affitional undesired complexity to the library.

@raysan5 raysan5 closed this Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants