Preventing an overflow in wvsprintf ??

S

Simon L

I've got a log object that takes a variable number of arguments..

void CLog::Log( const TCHAR* pcData ... )
{
va_list ap;
va_start(ap, pcData);

int iBuf = wcslen(pcData);
-> iBuf could contain just a formatting string so is small

TCHAR cLogstrW[BUFSIZE];
UINT iRtn = wvsprintf( cLogstrW , pcData , ap );

wvsprintf copies more than BUFSIZE.

I need to prevent buffer overflows here - any suggestions?

Thanks
 
D

Davlet Panech

Simon said:
I've got a log object that takes a variable number of arguments..

void CLog::Log( const TCHAR* pcData ... )
{
va_list ap;
va_start(ap, pcData);

int iBuf = wcslen(pcData);
-> iBuf could contain just a formatting string so is small

TCHAR cLogstrW[BUFSIZE];
UINT iRtn = wvsprintf( cLogstrW , pcData , ap );

wvsprintf copies more than BUFSIZE.

I need to prevent buffer overflows here - any suggestions?

Thanks

Use vswprintf, it accepts buffer size as an extra parameter (the
function you are calling, "wvsprintf" is not standard I think).

OTOH your platform (Windows?) may not have this function (IIRC it's in
ISO C++97, but older MSVC versions are missing many features). There's
probably some platform-specific equivalent, you might want to ask in a
relevant newsgroup.


D.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top