Debugging a redis contribution– adding bloom filter

I got stuck on this weird segmentation fault during my attempt to add bloom filter to redis. (See here for source.)

Running redis server with gdb and then printing out variables, i concluded that the Bloom filter struct’s member variable a points to an unassigned or atleast out of bounds memory address.

Now, my first thought was that damn may be it’s because default redis make creates the redis binary with gcc optimizations enabled. So  I did a

<blockquote>

make clean

followed it up with a

make noopt

as suggested by this part in the Makefile here.

noopt:
       $(MAKE) OPTIMIZATION=”-O0″

But that didn’t solve any of my problems. So at first , i blamed the Makefile saying it doesn’t propagate the -O0. But then decided, I’ll try the same scenario on a small test code. After all, there’s a lot that I don’t know about  systems programming. So i created a struct with some char pointers, created two pointers to the struct, initialized one, pointed the second pointer to first (after casting the first one to void*). Basically this is what happens with the redis as I pass the pointer to my bloom filter object to redis createObject function.  You can see here.

BLOOM *b = bloom_create(REDIS_BLOOM_FILTER_SIZE,fp);
redisLog(2,”Created BloomFilterObject n”);
robj *o = createObject(REDIS_BLOOM_FILTER,b);

Now for the test code.

#include 
typedef struct testA
{
    int a;
    float b;
    char *c;
}test;

void main()
{
    test *A,*B;

    A->a = 5;
    A->b= 12.0;
    A->c = "eue";

    //B = malloc(sizeof(test));
    B = (void*) A;

    printf("%dt %f t %s n ",B->a,B->b,B->c);
    //free(B);
}

You can find those here.

Anyway, as i run this and here’s the output