Re: Help with va_list, va_start



// The function
void FormatTest(const TCHAR* format, ...)
{
va_list args;
va_start(args, format);
TCHAR buf[1024] = {0};

wvsprintf(buf, format, args);

va_end(args);
}


void main (void)
{
// The test code
int val = 13;
FormatTest(("This is a test: %d"), val);
}

--
Vladimir


"buzz" <buzz@xxxxxxxx> wrote in message
news:%23ZYy$4$BGHA.2036@xxxxxxxxxxxxxxxxxxxxxxx
>I have a simple requirement....to develop a function that takes a parameter
>list like sprintf, and then pass it internally to sprintf. Everything
>compiles, but I don't get the answer is expect.
>
> // The function
> void FormatTest(const TCHAR* format, ...)
> {
> va_list args;
> va_start(args, format);
>
> TCHAR buf[1024];
> _stprintf(buf, format, args);
>
> va_end(args);
> }
>
> // The test code
> int val = 0x11223344;
> FormatTest(_T("This is a test: %X"), val);
>
> When I run the code, the buffer is filled with "This is a test: 2C20F9B8".
>
> When I examine the memory location at 0x2C20F9B8, I see my value
> 0x11223344.
>
> I tried using _sprintf(buf, format, (va_list)*args), but then I get "This
> is a test: 44".
>
> Can anyone tell me why this is not working, or show me how to make the
> code correct.
>
> Thanks!
>
> PS I see similar code in MFC8.
> PPS This code is running on a Pocket PC


.



Relevant Pages

  • Passing Variable Args
    ... void Log(const char* format, ...) ... va_list args; ... void DoLog1(const char* format, va_list* args) ...
    (comp.lang.c)
  • Re: Trouble with va_list processing
    ... void add (char *format, ...) ... va_start (args, format); ...
    (comp.lang.c)
  • Re: passing a va_list to sprintf
    ... "Shea Martin" wrote in message ... > void f ... > sprintf(buf, format, args); ... > But I can't get sprintf to properly take the args I have given to f. ...
    (comp.lang.c)
  • Re: passing a va_list to sprintf
    ... > void f ... > sprintf(buf, format, args); ... > But I can't get sprintf to properly take the args I have given to f. ...
    (comp.lang.c)
  • [Full-disclosure] Re: Format string in Doomsday 1.8.6
    ... Both Con_Message and conPrintf are vulnerable to a format string ... buffer = malloc; ... void conPrintf(int flags, const char *format, va_list args) ... vsprintf(message_buf, str, args); ...
    (Full-Disclosure)