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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:59:42+00:00 2026-05-26T01:59:42+00:00

I have run gdb, as my code show segfault. I understand that the code

  • 0

I have run gdb, as my code show segfault. I understand that the code that give the error is

210         if (colour_s->colorlist.colorlist_id == 1)
(gdb) print colour_s
$1 = (car_colour_list_t_slot *) 0x21
(gdb) print colorlist
$2 = (car_colour_list_t *) 0x12d1a80
(gdb) print colour_s->colorlist
Cannot access memory at address 0x21

typedef struct {
    int colorlist_id;
} car_colour_list_t;


typedef struct _car_colour_list_t_slot {
    car_colour_list_t colorlist;
    struct _car_colour_list_t_slot *next, *prev;
} car_colour_list_t_slot;


car_colour_list_t_slot *colour_s;
colour_s = (car_colour_list_t_slot *)malloc(sizeof(car_colour_list_t_slot));
car_colour_list_t *colorlist;
colorlist = (car_colour_list_t *)malloc(sizeof(car_colour_list_t));

I have already assigned those pointers memory, but when I tried to print colour_s->colorlist it fails (can not access memory at address 0x21)

Can anyone understand why this happens, although I have already assign memory to each poitner?

Thank you

  • 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-26T01:59:43+00:00Added an answer on May 26, 2026 at 1:59 am

    The colour_s pointer is definitely invalid. There is no doubt about it. GDB is simply informing you of this fact. (Any pointer near 0x0 is invalid, and any pointer with a residue modulo 4 is invalid for your structure.) The malloc function will never return 0x21.

    There are lots of ways your program can do this. They boil down to two basic types of errors in your program:

    • colour_s was not initialized.
    • colour_s was initialized, but it was accidentally overwritten by an error in a different part of your code.
    • there is an error in GDB or your compiler (not worth considering)

    Run your program with Valgrind or set a watchpoint on colour_s. These will help you discover where the error is in your code.

    As an alternative exercise, see if you can find the error just by reading your code, without running it. Read carefully. This kind of exercise will make you a better programmer.

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

Sidebar

Related Questions

I have been debugging in GDB (C code). The issue is if I run
I have run into a bit of a tricky problem in some C++ code,
I have run into an issue with WPF and Commands that are bound to
I have run into a situation where I want to ensure that a compound
I've run into some problems debugging a multi-threaded process using GDB. I have a
I have some code, that I'm currently porting from OS X to Linux (console
I seem to have some kind of multithreading bug in my code that makes
I am new to debugging an assembly code under gdb.Therefore, I have some question;
I have a simple piece of assembly code that works correctly on Mac OS
I have run across an XML Schema with the following definition: <xs:simpleType name=ClassRankType> <xs:restriction

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.