Bug:
While passing a double pointer to a function the value of the fields that the pointer is pointing to seems to be dependent on some local variable of the function.
More specifically when I comment the line L(in the function "function")
Output:
In the main function: 1
In the function: 1
But when I uncomment the same line,
Output:
In the main function: 1
In the function: 0
program:
typedef struct s{
int *value;
}s;
s** initialize()
{
s** temp = (s**)malloc(sizeof(s*));
s* f = (s*)malloc(sizeof(s));
f->value = NULL;
temp = &f;
return temp;
}
void function(s** what)
{
//Line L: size_t count = 0;
printf("In the function: %d\n", (*what)->value == NULL);
}
int main()
{
s** m = initialize();
printf("In the main function: %d\n", (*m)->value == NULL);
function(m);
}
What I have tried:
- I thought that I am getting random outputs, but that was not the case as I am consistently getting the same output.
- I tried deciphering the assembly language code but that was too cryptic for me.
Environment:
- compiler:
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
- operating system: linux mint