This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: seg fault on redirection


On Tue, 28 Nov 2000, Joe Buck wrote:

> 
> > What would cause a program to seg fault when the output is redirected
> > to a file but run file otherwise?
> 
> We could all try to come up with clever answers ... or you could tell us
> how you did it (what compiler, what platform, test case etc).
> 

Actually what it turned out to be was an uninitialized pointer.
Within the function a pointer was declared.  It is suppose to
be used as a return value from another function.  I ended up
changing it to just a regular unsigned long variable and passed
the address of it to the other function.

That doesn't explain why it would bomb when the output was redirected
to a file, especially since it had worked before I made changes to
another part of the code that should have been unrelated.

Either way, the original implementation was poor, IMO.  Having 
uninitialized pointers is probably just bad.  I probably could have
just passed the address of the pointer to the function that would
use it as a return value, but the current implementation is fine.

-- 
Jiann-Ming Su, js1@microwave.ph.msstate.edu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]