delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/01/26/07:18:19

From: khan AT xraylith DOT wisc DOT edu (Mumit Khan)
Subject: Re: printf() Trashing stuff
26 Jan 1999 07:18:19 -0800 :
Message-ID: <Pine.SUN.3.93.990126042433.3247A-100000.cygnus.gnu-win32@modi.xraylith.wisc.edu>
References: <36AC265E DOT 505C9F83 AT mindless DOT com>
Mime-Version: 1.0
To: Dobes Vandermeer <dobes AT mindless DOT com>
Cc: gnu-win32 AT cygnus DOT com

On Mon, 25 Jan 1999, Dobes Vandermeer wrote:

> 
> I am getting some really weird errors with printf().  Unlike my last
> problem, I *am* including stdio.h, and I do have -Wall enabled.  I am
> not getting any warnings or errors, however a step through of my program
> reveals that my data structures (which have been properly malloc()'d
> etc.) are fine immediately before calling printf, and are completely
> ruined after calling printf().  This has happened to me twice now, and
> removing the printf() prevents the data from being destroyed.

90+% of the time, it's a bug in one's code. Usually results from memory
corruption of the following type:
  - trashing unallocated memory, eg., writing beyond array limits. 
    Especially standard C str* runctions, as well as constructs like
    a[i], where i >= ARRAY_LIMIT || i < 0.
  - free'ing unallocated memory, or free'ing memory multiple times
  - just plain bugs in your code.

Your best bet is to really look at your code to see if you can spot
one of these; failing that, my recommendation is to find a Unix box, 
eg., Linux, and use one of the free memory debuggers such as 
ElectricFence or dmalloc to debug memory (de)allocation errors. I 
personally prefer Purify, but that's an overkill for most small 
programs. 

Regards,
Mumit


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019