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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:57:59+00:00 2026-06-06T18:57:59+00:00

I am getting a segmentation fault and I cannot figure out why. I have

  • 0

I am getting a segmentation fault and I cannot figure out why. I have a global TcpClient object that has a pointer to an Agent object. I am trying to access the agent pointer in a function when the segmentation fault occurs. In main, I have the cout statements before and after I set the agent member in TcpClient and both statements give me the same address.

TcpClient client((char*)PORT);
Agent* agent = new Agent;

int main(int argc, char* args[]) {
    //initialization code for agent's members
    cout<<"\nagent: "<<agent;
    client.setAgent(agent); //set it here
    cout<<"\nclient agent: "<<client.getAgent()<<"\n";
}

Then I have this function in TcpClient that gets called during the run (after setting the agent of course). I get the segmentation fault when I try to access agent. I have a cout statement in the beginning that tells me agent is 0x0.

void TcpClient::getCommand(char* command) { 
    std::cout<<"\nagent: "<<agent;

}

The setAgent is a typical setter –

void TcpClient::setAgent(Agent*& a) {agent = a;}



class Agent;
class TcpClient {
    //functions and stuff
private:
    Agent* agent;
};

The agent member isn’t accessed anywhere else in the code. The only thing I can come up with is that there is something about the TcpClient object being global that could make this happen, but I do not know what. Am I right about this? Any help is appreciated.

When I run the code, the debugger says –

Program received signal SIGSEGV, Segmentation fault.
__memcpy_ssse3_rep () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S:1454
1454    ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S: No such file or directory.
    in ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S
(gdb) back
#0  __memcpy_ssse3_rep ()
    at ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S:1454
#1  0x08049c52 in Agent::setGoal (this=0x0, g=...) at agent.cpp:33
#2  0x0805075e in TcpClient::getCommand (this=0x805aac8, 
command=0xbffff18d "1 3 1\n") at tcpclient.cpp:80
#3  0x08050b8d in TcpClient::communicate (this=0x805aac8) at tcpclient.cpp:153
#4  0x0804e0f8 in main (argc=1, args=0xbffff3f4) at mainclient.cpp:119
  • 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-06T18:58:00+00:00Added an answer on June 6, 2026 at 6:58 pm

    I have a function called communicate (which just lets server and client talk to each other) that calls the getCommand function I posted above. Right before I call getCommand, there was a memset call for a local char*. All I did was remove that line and the segmentation fault went away.

    Thanks for help everyone.

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

Sidebar

Related Questions

I am getting a segmentation fault on my getaddrinfo call and cannot figure out
I am getting segmentation fault in this code but i cant figure out why.
I have a process in Linux that's getting a segmentation fault. How can I
I'm getting a segmentation fault trying to compile the following code. My question is,
I'm trying to delete whole linked list but getting segmentation fault and not able
I have a C program below written on UNIX. I am getting segmentation fault.
I've a 'C' program which has encountered a strange problem.. I'm getting segmentation fault
I am getting segmentation fault while deleting an objected, being referenced by the pointer
Trying to copy a char *str to char c[] but getting segmentation fault or
I´m getting a segmentation fault with a pointer when it´s declared as local. 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.