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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:06:08+00:00 2026-06-01T07:06:08+00:00

Why am I getting segmentation fault? I ran it with gdb and it crashing

  • 0

Why am I getting segmentation fault? I ran it with gdb and it crashing attail_playlist -> next = p_playlist;.

struct playlist_ {
  int album;
  int track_num;
  struct playlist_ *next;
};
typedef struct playlist_  playlists;

struct users_ {
  int user_ID;
  struct playlist_ *playlist;
  struct users_ *next;
};
typedef struct users_ users;

int add_playlist(users *user_pointer,int user_ID,int album_ID,int track_num){

  playlists *head_playlist,*tail_playlist,*curr_playlist,*p_playlist;
  users *curr_users;

  curr_users = user_pointer;
  while(curr_users){

    /* Find this user in link list */
    if(curr_users -> user_ID == user_ID){
      curr_playlist = curr_users -> playlist;

      /* Check if playlist is empty for this user if so, update the empty list*/
      if(curr_playlist -> album == NULL && curr_playlist -> track_num == NULL){
        curr_playlist -> album = album_ID;
        curr_playlist -> track_num = track_num;
        curr_playlist -> next = NULL;
      }else{

        /*Creates a new playlist node with the request album and track number*/
        p_playlist = (playlists *)malloc(sizeof(playlists ));
        p_playlist -> album = album_ID;
        p_playlist -> track_num = track_num;
        p_playlist -> next = NULL;

        /*Traverse Playlist, find the tail node*/
        for(curr_playlist = curr_users -> playlist; curr_playlist -> next; curr_playlist = curr_playlist -> next){

          /*Adds the playlist at the end*/

          tail_playlist = curr_playlist;
        };

        tail_playlist -> next = p_playlist;
      }
      break;
    }
    curr_users = curr_users -> next;
  }
}
  • 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-01T07:06:09+00:00Added an answer on June 1, 2026 at 7:06 am

    You have

    for (curr_playlist = curr_users -> playlist; curr_playlist -> next; curr_playlist = cure_playlist -> next){
        tail_playlist = curr_playlist;
    }
    

    What happens if curr_playlist -> next is NULL on the first iteration? Then tail_playlist is never set, but it is dereferenced on the next line:

    tail_playlist -> next = p_playlist;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting a segmentation fault for the following code. Please advise. struct columns { char*
Whats wrong with this?I am getting segmentation fault during runtime. int size; scanf(%d,&size); int
Possible Duplicate: Getting Segmentation Fault // reverse a string #include`<stdlib.h>` #include`<stdio.h>` #include`<string.h>` #include`<math.h>` int
i am getting a segmentation fault while trying to call the addEdge(int, int) method.
Im getting a segmentation fault when trying to display an element of type (int)
I am getting segmentation fault in this code but i cant figure out why.
I'm getting a segmentation fault the first time I call malloc() after I protect
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 have a process in Linux that's getting a segmentation fault. How can I

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.