[comp.sys.mac.programmer] Weird string stuff : was Magical Moving Memory

pittenger-laurence@cs.yale.edu (Laurence Arthur Pittenger) (05/14/91)

Thanks to Jim Osborn for the suggestion which inspired the debugging
technique to find the problem, ie moving the suspect OpenCPort command
backward until the *real* problem became apparent.

Which was that, in all innocence, I called SetCTitle on my handle (ie
SetCTitle((ControlHandle) myObject, title), where myObject has as its
first member a ControlRecord).  Although this didn't produce any
noticable problems, it did something to corrupt the memory which only
showed up later with the OpenCPort command (or, in a different
scenerio, a MoveHHi command).  Since I had set the contrlVis field to
zero and the contrlDefProc field to NULL, I assumed that SetCTitle
would merely update the title, saving me the trouble of a for()
procedure.  I was wrong -- it does something else instead.  (What, I
don't know, though presumably it affects only the area just beyond the
ControlRecord, which is where the problem appeaed.  When this area
was, as before, merely part of the unallocated heap, the side-effect
didn't show up, which is why I'd never noticed it before.  It is such
things that give C programmers high blood-pressure, eh?)

Anyhow, should any of you be considering doing something similar, be 
warned!

Thanks to those of you who responded.

LP
-- 

Laurence A. Pittenger
CSNET  : pittenger-laurence@cs.yale.edu
BITNET : pitlaua@yalevm ,  pittenger-laurence@yalecs