A libdc1394 library function is causing a segmentation fault

This is a discussion on A libdc1394 library function is causing a segmentation fault within the Linux Programming forums, part of the Platform Specific Boards category; Ok, here is an odd problem: I have found that the function dc1394_dma_setup_capture is causing a segmentation fault when I ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    33

    A libdc1394 library function is causing a segmentation fault

    Ok, here is an odd problem:

    I have found that the function dc1394_dma_setup_capture is causing a segmentation fault when I am running my code. The problem is that I did not write this function, rather it is part of libdc1394, and 1394 firewire package I obtained through YaST.

    I have found dc1394_dma_setup_capture in the header /usr/include/libdc1394/dc1394_control.h, but I am not sure where the rest of the function is located, which makes it rather difficult to troubleshoot.

    Does anyone have any idea what is the cause of the segmentation fault or how to fix it?

    Thanks for the help.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, the question is, are you passing the right parameters to the function, in the right way?

    If I do:
    Code:
    int main() {
       char *p = (char *)0xdeadbeef;
       char str[100];
       memcpy(p, str, sizeof(str));
       return 0;
    }
    I can almost guarantee that the code will crash in memcpy (or some subfunction of memcpy) - this doesn't mean that memcpy is broken, does it? The pointer I passed in is bad [not guaranteed, but in user-mode on a 32-bit machine it almost certainly is, as it would be kernel address space, which is not user-writable].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    Thanks for the advice. I will see if I can change the input arguments to get it to work.

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    Ok, I found out that my declaration of dc1394_dma_setup_capture uses a different number of input arguments than appear in the prototype that is found in libdc1394. However, when I change the declaration of dc1394_dma_setup_capture in my code to match that of the prototype, gcc tells me that I am using too many arguments.

    Have any idea why this might occur?

    Thanks.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Because, if you call the function according to your wrong prototype, you pass it a certain number of arguments. If you then change the prototype but not the call (as apparently you have done), obviously the two will no longer match.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    Actually, I think I have found out what is going wrong. I have two copies of libdc1394 currently installed, one in /usr/include, and a second in /usr/local/include. Apparently my program matches the prototype in /usr/local/include, and that is the one that the compiler is currently using. So it seems my function and prototype does match, its just to a library in a different location. I wonder if having the two different libraries is causing the fault.

    Any thoughts?

    Thanks.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Possibly. Having two versions of the library is a good path to trouble.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    Ok, by removing the duplicate libraries, I have managed to get rid of the segmentation errors.

    Unfortunately, I am still not getting a proper video feed. I wonder in that is a problem with the raw1394 libraries.

    Thanks for the help. This was a rather stubborn problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM

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