この Valgrind 出力を取得します (これが唯一のエラーです)。
==20627== Conditional jump or move depends on uninitialised value(s)
==20627== at 0x804913A: main (main.c:223)
私main.c
は大まかに次のようになります。
//other code
char **sets;
//other code
//char** get_char_sets(FILE *source);
sets = get_char_sets(config_file); // I malloc the sets in here
//other code
int i = 0;
while(sets[i]){ // line 223
free(sets[i]);
i++;
}
free(sets);
//other code
get_char_sets
次のようになります。
char** get_char_sets(FILE *source){
char **sets = malloc((n + 1) * sizeof(char*));
for(int i=0;i<=n;i++){
sets[i] = malloc(1 * sizeof(char));
}
//rest of function
return sets;
}
valgrind は、初期化されていない変数を使用していると言っていることを理解しています。私が見ることができるのは だけですがsets
、返されたポインターが割り当てられます。malloc()
get_char_sets()
コードを修正するためにその valgrind エラーを取り除くにはどうすればよいですか?