Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:16:18+00:00 2026-06-18T09:16:18+00:00

I have a pretty long program with multiple classes so I wont post it

  • 0

I have a pretty long program with multiple classes so I wont post it unless you need it. But after main returns I get a segmentation fault.

Using GDB I can see this error:

program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000002300103be8
0x00000001000035cc in std::_Rb_tree<std::string, std::string, std::_Identity, std::less,     std::allocator >::_S_right (__x=0x2300103bd0) at stl_tree.h:512
512       { return static_cast<_Link_type>(__x->_M_right); }

I’m very new to C++ so this just looks like gibberish to me. Can anyone decipher it? It looks like one of my STL containers might be causing the issue? Any advice on how to fix it?

EDIT With Code:

Okay so I’ve isolated it down to somewhere in this if block of main, It was the last thing I wrote and when I comment it out the program runs fine.

else if(line.substr(0, 3) == "Rec") // Recieve 
  {       
      istringstream ss(line);
      string s; // output string
      string upc;
      string name;
      int amount;
      int count = 0;
      while(ss >> s) // go through the words in the line
      {
          count++;
          if(count == 2)
            upc = s;
          else if (count == 3)
          {
            istringstream isa(line.substr(20, 2));
            isa >> amount; //Parse the amount
          }
          else if (count == 4)
            name = s;
      }


      warehouses.find(name)->second.receive_food(upc, amount); //add the food to the warehouse

  }

To clarify the line we are looking at is in this format:

Receive: 0984523912 7 Tacoma

warehouses is a map : map<string, a4::warehouse> warehouses; //all the warehouses.

Here is the warehouse receive method

void warehouse::receive_food(std::string upc, int amount)
{
    items.find(upc)->second.receive(amount);

    todays_transactions = todays_transactions + amount;
}

Where items is std::map<std::string, food> items;

And Finally the Food Receive method

void food::receive(int amount)
{
    crates.push_back(crate(life, amount));
}

Where crates is std::list<crate> crates;

And a crate is

    class crate
{
    public:
        crate(int, int);
        ~crate();
        int life;
        int quantity;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:16:19+00:00Added an answer on June 18, 2026 at 9:16 am

    Looks like a memory corruption. _Rb_tree suggests that the error has something to do with std::map which is usually implemented as a red-black tree. It is hard to say more without seeing code. I recommend using Valgrind to debug the issue.

    After looking at the code that you’ve posted in the update, I think that the problem is that you don’t check whether warehouses.find(name) returns a valid iterator. It can return map::end() if the key is not found.

    Add a check:

      map<string, a4::warehouse>::iterator it = warehouses.find(name);
      if (it != warehouses.end())
        it->second.receive_food(upc, amount);
      else ; // handle the case of a missing key
    

    and similar checks for other calls to map::find.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that is pretty long. Any easy way to undo
I have a list of user identifiers which are pretty long. The identifiers may
I have looped data from mysql, and it's a pretty long list. What's the
I have built a PHP calendar system and have pretty much everything done but
I have a pretty simple trigger: CREATE OR REPLACE FUNCTION f_log_datei() RETURNS TRIGGER AS
I have a pretty long running job, which runs for several minutes and then
I have a C-programm (a lot of numerics and too long to post) which
I have a program that runs fine in DEBUG mode but in RELEASE mode
In my embedded c program I have a struct: struct var{ unsigned long value;
I need to send some pretty long strings from a flash application to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.