log4cplus::helpers::towstring has a memory access exception
Logging Framework for C++
Brought to you by:
wilx
I'm using log4cplus as a logger for both CLR and non-CLR C++/CLI code and C# code so for that reason I'm using the Unicode x64 build of log4cplus, log4cplusU.lib/dll. The most recent build I've done is VS2013 but this also happens on other builds.
If I run the following code in a non-CLR C++/CLI x64 console application, I get a memory access exception.
int tmain(int argc, TCHAR argv[]) { std::string LogFileName = "WhenLoggingCppManagedCode.log"; auto db = log4cplus::helpers::towstring(LogFileName); }
What's up?
Unhandled exception at 0x00007FF8E4A1CDA1 (msvcr120.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
Unfortunatelly, this does not tell me much. You will have to try to debug this yourself a littel bit. What is the call stack?
Diff:
Exception:
Unhandled exception at 0x00007FF8E4A1CDA1 (msvcr120.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
What's up?
I'm using Visual Studio 2013. My call stack at the exception looks like:
At the point where the exception fires in
std::vector(size_type)
,_Count
is a crazy number.Last edit: Václav Haisman 2016-05-18
The reason appears to be that the string parameter gets scrambled or misinterpreted.
The same problem manifests itself on non-Unicode builds of log4cplus in unmanaged code in debug mode on VS but not in release mode builds.
For example:
Last edit: Kevin Lucidyne 2016-05-17
Here are the VS 2013 project settings for the log4cplus project.
Here are the project settings for the console application
Have you tried to execute any of the tests in the test suite? Do they crash as well?
You seem to be using VS 2013 for everything but just to clarify, are you using VS 2013 for both log4cplus builds and your application builds?
None of the tests compile. VS2013 for both. The free version of VS2013 is available at https://www.visualstudio.com/en-us/news/vs2013-community-vs.aspx