From: Eli Zaretskii Newsgroups: comp.os.msdos.djgpp Subject: Re: Corruption of read-only files on program crash Date: Thu, 9 Dec 1999 11:36:41 +0200 Organization: NetVision Israel Lines: 29 Message-ID: References: <82l8ll$4h2 AT romeo DOT logica DOT co DOT uk> NNTP-Posting-Host: is.elta.co.il Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: news.netvision.net.il 944732104 15168 199.203.121.2 (9 Dec 1999 09:35:04 GMT) X-Complaints-To: abuse AT netvision DOT net DOT il NNTP-Posting-Date: 9 Dec 1999 09:35:04 GMT X-Sender: eliz AT is In-Reply-To: <82l8ll$4h2@romeo.logica.co.uk> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Wed, 8 Dec 1999, Chris Underwood wrote: > When the program crashes, it occasionally destroyes the text > files it happens to have open, either replacing them with a series of > repeating bytes or blanking them completely. This is strange, since the > program only ever opens files using the following: > > infile = fopen(filename, "r"); > > Note the open mode is "r", for read access only. How can a program crash > damage files that are never written to, or even open for writing? Bugs are sometimes very ingenious ;-) For example, your bug(s) might be overwriting parts of memory used by your program's and causing the files to be open in a mode other than read-only. The best advice I can give you is to run the program under the debugger, find the cause of the crashes and correct it. It is quite possible that the scribbling over files will go away when you correct that bug. It might be a good idea to run the program in plain DOS mode, btw. CWSDPMI, the DPMI server used on plain DOS, supports the NULL pointer dereference protection, and so will help you catch possible bugs much earlier than they get detected on Windows. It is possible that an uncaught dereference of a NULL pointer does its damage before the program crashes, and one effect of that damage is your destroyed files.