468,513 Members | 984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

Preventing an overflow in wvsprintf ??

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
1 3483
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.

Similar topics

15 posts views Thread by Andrew Fedoniouk | last post: by
27 posts views Thread by REH | last post: by
7 posts views Thread by wij | last post: by
25 posts views Thread by junky_fellow | last post: by
19 posts views Thread by Xavier Décoret | last post: by
8 posts views Thread by starffly | last post: by
42 posts views Thread by thomas.mertes | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.