On 8/31/07, Skybuck Flying <[EMAIL PROTECTED]> wrote: > ----- Original Message ----- > From: "ik" <[EMAIL PROTECTED]> > To: <[email protected]> > Sent: Friday, August 31, 2007 11:01 AM > Subject: Re: [lazarus] Critical BUG in TBits class! > > > > Hi Please see my code inline > > > > On 8/31/07, 12 12 <[EMAIL PROTECTED]> wrote: > >> I tried to include sophisticated unit with math operations into my > >> project. > >> The unit worked fine in Delphi. > >> But in Lazarus it get error when call TBits.SetSize(0): > >> "Invalid bit index -1". > >> I go to implementation of method TBits.SetSize and see this: > >> > >> "procedure TBits.setSize(value : longint); > >> begin > > > if (Value > 0) then > > grow(value - 1) > > else .... > > This is your attempt at a bug fix. (next time mention it cause it looked > kinda confusing) > > However you didn't supply the full bug fix.
It's not a bug fix, because I do not know the code, or understand it's logic, however I tried to give a better idea on how such code should look like. > > What if he wants to set the size to zero to reduce the memory to zero. > > That should be possible ! Sorry, I don't understand your point. > > >> end;" > >> > >> The method tries to set negative value of size! > >> > >> Who can help? > >> > > > > Please always check that you are able to do the operation without > > arriving to overflow (for example). > > A question is, why Value is longint and not a Cardinal, is there a > > reason for negative size ?! > > Suppose it was a longword. > > 0 - 1 wraps back to 4 billion. > > That would have allocated 4 billion bits. > > In this case he was probably lucky that did not happen and instead got > index -1 error ;) > > Also the -1 seems a logical coding mistake. (I am not sure what grow does) > > If grow is simply a SetLength method that it is incorrect. > > Size := 1; // means 1 bit. So at least 1 "thing" must be allocated. > > Value(1)-1=0; // nothing would be allocated ? > > Weird code. > > Sloppy too ? > > Bye, > Skybuck. > > _________________________________________________________________ > To unsubscribe: mail [EMAIL PROTECTED] with > "unsubscribe" as the Subject > archives at http://www.lazarus.freepascal.org/mailarchives > -- http://ik.homelinux.org/ _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives
