Thread: Segfault for who knows what reason

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you should show the code
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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);
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 01: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, 01: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