Solved

Segmentation fault at bzero

Posted on 2006-11-13
7
804 Views
Last Modified: 2008-03-03
      struct direntry{
            char filename[FILENAME_LEN];
            char ext[EXT_LEN];
            char attr;
            char resv[RESV_LEN];
            char datetime[DT_LEN];
            char startCluster[SCLUSTER_LEN];
            char filesize[FILESIZE_LEN];
      } *dir_entry;
bzero(dir_entry,sizeof(struct direntry));

At the bzero I get segmentation fault, what am I wrong and how to correct it?
0
Comment
Question by:william007
7 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 17934457
you did not initialize dir_entry to point to valid memory
you may want
dir_entry = calloc(sizeof(struct direntry));
0
 
LVL 86

Expert Comment

by:jkr
ID: 17935414
Or did you mean to

struct direntry de;

bzero(&de,sizeof(struct direntry));

?
0
 
LVL 1

Assisted Solution

by:Ashwini_pandey
Ashwini_pandey earned 100 total points
ID: 17936323
1.dir_entry is a pointer that is not pointing to any valid memory location.
accessing any struct member using this dir_entry may  cause segmentation fault.
2.plaese tell what bzero(dir_entry,sizeof(struct direntry)) is intended for ?

 
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:numansiddique
ID: 17936875
@Ashwini_pandey

bzero initializes the memory area of the structure to zero ( or NULL).  its like using memset as memset((void *)dir_entry,0,sizeof(struct direntry));
0
 
LVL 1

Expert Comment

by:Ashwini_pandey
ID: 17963076
@numansiddique
" bzero initializes the memory area of the structure to zero ( or NULL).  its like using memset as memset((void *)dir_entry,0,sizeof(struct direntry))"

You must allocate memory to dir_entry using statement before calling bzero function
dir_entry = (struct direntry *)malloc(sizeof(struct direntry));


0
 
LVL 9

Author Comment

by:william007
ID: 17970877
Thanks=)
0
 
LVL 2

Expert Comment

by:numansiddique
ID: 17970998
@Ashwini_pandey
thats r8, i agree with you
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now