Solved

Segmentation fault at bzero

Posted on 2006-11-13
7
894 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

707 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