Segfault for who knows what reason

This is a discussion on Segfault for who knows what reason within the C Programming forums, part of the General Programming Boards category; Hi, I'm working on an assignment that measures internal fragmentation of files (and size distribution) starting at a base directory. ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    11

    Segfault for who knows what reason

    Hi,

    I'm working on an assignment that measures internal fragmentation of files (and size distribution) starting at a base directory. So far, I'm just working with a single directory gathering statistics, and everything seems to be working out great, except, for some reason, when i added a new integer variable, it changed to the following:

    Scanning Directory '.'
    Retrieving info about: '.'
    Segmentation fault


    but initially looked like:

    Scanning Directory '.'
    Retrieving info about: '.' done.
    Retrieving info about: '..' done.
    Retrieving info about: 'main.c'
    Block size: 2; Category: 1; done.
    Percentage of files 1 block or less = 66%
    Illegal instruction


    Sometimes it displays at the end of the longer one a Segfault as well, but it's appearing after everything has executed.

    Any idea why this is happening? I'm working with the dirent struct and using readdir() and lstat() to get file information (requirements for the assignment)

    I ran it through gdb, but it just gives me a hex value and doesn't tell me where the segfault is occurring...

    thanks,
    Phlook

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    you should show the code
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    Removed
    Last edited by phlook; 03-14-2009 at 11:32 PM. Reason: code for assignment

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    you are passing to lstat not initialized pointer. What struct will the function fill?

    it should be

    Code:
    struct stat buf;
    lstat(dp->d_name,&buf);
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    beautiful! thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. atoi produces segfault
    By someprogr in forum C Programming
    Replies: 13
    Last Post: 11-04-2008, 12:37 PM
  2. malloc() resulting in a SegFault?!
    By cipher82 in forum C++ Programming
    Replies: 21
    Last Post: 09-18-2008, 11:24 AM
  3. use of printf prevents segfault!
    By MK27 in forum C Programming
    Replies: 31
    Last Post: 08-27-2008, 12:38 PM
  4. weird segfault in fgets in process
    By 911help in forum C Programming
    Replies: 10
    Last Post: 12-29-2007, 12:51 PM
  5. Another reason to not like America
    By Shiro in forum A Brief History of Cprogramming.com
    Replies: 129
    Last Post: 06-13-2002, 12:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21