1

I successfully compile the program at the Question How to pass a string type path to boost::filesystem:path's constructor? However, the output result shows more than the expected one.

Folder status: 0
Bus error: 10

The first line is the only expected result. I do not understand why the second one comes?

I get the following debug information by gdb:

(gdb) run
Starting program: /Users/ZL/Desktop/mtfsg 
Reading symbols for shared libraries ++++............................. done
Folder status: 0

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00007fff5fc005a0
0x00007fff9046aab7 in std::basic_string<char, std::char_traits<char>, 
std::allocator<char>>::~basic_string ()
(gdb) bt
#0  0x00007fff9046aab7 in std::basic_string<char, std::char_traits<char>, 
std::allocator<char> >::~basic_string ()
#1  0x00000001000018dd in main () at m.cpp:12
4
  • 1
    It's a bug. You'll need to debug to find out what the issue is. Run the program under your favorite debugger. Commented Aug 20, 2012 at 7:37
  • But any suggestion on how to debug under the g++ command line compiler? Or under the Mac OS X? I have little experience on debugging in C++. Commented Aug 21, 2012 at 1:00
  • Run the program under gbd. When it crashes, type where. Then you use up and down to navigate the stack frames and print to see the values of things. Commented Aug 21, 2012 at 1:03
  • I get the debug information by gdb. Please see the added information on the question area. Commented Aug 21, 2012 at 2:16

1 Answer 1

0

Finally, I find the point of the error in my code:

In class OSxFS (tfs.h file), the method "string ShowStatus()" has an incorrect return type "string". This method does not need a return value since its functionality is only to print the directory (folder) status on the screen. So, I replace the "string" return type by "void".

The original code of method "string ShowStatus()"

**string** ShowStatus()
    {
      boost::filesystem::file_status folderStatus =
       boost::filesystem::status(mFolderPath);

      try
      {
        cout<<"Folder status: "<<boost::filesystem::is_directory(folderStatus)<<endl;
      }
      catch(boost::filesystem::filesystem_error &e)
      {
        cerr<<"Error captured: "<<e.what()<<endl;
      }
    }

The correct code:

**void** ShowStatus()
    {
      boost::filesystem::file_status folderStatus = 
       boost::filesystem::status(mFolderPath);

      try
      {
        cout<<"Folder status: "<<boost::filesystem::is_directory(folderStatus)<<endl;
      }
      catch(boost::filesystem::filesystem_error &e)
      {
        cerr<<"Error captured: "<<e.what()<<endl;
      }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.