I am allocating enough memory for two pointers which I treat as arrays:
// Allocate memory for both adj and deg
int *adjdeg = malloc(sizeof(int)*n*n);
adj = adjdeg;
deg = adjdeg + n*n - n;
I am then using GNU’s bzero from string.h to initialize the values in the deg “array” to 0 (the adj “array” doesn’t need to be initialized to it since I write to it before I ever read from it). This works fine, and my program runs successfully, but valgrind reports many errors about use of initialized values whenever I read from deg (IE. deg[0]). Here is my call to bzero:
// My bzero call
bzero(deg, n);
valgrind is happy if I remove my call to bzero and use a loop like:
int i;
for(i = 0; i < n; i++)
deg[i] = 0;
Is there any way to tell valgrind that bzero is initializing that area in memory correctly? I’m using gcc 4.6.3 and valgrind 3.7.0
Note: I get the same errors in valgrind if I use memset instead of bzero.
You should be using:
As it is, you’re initializing
nbytes, notnintegers. For maximal portability, you should probably usememset()instead ofbzero(), but you still need thesizeof(int)multiplier in the size: