Solved

Segmentation fault at bzero

Posted on 2006-11-13
7
833 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

823 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