Re: Code fails with Segmentation Fault
- From: dcorbit@xxxxxxxxx
- Date: 28 Nov 2006 09:26:57 -0800
Maybe this will be helpful:
--- Module: FOO.C (C)
_
words = (char **) calloc(max, sizeof (char *));
FOO.C(25) : Info 732: Loss of sign (arg. no. 1) (int to unsigned int)
_
apps = (int *) calloc(max, sizeof (int));
FOO.C(26) : Info 732: Loss of sign (arg. no. 1) (int to unsigned int)
_
while (fgets(string, 1000, input)) {
FOO.C(30) : Warning 530: Symbol 'string' (line 12) not initialized ---
Eff. C++
3rd Ed. item 4
FOO.C(12) : Info 830: Location cited in prior message
_
while (fgets(string, 1000, input)) {
FOO.C(30) : Warning 668: Possibly passing a null pointer to function
'fgets(char *, int, struct _iobuf *)', arg. no. 3 [Reference: file
FOO.C:
line 27]
FOO.C(27) : Info 831: Reference cited in prior message
_
if (!strcmp(words[i], word)) {
FOO.C(35) : Warning 613: Possible use of null pointer 'words' in left
argument
to operator '[' [Reference: file FOO.C: line 25]
FOO.C(25) : Info 831: Reference cited in prior message
_
apps[i]++;
FOO.C(37) : Warning 613: Possible use of null pointer 'apps' in left
argument
to operator '[' [Reference: file FOO.C: line 26]
FOO.C(26) : Info 831: Reference cited in prior message
_
words[n] = strdup(word);
FOO.C(41) : Warning 613: Possible use of null pointer 'words' in left
argument
to operator '[' [Reference: file FOO.C: line 25]
FOO.C(25) : Info 831: Reference cited in prior message
_
apps[n] = (int) malloc(sizeof(int));
FOO.C(42) : Warning 613: Possible use of null pointer 'apps' in left
argument
to operator '[' [Reference: file FOO.C: line 26]
FOO.C(26) : Info 831: Reference cited in prior message
_
apps[n] = 1;
FOO.C(43) : Warning 613: Possible use of null pointer 'apps' in left
argument
to operator '[' [Reference: file FOO.C: line 26]
FOO.C(26) : Info 831: Reference cited in prior message
_
words = (char **) realloc(words, max);
FOO.C(47) : Info 732: Loss of sign (arg. no. 2) (int to unsigned int)
_
apps = (int *) realloc(apps, max);
FOO.C(48) : Info 732: Loss of sign (arg. no. 2) (int to unsigned int)
_
printf("Word '%s' appears %d time(s).\n", words[i], apps[i]);
FOO.C(57) : Warning 613: Possible use of null pointer 'words' in left
argument
to operator '[' [Reference: file FOO.C: lines 25, 47]
FOO.C(25) : Info 831: Reference cited in prior message
FOO.C(47) : Info 831: Reference cited in prior message
_
printf("Word '%s' appears %d time(s).\n", words[i], apps[i]);
FOO.C(57) : Warning 613: Possible use of null pointer 'apps' in left
argument
to operator '[' [Reference: file FOO.C: lines 26, 48]
FOO.C(26) : Info 831: Reference cited in prior message
FOO.C(48) : Info 831: Reference cited in prior message
_
return 0;
FOO.C(60) : Warning 429: Custodial pointer 'words' (line 12) has not
been freed
or returned
FOO.C(12) : Info 830: Location cited in prior message
_
return 0;
FOO.C(60) : Warning 429: Custodial pointer 'apps' (line 13) has not
been freed
or returned
FOO.C(13) : Info 830: Location cited in prior message
_
}
FOO.C(61) : Note 952: Parameter 'argv' (line 10) could be declared
const ---
Eff. C++ 3rd Ed. item 3
FOO.C(10) : Info 830: Location cited in prior message
_
}
FOO.C(61) : Info 818: Pointer parameter 'argv' (line 10) could be
declared as
pointing to const --- Eff. C++ 3rd Ed. item 3
FOO.C(10) : Info 830: Location cited in prior message
_
}
FOO.C(61) : Note 953: Variable 'string' (line 12) could be declared as
const
--- Eff. C++ 3rd Ed. item 3
FOO.C(12) : Info 830: Location cited in prior message
_
}
FOO.C(61) : Note 954: Pointer variable 'word' (line 12) could be
declared as
pointing to const --- Eff. C++ 3rd Ed. item 3
FOO.C(12) : Info 830: Location cited in prior message
_
}
FOO.C(61) : Note 952: Parameter 'argc' (line 10) could be declared
const ---
Eff. C++ 3rd Ed. item 3
FOO.C(10) : Info 830: Location cited in prior message
.
- References:
- Code fails with Segmentation Fault
- From: Vlad Dogaru
- Code fails with Segmentation Fault
- Prev by Date: Re: I am studying c myself .Which books I should read?
- Next by Date: Re: Reading a string of unknown size
- Previous by thread: Code fails with Segmentation Fault
- Next by thread: Re: Code fails with Segmentation Fault
- Index(es):