I have the following program http://ideone.com/1RPs8E . It uses a variadic function tlog that will print a line in a log file. It receives a level for the line printed, a file name, a line and a function for debug information and a format for printf and a list o arguments.
void tlog(int level, const char *file, int line, const char *fun, const char *fmt, ...)
I also use a LOGL macro that calls tlog function for the current file, line and function.
#define LOGL(level, fmt, ...) tlog(level, __FILENAME__, __LINE__, __FUNCTION__, fmt, ##__VA_ARGS__)
And various macros that use LOGL macro for example:
#define DEBUGEX(fmt, ...) LOGL(LDEBUGEX, fmt, ##__VA_ARGS__)
#define DEBUG(fmt, ...) LOGL(LDEBUG, fmt, ##__VA_ARGS__)
#define INFO(fmt, ...) LOGL(LINFO, fmt, ##__VA_ARGS__)
When running the program in valgrind:
$ valgrind -v --track-origins=yes ./t
I receive the following error: "Uninitialised value was created by a stack allocation" on the line 150 (when I use the DEBUGEX macro). Full log here: http://pastebin.com/rZu4nkHd
What is the problem with the code? For me it seems to be ok. If I remove the level parameter from the tlog function and all the macros that call it the error does not occur anymore.
Tested with gcc 4.8.2 on Archlinux, and gcc 4.6.3 on Ubuntu 12.04.3
"%p"
casting to(void *)
to print pointers. – alkvoid*
isn't even necessary, here, the thing isvoid*
. – Jens GustedtlX
probably is meant for 64 bit wide data, where your pointers are perhaps just 32 bit – Jens Gustedt