I have a c++ code which recently started throwing segmentation fault. i know the issue is due to the uninitialized pointer. But my doubt is why this code started throwing seg fault suddenly. This code was not changed since 2010. Is it possible to have a segmentation fault without any change to the code? Here is the code:
void COB :: processfile()
{
ofstream *pbm_ptr; //uninitialiased ptr
..
while(currentRecord,readLine(_cobstream, FALSE))
{
...
if(_cobvalues[POS_REC_TYPE] == DETAIL)
{
pbm_ptr = null; //initialising
...
}
else
{
if(pbm_ptr != NULL)
*pbm_ptr << currentRecord(0,RECORD_LENGTH) << endl; //segmentation fault
..
}
I would like to add one more point that after i get segmentation fault, if i rerun the same executable again with the same input file, there will not be any error for the second run. Can anyone tell me what is the cause of such result ?