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

  • Home
  • SEARCH
  • 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 8405009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:44:31+00:00 2026-06-09T22:44:31+00:00

I am getting a segmentation fault error when I try to run my program

  • 0

I am getting a segmentation fault error when I try to run my program with arguments. Now I’ve run it through GDB and found the line in question and it looks like this:

*dstip = (*optarg);

the prototype is:

char *dstip;

and finally it is being called in this line:

char *filter = ("ip dest host %s", dstip);

Now looking back at it I’m not surprised it doesn’t work as it looks… wrong frankly, and the problem is solved by removing these lines (and altering the filter text) completely. However, I need the IPv4 address being inputed to show up in the error message filter will be used in, and being useless with pointers and having tried different things back and forth I can’t get it right. That is, I only get warning initialization makes pointer from integer and the like… what to do?

  • 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-09T22:44:32+00:00Added an answer on June 9, 2026 at 10:44 pm

    The statement

    *dstip = (*optarg);
    

    doesn’t set dstip to point to optarg. Instead it sets the first character of what dstip points to to the same value as the first character that optarg points to. I.e. it’s the same as

    dstip[0] = optarg[0];
    

    As dstip is an uninitialized pointer, you change an unallocated area in memory and that will lead to weird things happening.

    Also, the expression

    ("ip dest host %s", dstip)
    

    doesn’t do what you think it does, at least if you think it will return a formatted string. What it really does is using the comma operator, which evaluates the expressions on both sides of the comma, but return only the result of the expression of the right side of the comma.

    • 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 error when running my program in GCC. This
I am getting a segmentation fault error when I run this code. I don't
I'm getting this error: Program received signal SIGSEGV, Segmentation fault. 0x0000000000407265 in Quadtree::deeper (this=0x7fffffffe430,
I am getting the following error message: Program received signal SIGSEGV, Segmentation fault. 0x08048ff3
I am getting a Segmentation fault (core dumped) run-time error with the following code:
Why am I getting segmentation fault? I ran it with gdb and it crashing
I am getting a segmentation fault from bash when I try to SSH to
I'm getting a segmentation fault everytime i want to run this code : from
i seem to be getting this error everytime i try to run my android
I've a 'C' program which has encountered a strange problem.. I'm getting segmentation fault

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.