[Log4cplus-devel] [ log4cplus-Support Requests-3570926 ] Buffer overrun with Hello World example
Logging Framework for C++
Brought to you by:
wilx
From: SourceForge.net <no...@so...> - 2012-09-24 13:43:16
|
Support Requests item #3570926, was opened at 2012-09-22 21:00 Message generated for change (Comment added) made by wilx You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=429074&aid=3570926&group_id=40830 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: v1.1.0 Status: Pending Priority: 5 Private: No Submitted By: https://www.google.com/accounts () Assigned to: Václav Zeman (wilx) Summary: Buffer overrun with Hello World example Initial Comment: I'm attempting to use logforcplus in my first c++ project in over ten years, so please assume I might have done something simple wrong. I cannot get the Hello World example working without buffer overrun errors. I downloaded log4cplus-1.1.0-rc10. I used VS2010 to open the sln in msvc10 folder, set log4cplus project to Debug_Unicode, and compile. I created a new project directory log4cplusDemo, with subdirectories bin, include, lib, and src. "Bin" contains log4cplusUD.dll and pdb, "include" contains include\log4cplus, and "lib" contains log4cplusUD.lib. I used VS2012 to create a new C++ Win32 exe in the "src" directory. Project Properties..Configuration Properties..General..Character Set is Unicode. Configuration Properties..C/C++..General..Additional Include Directories has a reference to "include". Configuration Properties..Linker..General..Additional Library Directories has a reference to "lib". Linker..Input..Additional Dependencies has a reference to "log4cplusUD.lib". Trying the hello world example resulted in a buffer overrun error. I was able to expand the macro and isolate the failing line. Replacing it with a hardcoded string works, but causes a buffer overrun when main() exits. What am I doing wrong? #include "stdafx.h" #include <log4cplus/logger.h> #include <log4cplus/loggingmacros.h> #include <log4cplus/configurator.h> using namespace log4cplus; int _tmain(int argc, _TCHAR* argv[]) { BasicConfigurator config; config.configure(); Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("main")); // This causes buffer overrun on this line // LOG4CPLUS_WARN(logger, LOG4CPLUS_TEXT("Hello, World!")); // This works (by commenting out original call to .str() and sending a string directly), // but buffer overflow error occurs on return statement. do { log4cplus::Logger const & _l = log4cplus::detail::macros_get_logger (logger); // I can't figure out this macro, and it's just checking if the desired log level is enabled so comment out // if (LOG4CPLUS_MACRO_LOGLEVEL_PRED ( //_l.isEnabledFor (log4cplus::logLevel), logLevel)) { log4cplus::tostringstream & _log4cplus_buf = log4cplus::detail::get_macro_body_oss (); _log4cplus_buf << LOG4CPLUS_TEXT("Hello, World!"); log4cplus::detail::macro_forced_log (_l, log4cplus::WARN_LOG_LEVEL, // This causes buffer overflow error, replace with string directly //_log4cplus_buf.str(), L"Hello world!", __FILE__, __LINE__, LOG4CPLUS_MACRO_FUNCTION () ); //} } while (0); getchar(); return 0; } ---------------------------------------------------------------------- >Comment By: Václav Zeman (wilx) Date: 2012-09-24 06:43 Message: I have tried to reproduce your problem with Visual Studio 2012 using trunk source (because there were not any changes that could possibly influence the outcome of the minimal BasicConfigurator test). I cannot reproduce it. I have tried a performance_test and thread_test in their original form. Then I have removed the source in main.cxx of thread_test and pasted in yours. It still works fine. My guess is that you are still mixing stuff built with VS 2010 and VS 2012. Please double check that the log4cplusUD.{dll,lib} etc. files are really built by the same Visual Studio as your test/application. ---------------------------------------------------------------------- Comment By: Václav Zeman (wilx) Date: 2012-09-23 22:42 Message: The code should work in both VS 2010 and VS 2012 but mixing binaries from different VS versions is not possible. I will try to take a look at the problem but first I will have to get VS 2012. ---------------------------------------------------------------------- Comment By: https://www.google.com/accounts () Date: 2012-09-23 20:10 Message: Building log4cplus in VS 2012 didn't help (yes, it does open the VS2010 solution just fine). I moved hello world to VS 2010 and it works, even with the VS 2012 compiled log4cplus, which I thought was interesting. After digging through the project options for VS 2012 hello world, I found Configuration Properties..General..Platform Toolkit. It was set to VS 2012 (v110), setting it to VS 2010 (v100) made the buffer overrun disappear, and I was able run hello world without any macro hacking. Unfortunately this means choosing between using the new C++11 libraries or log4cplus in my project. I flipped it back to v110 and experimented some. The buffer overrun at the end of main() in the code I first posted is actually coming from the declaration of BasicConfigurator. Using the v110 toolset, simply doing this: int _tmain(int argc, _TCHAR* argv[]) { BasicConfigurator config; return 0; } causes the overrun at the return statement. I thought you might want to know for when you start adding C++11 support. Thanks for your time and advice on this, I really appreciate it. Your project looked great and I'm disappointed I'm not going to be able to use it. ---------------------------------------------------------------------- Comment By: Václav Zeman (wilx) Date: 2012-09-22 22:48 Message: AFAIK, you cannot do that. Trying to combine VS 2010 built library and VS 2012 compiled executable, in general, does not work. Build log4cplus using VS 2012 as well. I have not tried but there should be no problem opening the VS 2010 solution in VS 2012 and building it there. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=429074&aid=3570926&group_id=40830 |