home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22029 < prev    next >
Encoding:
Text File  |  1993-01-24  |  1.9 KB  |  58 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!munnari.oz.au!uniwa!cujo!ncrpda.curtin.edu.au!rocky.curtin.edu.au!user
  3. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  4. Subject: Re: Verifying valid handles, how to?
  5. Message-ID: <peter-230193180216@rocky.curtin.edu.au>
  6. Followup-To: comp.sys.mac.programmer
  7. Lines: 44
  8. Sender: news@ncrpda.curtin.edu.au
  9. Nntp-Posting-Host: ncrpda.curtin.edu.au
  10. Organization: NCRPDA, Curtin University
  11. References: <1993Jan22.015520.1@fnalo.fnal.gov>
  12. Date: Sat, 23 Jan 1993 10:01:36 GMT
  13.  
  14. In article <1993Jan22.015520.1@fnalo.fnal.gov>, gwatts@fnalo.fnal.gov
  15. wrote:
  16.  
  17. > the handle is stored in register a1.  I don't know, however, how to check
  18. > if it is a valid handle without causing an error (bus or otherwise) of
  19. > somesort.  Especially if it is a random number!  Anyone know?  Is there
  20.  
  21. here's a random attempt at it.  First check that the handle is even.  Then
  22. check that it points to an area inside your heap or inside the system heap,
  23. then check that h^ is inside the heap as well, and finally that recover
  24. handle gives the right value.
  25.  
  26.  function InsideHeap (p: univ ptr; hz: THz): boolean;
  27.  begin
  28.   InsideHeap := (longInt(p) >= longInt(hz)) & (longInt(p) <
  29. longInt(hz^.bkLim));
  30.  end;
  31.  
  32.  function ValidHandle (h: univ handle): boolean;
  33.   var
  34.    valid: boolean;
  35.  begin
  36.   valid := false;
  37.   if BAND(h, 1) = 0 then begin
  38.    if InsideHeap(h, ApplicZone) then begin
  39.     valid := (BAND(h^, 1) = 0) & InsideHeap(h^, ApplicZone);
  40.    end
  41.    else if InsideHeap(h, SystemZone) then begin
  42.     valid := (BAND(h^, 1) = 0) & InsideHeap(h^, SystemZone);
  43.    end;
  44.   end;
  45.   if valid then begin
  46.    valid := RecoverHandle(h^) = h;
  47.   end;
  48.   ValidHandle := valid;
  49.  end;
  50.  
  51. (Code tried and tested, but by no means guarenteed)
  52.  
  53. That would seem to be a good start...
  54.    Peter.
  55.  
  56. _______________________________________________________________________
  57. Peter N Lewis <peter@cujo.curtin.edu.au>             Ph: +61 9 368 2055
  58.