fputws yields Access Violation - by mats_11727

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


3
0
Sign in
to vote
ID 772585 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 11/28/2012 12:30:29 PM
Access Restriction Public

Description

I've found a weird issue with outputting wide chars in Visual Studio 2012 which I've narrowed down to the following code.

#include <cstdio>
int main()
{
  fputws(L"Hello World\n", stdout); // Throws Access Violation exception
}

This throws an exception when run. 

If I add a simple fputs in front it works fine.

#include <cstdio>
int main()
{
  fputs("", stdout);
  fputws(L"Hello World\n", stdout); // Now this works.
}

Other wide char output functions seems to work just fine: 

std::wcout << L"Hello world" << std::endl;
wprintf(L"Hello world\n");
_putws(L"Hello\n", stdout);
putwchar(L'H');

Also, the crash doesn't appear in Visual Studio 2008 or Visual Studio 2010. This can be confirmed by opening a Visual Studio 2010/2008 Command Prompt and compile and run the test file.
Sign in to post a comment.
Posted by Justin Vallon on 1/8/2013 at 2:26 PM
VS2012update1 fixed the problem. msvcr110d.dll version is 11.00.51106.1.
Posted by Justin Vallon on 1/8/2013 at 8:19 AM
Please reopen.

I have the same problem. Here is the cause, as far as I can tell:

In fputs.c, line 49, there is a call to _CHECK_IO_INIT(EOF), which ends up calling _ioinit, which (by the comment) initializes stdout. However, fputws.c has no such call, and so stdout is uninitialized when the characters are written to the buffer.

This would also seem to confirm that the workaround is to call fputs("", stdout) so that _ioinit is called.

My msvcr110d.dll version is 11.00.50727.1. fputws.c is from vs11\VC\crt\src\fputws.c. Dev is VS11 Express 2012 for Windows Desktop 11.0.50727.42 VSLRSTAGE, Visual C++ 2012 05695-004-0030004-02232.
Posted by mats_11727 on 11/29/2012 at 2:17 AM
I found a different machine to test this on myself and the crash didn't happen. Seems to be some kind of dependency I have on my local machine. Will investigate this further on my own.

Thanks for the prompt feedback. Please close this issue.
Posted by Microsoft on 11/28/2012 at 11:02 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information(a video or something). Please submit this information to us within 3 business days. We look forward to hearing from you with this information.
In my case, the code works fine as 527181.png shows, my vs is VS Ultimate 2012 Version 11.0.51020.03 update 1 CTP.
Posted by Microsoft on 11/28/2012 at 3:52 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)