NO

Author Topic: [FIXED] Checking arguments to a variadic function is broken?  (Read 2959 times)

iZzz32

  • Guest
Quote from: Pelles C changelog between 5.00.1 to 6.00
• Added support for checking arguments to a variadic function using the literal format string (printf, scanf, or scanf_s syntax).

Quote from: Pelles C manual
vaformat(family, n, m)
Used for checking arguments to a variadic function using a literal format string. The family argument must be printf, scanf, or scanf_s, to specify that the format string contains specifiers for the printf, scanf, or scanf_s family of functions, respectively. The n argument specifies the number of the format string argument in the variadic function (1-127). The m argument specifies the number of the first argument to check (1-127).  [6.00]

And an example:
Code: [Select]
__declspec(vaformat(printf,2,3)) int __cdecl sprintf(char *buf, const char *format, ...);

What I’m trying to do is to make a compiler warn me about invalid arguments for debug macros. But pocc -W2 -c test.c produces no warnings even for the following code. Am I doing something wrong? Is it broken in 7.00?

Code: [Select]
#include <stdio.h>
#include <stdarg.h>

__declspec(vaformat(printf,1,2)) void __cdecl foo(const char * fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  (void) vprintf(fmt, ap);
  va_end(ap);
}

int main(void)
{
  foo("%s %s %s", 1.0);
  return 0;
}

Update: wow, it works for printf and others. And it works for mine function too, but only if there is a declaration without definition or if the declaration containing __declspec(varformat) is below the definition. I’m not sure if it is a bug, but… any reason for this?
« Last Edit: May 28, 2012, 03:47:16 PM by iZzz32 »

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Checking arguments to a variadic function is broken?
« Reply #1 on: May 15, 2012, 05:58:53 PM »
It looks like a bug; a definition appears to kill this annotation. I will look at it...
/Pelle