Hi, thanks for the help AndiPersti. I found out in the meanwhile that the conditional jumps and the invalid reads are unrelated, so sorry for the fuzz. The conditional jumps I managed to solve now. However, I still don't see where the invalid reads are coming from.
The errors refer to the line where BAE[i] is allocated in the func_Z() function. The errors are:
Code:
==7407== Invalid read of size 8
==7407== at 0x411851: func_Z (dcoeff.c:3)
==7407== by 0x41482D: main (main.c:79)
==7407== Address 0x59c3d80 is 0 bytes after a block of size 144 alloc'd
==7407== at 0x4A06B0F: calloc (vg_replace_malloc.c:593)
==7407== by 0x40EB1F: func_Z (dcoeff.c:43)
==7407== by 0x41482D: main (main.c:79)
==7407==
==7407== Invalid read of size 8
==7407== at 0x411854: func_Z (dcoeff.c:3)
==7407== by 0x41482D: main (main.c:79)
==7407== Address 0x59c3d88 is 8 bytes after a block of size 144 alloc'd
==7407== at 0x4A06B0F: calloc (vg_replace_malloc.c:593)
==7407== by 0x40EB1F: func_Z (dcoeff.c:43)
==7407== by 0x41482D: main (main.c:79)
==7407==
Here's the relevant code:
Header:
Code:
#ifndef HEADER_H
#define HEADER_H
#include <stdlib.h>
#include ... (and so on)
#define PI 3.141592653589793
typedef double _Complex cplx;
struct Point;
typedef struct Point{
double x;
double y;
} Point;
struct Groups;
... (and so on)
int *NumQ;
Point defineVec(double, double);
Point ... (and so on)
void func_Z(int, Group *, int *, int *, double, PartBlockMatrix *);
void ... (and so on)
#endif
main.c:
Code:
#include "EFIEsolver.h"
int main(){
int NumGroups = 2;
Group *Groups = (Group *) calloc(NumGroups,sizeof(Group));
int *d_flag = (int *) calloc(NumGroups*(NumGroups+1)/2,sizeof(int));
int *M = (int *) calloc(NumGroups,sizeof(int));
PartBlockMatrix *Z = (PartBlockMatrix *) calloc(NumGroups*NumGroups,sizeof(PartBlockMatrix));
NumQ = (int *) calloc(NumGroups,sizeof(int));
double k = 2.*PI;
... (here follows the initialisation of all variables)
func_Z(NumGroups, Groups, d_flag, M, k, Z);
... (freeing allocated memory)
}
The function func_Z:
Code:
#include "EFIEsolver.h"
void func_Z(int NumGroups, Group *Groups, int *d_flag, int *M, double k, PartBlockMatrix *Z){
int i;
cplx **BAE, **HE2C;
... (and so on)
BAE = (cplx **) calloc(NumGroups,sizeof(cplx *));
HE2C = (cplx **) calloc(NumGroups,sizeof(cplx *));
for(i=0;i<NumGroups;i++){
BAE[i] = (cplx *) calloc(2*NumQ[i]+1,sizeof(cplx));
HE2C[i] = (cplx *) calloc(2*NumQ[i]+1,sizeof(cplx));
}
... (and so on)
}
Any help is welcome!