#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    57
    Rep Power
    0

    Segmentation Fault At Run Time


    Debugging I have a Suspended Signal SIGSEGV : Segmantation Fault before entering the function:

    void prefilterCompilation(double** radius, double** theta, int cols , int rows);

    It must be an error about radius and theta but I don' t understand why. What I did with this variables in the main:

    Code:
    double** radius, **theta;
    ...
    raidus=(double**)malloc(sizeof(double*)*rows;
     for(int i=0;i<rows;i++);
      radius[i]=(double*)malloc(sizeof(double)*cols;
    
    theta=(double**)malloc(sizeof(double*)*rows;
     for(int z=0;z<rows;z++);
      theta[z]=(double*)malloc(sizeof(double)*cols;
    The strange thing is that I could enter in the function before. After changing something in , now I can not enter inside again. And what I change in a first time was working good.when I finish to change every thing with relationship with the first thing I changed, I could not enter again.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    OK, where is the real code?

    > raidus=(double**)malloc(sizeof(double*)*rows;
    raidus is spelled wrong, and there's a missing ) at the end of the statement.

    > for(int i=0;i<rows;i++);
    There is an extra ; at the end. What this means is the loop does nothing at all, then....

    > radius[i]=(double*)malloc(sizeof(double)*cols;
    This becomes an out of bound memory access.

    Also, remove all those casts on the result of malloc. It serves NO useful purpose in a correctly written C program (at worst, it hides a serious bug).

    If you get warnings about "cannot convert void*", then stop using C++ to compile your C code.

    If this really is C++ code, then in the first instance you should be using std::vector, or failing that, the new operator.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    57
    Rep Power
    0
    Hi,

    for the first and second points, I just dind copy well because I m using a VM and can not use from there internet. Now why the third is an error? I studied C language for this I write in C, but my work is about image-processing, so I have to use C++ for some function of this library.

IMN logo majestic logo threadwatch logo seochat tools logo