Solved

Segmentation fault at bzero

Posted on 2006-11-13
7
819 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

867 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

16 Experts available now in Live!

Get 1:1 Help Now