Application crash when using substr on AIX

This is a discussion on Application crash when using substr on AIX within the C++ Programming forums, part of the General Programming Boards category; Hi, I am trying to use substr on a large string, 20-30MB. The same code compiles and run on other ...

  1. #1
    niv
    niv is offline
    Registered User
    Join Date
    May 2011
    Posts
    4

    Application crash when using substr on AIX

    Hi,

    I am trying to use substr on a large string, 20-30MB.
    The same code compiles and run on other platforms (linux, HP, Windows) with no problem, but when running on AIX 6.1, it crashes.

    Seems like a memory problem, maybe process memory limit was reached, how can I find out?
    When I sorround the substr call with a try/catch I catch the exception, however I use catch (...) as I'm not sure what exception should be caught, and I would like to print it so maybe it will give me a clue.

    Thanks.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Maybe we could help you if we saw the actual code.
    Anything that STL throws inherits std::exception.
    I never put signature, but I decided to make an exception.

  3. #3
    niv
    niv is offline
    Registered User
    Join Date
    May 2011
    Posts
    4
    Quote Originally Posted by kmdv View Post
    Maybe we could help you if we saw the actual code.
    Anything that STL throws inherits std::exception.
    Here is the code:

    Code:
    string double_newline("\r\n\r\n");
    string::size_type reply_starts_at = reply.find(double_newline);
    if (reply_starts_at == string::npos) 
    {
      throw http_exception("http_connection::parse_reply(): unable to determine reply start");
    }
    
    return reply.substr(reply_starts_at + double_newline.length());
    Thanks.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    The code is correct. Keep in mind that something completely different and irrevelant may cause this crash. If the strings are really long, check string::max_size() but I doubt it will return something below your lengths. If you cannot catch an exception with (...) this is not a C++ exception. This part is correct, even if something went wrong it would throw a software, catchable exception (std::bad_alloc or std::out_of_range).

    EDIT:
    If you do catch the exception, just use:
    Code:
    try
    {
    }
    catch (const std::exception& e)
    {
        std::cout << e.what() << std::endl;
    }
    Last edited by kmdv; 05-26-2011 at 03:42 AM.
    I never put signature, but I decided to make an exception.

  5. #5
    niv
    niv is offline
    Registered User
    Join Date
    May 2011
    Posts
    4
    Okay, I was able to catch the exception, it is "bad allocation".
    Also, reply.max_size() returned "-3".

    Any idea?

  6. #6
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    You implicitly converted max_size() to a signed integer type, hence -3.
    You are running out of memory so you need a different approach for storing part of this string (for example, using index and length variables).
    I never put signature, but I decided to make an exception.

  7. #7
    niv
    niv is offline
    Registered User
    Join Date
    May 2011
    Posts
    4
    Indeed, when I used %u I got 4,294,967,293 for max_size() which is a lot more than I need.
    If the process is running out of memory, maybe I can adjust that?
    This small piece of code is part of a very large implementation, it is not possible rigth now to make changes to the way we process the response, i have to figure a way to make it work =\

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Yet another problem with substr
    By manasij7479 in forum C++ Programming
    Replies: 12
    Last Post: 05-26-2011, 12:43 PM
  2. substr problems
    By spudval in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2007, 05:48 AM
  3. Substr
    By mhenderson in forum C Programming
    Replies: 4
    Last Post: 08-04-2006, 01:44 AM
  4. using char with .substr()
    By sunburnbyRA in forum Windows Programming
    Replies: 2
    Last Post: 02-24-2004, 08:10 AM
  5. using substr
    By riley03 in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2002, 05:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21