Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!orc!bbn.com!nic!chaos.cs.brandeis.edu!chaos!phils From: phils@chaos.cs.brandeis.edu (Phil Shapiro) Newsgroups: comp.sys.mac.programmer Subject: Re: simple C Problem Message-ID: Date: 11 Oct 90 19:35:29 GMT References: <1268@beguine.UUCP> <10630@goofy.Apple.COM> Sender: @chaos.cs.brandeis.edu Organization: Symantec Corp. Lines: 39 In-Reply-To: sean_parent.snarkmail_l_z@gateway.qm.apple.com's message of 9 Oct 90 18:28:19 GMT In article <10630@goofy.Apple.COM> sean_parent.snarkmail_l_z@gateway.qm.apple.com (Sean Parent) writes: In article <1268@beguine.UUCP> Eliot.Henry@samba.acs.unc.edu (BBS Account) writes: > > char thebuffer[512]; > In article <1268@beguine.UUCP> Eliot.Henry@samba.acs.unc.edu (BBS Account) writes: > > /* Load the array with 0 bits (ascii character zero) */ > for (i=1; i<=512; i++) > thebuffer[i]=0; This is a commen problem with pascal programers converting to C. thebuffer is an array containing 512 items but is indexed form 0 to 511. The for loop here will write off the end of the array. True. But there is another, more insidious bug: In article <1268@beguine.UUCP> Eliot.Henry@samba.acs.unc.edu (BBS Account) writes: int i,j,lb; In article <1268@beguine.UUCP> Eliot.Henry@samba.acs.unc.edu (BBS Account) writes: for (i=1; i<=800; i++) { Param.ioParam.ioPosOffset=i*512; This will produce an integer overflow (in THINK C, at least). Even though the result of "i*512" is stored in a long integer, the calculation is performed using short (16 bit) integer. Either declare "i" as a long, or use 512L. -phil shapiro, symantec tech support -- Phil Shapiro phils@chaos.cs.brandeis.edu