Edit : the problem seems to be either mac os or valgrind, because even when I execute simple program like :
#include <stdio.h>
int main()
{
int a;
a = 28;
printf("a = %d\n", a);
return (0);
}
I keep having the Conditional jump error
I'm learning how to use threads in c, and I'm stuck with a 'Conditional jump or move depends on uninitialised value(s)' on valgrind when executing this code. I don't understand where the error commes from :
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
struct s_struct;
typedef struct s_test
{
int q;
int w;
int e;
struct s_struct *strct;
} t_test;
typedef struct s_struct
{
int a;
int b;
int c;
t_test *test;
} t_struct;
void *function(void *strct)
{
t_struct *s;
s = (t_struct *)strct;
s->a = 42;
s->test[2].q = 32;
return (NULL);
}
int main()
{
t_struct strct;
pthread_t th;
strct.test = (t_test *)malloc((sizeof(t_test) * 5));
strct.a = 17;
strct.test[2].q = 5;
printf("s.a = %d\n", strct.a);
printf("s.test[2].q = %d\n", strct.test[2].q);
pthread_create(&th, NULL, &function, &strct);
pthread_join(th, NULL);
printf("s.a = %d\n", strct.a);
printf("s.test[2].q = %d\n", strct.test[2].q);
free(strct.test);
return (0);
}
Could someone help me understand why I'm having this error.
The valgrind result is :