Hi,
I have a strange case of "memory corruption", if I can call it that way...
I have a struct:
Code:
typedef struct
{
uint64_t localizacion;
uint64_t tipo;
float azimuth[64];
float altura[64];
float tilt[64];
} individuo;
And then, I have two arrays of that type:
Code:
individuo *padres, *hijos;
Which I initialize witch calloc:
Code:
padres = calloc ( 64, sizeof ( individuo ) );
hijos = calloc ( 64, sizeof ( individuo ) );
I initialize them with random values:
Code:
for ( i = 0; i < 64; i++ )
{
// Localizaciones
srand ( rand() );
padres[i].localizacion = ( uint64_t ) ( ( pow ( 2, 32 ) * rand() ) / RAND_MAX ) << 32;
srand ( rand() );
padres[i].localizacion = padres[i].localizacion | ( uint64_t ) ( ( pow ( 2, 32 ) * rand() ) / RAND_MAX );
// Tipo de antena
srand ( rand() );
padres[i].tipo = ( uint64_t ) ( ( pow ( 2, 32 ) * rand() ) / RAND_MAX ) << 32;
srand ( rand() );
padres[i].tipo = padres[i].tipo | ( uint64_t ) ( ( pow ( 2, 32 ) * rand() ) / RAND_MAX );
//printf("Individuo %d: %llx - %llx\n",i,padres[i].localizacion,padres[i].tipo);
for ( j = 0; j < 64;j++ )
{
// Altura
srand ( rand() );
padres[i].altura[j] = 1 + 14 * ( ( float ) rand() / ( float ) RAND_MAX );
// Azimuth
srand ( rand() );
padres[i].azimuth[j] = 5 * ( ( float ) rand() / ( float ) RAND_MAX );
// Tilt
srand ( rand() );
padres[i].tilt[j] = 15 - 30 * ( ( float ) rand() / ( float ) RAND_MAX );
}
}
As you can see, altura, tilt and azimuth, have a range of valid values, which I check out every time I modified it (I add a smaller random value).
The problem is that, sometimes, some strange values appears, sometimes 0, sometimes big positive or negative values, or values very close to zero.
I tried to debug the binary, with no results, and using Valgrind, it throws this:
Code:
==7468== Invalid read of size 1
==7468== at 0x4023EF1: memcpy (mc_replace_strmem.c:406)
==7468== by 0x8049B01: main (dios2.c:415)
==7468== Address 0x41B6977 is 1 bytes before a block of size 50,176 alloc'd
==7468== at 0x402195F: calloc (vg_replace_malloc.c:279)
==7468== by 0x804892A: main (dios2.c:100)
just before detecting a strange value (I wrote a function to check the integrity of the values in the arrays).
I don't know if I'm doing something wrong, as, these strange values, doesn't appear on all values, only from time to time, so, if you can point me where could be the problem...
Thanks in advance.