🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.ibm.pc.programmer
2 messages
2 total messages Started by Michael K. Minakami Mon, 19 Mar 1990 05:40
File buffer trashing data?
#32
Author: Michael K. Minakami
Date: Mon, 19 Mar 1990 05:40
12 lines
1039 bytes
I'm trying to debug a program and came across something unusal: fwrite()
is changing the contents of an array. The array has memory calloc'ed
for it at the beginning of the program, and when fwrite() is called it 
trashes everything started at array+4. I dereferenced the file pointer and
found a variable (blk?) that was pointing to that location. Also tracing
through fwrite, the array was being changed by a memcpy which (surprise)
copied the data I wanted to fwrite over the array. 

Does anyone know what's going on? 

Thanks
Michael
Re: File buffer trashing data?
#37
Author: Jim Patterson
Date: Tue, 20 Mar 1990 14:04
17 lines
1426 bytes
In article <1990Mar19.054020.13581@Neon.Stanford.EDU> minakami@Neon.Stanford.EDU (Michael K. Minakami) writes:
>I'm trying to debug a program and came across something unusal: fwrite()
>is changing the contents of an array. The array has memory calloc'ed
>for it at the beginning of the program, and when fwrite() is called it 
>trashes everything started at array+4.

It sounds like someone has free'd your array before you're done with
it, and when you opened the file later, the buffer stdio uses was
given the area previously free'd. If you put a breakpoint in free
you might catch the offender. This might also happen without an
actual free if somehow you've corrupted the free list that malloc/free
maintain.
-- 
Jim Patterson                              Cognos Incorporated
UUCP:decvax!utzoo!dciem!nrcaer!cognos!jimp P.O. BOX 9707    
PHONE:(613)738-1440                        3755 Riverside Drive
                                           Ottawa, Ont  K1G 3Z4
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads