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 4323924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:03:52+00:00 2026-05-21T09:03:52+00:00

I have an error with an assignment, of which I get a seg fault,

  • 0

I have an error with an assignment, of which I get a seg fault, that when reading the core dump gives this:

#0  0xb781eb27 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const () from /usr/lib/libstdc++.so.6

This is the code snippet I believe it is referring to.

bool flightmap::GetNextCity(int& index, int& nextCity){
    bool success = false;
    flightRec tmp, tmp2;
    for (int i = nextCity; (!success) && (i < size); i++)
    {//if Citytmp goes over size, we never found it
        tmp.DestinationCity = GetCityName(i);
        tmp2 = map[index].Retrieve(tmp,success);
    }//end for loop
    if (success)
    {
        nextCity = GetCityNumber(tmp2.DestinationCity);
    }//end if
    return success;
}

Here is the Retrieve function:

flightRec sortedListClass::Retrieve(flightRec& input, bool& success) const{
    nodeptr curr;
    flightRec tmp;
    curr = head;
    if (head == NULL)
    {//If the list is empty
        std::cout << "List empty, operation not preformed" << std::endl;
        success = false;
    }
    /*LINE 167*/ while ((curr!=NULL)&&(!(curr->DestinationCity==input.DestinationCity))) //<- THIS IS LINE 167
    {//Here we first check if curr points to NULL, then we see if DesinationCity and Origin are not yet found.
        curr=curr->ptr;
    }
    if ((curr->DestinationCity==input.DestinationCity))
    {//If we found it, then let's return it...
        tmp.DestinationCity=curr->DestinationCity;
        //tmp.Origin=curr->Origin;
        tmp.flightnumber=curr->flightnumber;
        tmp.cost=curr->cost;
        success = true;
        return tmp;
    }
    else //We didn't and then...damn.
    {
        //std::cout << "Can't find flight to " << input.DestinationCity << std::endl;
        success = false;
    }
}

flightRec:

struct flightRec{
    std::string Origin;
    int flightnumber;
    float cost;
    std::string DestinationCity;
    bool operator <(const flightRec& rhs) const;
    bool operator ==(const flightRec& rhs) const;
    flightRec* ptr;
};
typedef flightRec* nodeptr;

flightMap.h

#ifndef FLIGHTMAP_H
#define FLIGHTMAP_H
#include "sortedListClass.h"
#include "stackClass.h"
#include <fstream>
#include <cstdio>

class flightmap {
public:
    flightmap();
    flightmap(const flightmap& orig);
    virtual ~flightmap();
    void readcities (std::ifstream& in);
    void readflights (std::ifstream& in);
    void display ();
    void isPath (int& in, int& out);
    void MarkVisited (int& index);
    bool IsVisited (int& index);
    void UnvisitAll ();
    bool GetNextCity (int& index, int& nextCity);
    int GetCityNumber(std::string& city);
    std::string GetCityName(int& index);
private:
    int size;
    sortedListClass* map;
    std::string* origin;
    bool* visited;
};

#endif

After typing bt into gdb this is what the output was:

#0  0xb7f4eb27 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const () from /usr/lib/libstdc++.so.6
#1  0x0804a407 in std::operator==<char> (__lhs=..., __rhs=...) at /usr/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c++/4.5.2/bits/basic_string.h:2345
#2  0x0804ab32 in sortedListClass::Retrieve (this=0x8053468, input=..., success=@0xbffff0a3) at sortedListClass.cpp:167
#3  0x0804a1ff in flightmap::GetNextCity (this=0xbffff4dc, index=@0xbffff108, nextCity=@0xbffff104) at flightMap.cpp:197
#4  0x08049ba7 in flightmap::isPath (this=0xbffff4dc, in=@0xbffff164, out=@0xbffff160) at flightMap.cpp:110
#5  0x08049314 in FindPath (datafile=..., map=...) at ola6.cpp:51
#6  0x08049190 in main (argc=2, argv=0xbffff5b4) at ola6.cpp:35
  • 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-05-21T09:03:53+00:00Added an answer on May 21, 2026 at 9:03 am

    bt is correct for a backtrace. You can see there the error starts in sortedListClass::Retrieve line 167. The next entry in the backtrace (working back up to #0) is for operator ==, which means the == on line 167 is the cause of the crash.

    There are a few == calls in the code you posted, so if you can edit your post and indicate which line is line 167 we can diagnose further.

    Update after line number was added:

    This is just a guess, but it’s possible you have forgotten to set the ptr member to NULL at some point earlier in the program, so that in that loop around line 167-168 curr eventually points at a random memory location, causing the crash. It’s also possible that the object at that memory location has since been freed, but ptr hasn’t been updated and is pointing at the now deleted object. Check your code closely where you allocate new flightRec objects and make sure you are always setting ptr correctly.

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

Sidebar

Related Questions

This is the error that I get Linker error undefined reference to RationalNumber::RationalNumber(int, int)
Hello i have error when i am forwarding page without parameter. that is happen
I experience strange problem. We have error handling in global.asax that would redirect user
I have this error when trying to generate the meta model with JOOQ: org.jooq.exception.DataAccessException:
i have an error in this code NSString *str = @above string; //load above
I have a detail view that includes three UIButtons, each of which pushes a
I have Assignment due in which i'm stuck on a question. Add a Sales
I have encountered an error which has stumped me for many days now. A
I am working on a shopping cart assignment for that I have created a
I have this loop which generates a vector Diff. How do I place the

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.