Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

How to prevent GCC from compiling error-prone vsnprintf?

$
0
0

Is it possible to detect at compile time that the fourth argument of vsnprintf() consists of fewer than required by the third argument of vsnprintf()? I mean:

#include <stdio.h>#include <stdarg.h>void foo(const char* format, ...){    char buffer[256];    va_list args;    va_start (args, format);    vsnprintf(buffer, 256, format, args); // args may points to fewer arguments than expected in the format                                va_end (args);}int main (){    foo("%d %d", 1); // the format requires two arguments, but only one is provided, so a warning from the compiler is expected here    return 0;}

gcc -Wall main.c compiles the above without warnings


Viewing all articles
Browse latest Browse all 22113

Trending Articles