Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!isgate!krafla!sigurasg From: sigurasg@rhi.hi.is (Sigurdur Asgeirsson) Newsgroups: comp.sys.mac.programmer Subject: Think Pascal 3.0.2 generates incorrect code? Summary: CLR.B (A0,D0.L) instead of (A0,D0.W) Keywords: Think Pascal 3.0.2 Message-ID: <3264@krafla.rhi.hi.is> Date: 17 Jun 91 23:29:56 GMT Organization: University of Iceland Lines: 51 A friend of mine is starting to program XCMD's and wanted me to show him how to concat two parameters into the result, so I wrote something like: type charArr = packed array [0..32767]; charPtr = ^charArr; charHndl = ^charPtr; ... Procedure Main(usual stuff) var len1, len2: integer; result: charHndl; begin len1 = GetHandleSize(param1) - 1; len2 = GetHandleSize(param2) - 1; result = charHndl(NewHandle(len1 + len2 + 1); ... {HLock'em all} BlockMove(param1^, result^, len1); BlockMove(param2^, @result^^[len1], len2); {So far so good, everything works till now (param n being parameter handle} {no. n from parameter block)} result^^[len1 + len2] := chr(0); {this compiles to an ADD.W D0,D7 or some such, and then CLR.B (A0, D0.L)} {instead of CLR.B (A0, D0.W), and some garbage in the high byte of D0, } {sending the zero byte to outer space (or inner space) corrupting the } {heap, crashing the mac, evoking a big laugh from my friend (who still } {doesn't believe that it's a compiler error).} ... {HUnlock'em all and put result into parameter block} end; The XCMD was compiled with range checking and overflow checking on, with Think Pascal 3.0.2 (upgraded from 3.0 I think). Has anyone seen this before or am I the first person in the world to be hit by this bug (or was it perhaps only a bad dream)? BTW: the code above was typed from memory, any errors result there from (the darned thing worked after I changed the D0.L to D0.W with TMON). -- sigurasg@rhi.hi.is | "Well you know, C isn't that hard, void (*(*f[])())() for Sigurdur Asgeirsson | instance defines f as an array of unspecified size, of | pointers to functions returning a pointer to a function | returning void... I think"