By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

Preventing an overflow in wvsprintf ??

P: n/a
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

Sep 26 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Simon L wrote:
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.
Sep 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.