Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2005

Tip: Looking for answers? Try searching our database.

12 octobers patches _vscwprintf( pszFormat, args ); difference!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Egbert Nierop (MVP for IIS) - 13 Oct 2005 10:49 GMT
Am I the only one?

After having installed the patches as a brave MS citycen :),
this function suddenly returns one less then before or possible
vswprintf assumes the given length including the terminating zero.
Doug Harrison [MVP] - 13 Oct 2005 16:28 GMT
On Thu, 13 Oct 2005 11:49:30 +0200, "Egbert Nierop \(MVP for IIS\)"
<egbert_nierop@nospam.invalid> wrote:

>Am I the only one?
>
>After having installed the patches as a brave MS citycen :),
>this function suddenly returns one less then before or possible
>vswprintf assumes the given length including the terminating zero.

Can you demonstrate this in a little console program?

Signature

Doug Harrison
Visual C++ MVP

Egbert Nierop (MVP for IIS) - 14 Oct 2005 08:09 GMT
> On Thu, 13 Oct 2005 11:49:30 +0200, "Egbert Nierop \(MVP for IIS\)"
> <egbert_nierop@nospam.invalid> wrote:
[quoted text clipped - 6 lines]
>
> Can you demonstrate this in a little console program?

ps: I established this bug. It is not windows but VC 8 which behaves
different with VC 7.
I have mailed this to Michael M (Microsoft).
BSTR __cdecl Format(PCWSTR pszFormat, ...) throw()

{

va_list args;

HRESULT hr = S_OK;

BSTR retVal = NULL;
va_start( args, pszFormat );

int len = _vscwprintf( pszFormat, args );

retVal = SysAllocStringLen(NULL, len);

if(retval != NULL)

vswprintf( retVal, (SIZE_T)len, pszFormat, args );

va_end(args);

return retVal;

}

INT main()

{

CoInitialize(NULL);

{

   BSTR test = Format(L"%s, %d,%s", L"one", 2, L"three");

   wprintf(test); //"output one, 2, thre" <-- BUG this used to have the
correct length in VC 7?

   SysFreeString(test);

}

CoUninitialize();

return 0;

}
Jochen Kalmbach [MVP] - 14 Oct 2005 08:26 GMT
Hi Egbert!

> ps: I established this bug. It is not windows but VC 8 which behaves
> different with VC 7.
[quoted text clipped - 12 lines]
> return retVal;
> }

If it had worked in VC7(.1) then it was a bug in VC7(.1) and is now
corrected in VC8 :-)

The following line is wrong:
> int len = _vscwprintf(pszFormat, args);

You should change it to
int len = _vscwprintf(pszFormat, args) + 1;

The reason is:
_vscprintf doesn't count the terminating '\0'!
but vswprintf requires the terminating NUL in in the count.

Signature

Greetings
  Jochen

   My blog about Win32 and .NET
   http://blog.kalmbachnet.de/

Egbert Nierop (MVP for IIS) - 14 Oct 2005 08:44 GMT
> Hi Egbert!
>
[quoted text clipped - 17 lines]
> If it had worked in VC7(.1) then it was a bug in VC7(.1) and is now
> corrected in VC8 :-)

Great! :<

Counting on bugs helps one to improve his skills :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.