|
Boost Users : |
Subject: [Boost-users] [Filesystem] String corruption in path in V3 and Boost 1.44
From: Will Watts (willw_at_[hidden])
Date: 2010-09-22 06:15:54
I have the following method:
boost::filesystem::path Sfw::CFolders::GetModulePath()
{
char buffer[MAX_PATH+1];
chknzapi (GetModuleFileName (NULL, buffer, MAX_PATH));
return buffer; // Converted to fs::path object
}
Under Boost 1.43 this seemed to work fine. The char buffer is used to create a temporary path object, which is returned by value from the function.
But when I upgraded to Boost 1.44, and recompiled with BOOST_FILESYSTEM_VERSION=3 and BOOST_FILESYSTEM_NO_DEPRECATED defined, I found that, although it still compiled, it no longer worked properly.
Specifically, the contents of the path becomes corrupted to garbage. I got the impression that the path object returned, instead of containing a copy of the character string, retains a pointer to the original char buffer[] on the stack - which is naturally trampled on by subsequent activity.
Changing the function to this:
boost::filesystem::path Sfw::CFolders::GetModulePath()
{
char buffer[MAX_PATH+1];
chknzapi (GetModuleFileName (NULL, buffer, MAX_PATH));
return string(buffer);
}
seems to fix the problem.
I admit I have not examined the code for the filesystem::path class - I am roundly intimidated by Boost code.
Is my problem caused by a bug in the library introduced by 1.44, or am I just using the library incorrectly? Is my fixed version acceptable, or am I just 'lucky' that it seems to work?
The environment is Visual C++ 10, targetting 32-bit. As well as the #defines listed above, I have also got BOOST_NO_RVALUE_REFERENCES defined, to address a compilation problem with another Boost library.
Regards
Will
PS: Apologies if this is a dupe. I attempted to post this via an NNTP account, which I believed had the correct rights, but didn't seem to do the business.
Applied Industrial Systems is a limited company registered in England.
Registered number: 2552260. Registered office: 11 Riverview,
The Embankment Business Park, Stockport, Cheshire SK4 3GN.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net