home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / XLSP21TC.ZIP / XL-XS001.BUG / text0000.txt < prev   
Encoding:
Text File  |  1991-04-14  |  2.3 KB  |  64 lines

  1.  
  2. I stumbled across a bug in Xscheme's handling of ports. It turns out
  3. that none of the functions that take ports as arguments check whether
  4. the port is open (i.e. it hasn't been closed) (except xclose() itself!).
  5. Sending a closed port to e.g. READ causes a NULL dereference down in
  6. the OS specific stuff: on my UNIX machine Xscheme dies with a SIGSEGV.
  7. The easiest fix (although it has the side-effect of making PORT? return #F
  8. for closed ports) is to change the portp() macro in xscheme.h like this:
  9.  
  10. *** xscheme.h.~1~    Sun Feb 19 13:25:29 1989
  11. --- xscheme.h    Wed Apr 12 18:41:26 1989
  12. ***************
  13. *** 207,213 ****
  14.   #define consp(x)    ((x) && ntype(x) == CONS)
  15.   #define stringp(x)    ((x) && ntype(x) == STRING)
  16.   #define symbolp(x)    ((x) && ntype(x) == SYMBOL)
  17. ! #define portp(x)    ((x) && ntype(x) == PORT)
  18.   #define objectp(x)    ((x) && ntype(x) == OBJECT)
  19.   #define fixp(x)        ((x) && ntype(x) == FIXNUM)
  20.   #define floatp(x)    ((x) && ntype(x) == FLONUM)
  21. --- 207,213 ----
  22.   #define consp(x)    ((x) && ntype(x) == CONS)
  23.   #define stringp(x)    ((x) && ntype(x) == STRING)
  24.   #define symbolp(x)    ((x) && ntype(x) == SYMBOL)
  25. ! #define portp(x)    ((x) && ntype(x) == PORT && getfile(x))
  26.   #define objectp(x)    ((x) && ntype(x) == OBJECT)
  27.   #define fixp(x)        ((x) && ntype(x) == FIXNUM)
  28.   #define floatp(x)    ((x) && ntype(x) == FLONUM)
  29.  
  30.  
  31. I then went to see if Xlisp was equally fragile, but luckily it wasn't.
  32. Only xformat() (due to it's checking for NIL, T and unnamed streams)
  33. misses to check that the file is open.
  34. The following patch fixes that problem (your line numbers may vary):
  35.  
  36. *** xlfio.c.~1~    Mon Dec 19 06:07:30 1988
  37. --- xlfio.c    Wed Apr 12 20:35:40 1989
  38. ***************
  39. *** 410,416 ****
  40.       else {
  41.       if (stream == true)
  42.           stream = getvalue(s_stdout);
  43. !     else if (!streamp(stream) && !ustreamp(stream))
  44.           xlbadtype(stream);
  45.       val = NIL;
  46.       }
  47. --- 410,420 ----
  48.       else {
  49.       if (stream == true)
  50.           stream = getvalue(s_stdout);
  51. !     else if (streamp(stream)) {    /* copied from xlgetfile() */
  52. !         if (getfile(stream) == NULL)
  53. !         xlfail("file not open");
  54. !     }
  55. !     else if (!ustreamp(stream))
  56.           xlbadtype(stream);
  57.       val = NIL;
  58.       }
  59. -- 
  60. Mikael Pettersson, Dept of Comp & Info Sci, University of Linkoping, Sweden
  61. email: mpe@ida.liu.se  or  ..!{mcvax,munnari,uunet}!enea!liuida!mpe
  62.  
  63.  
  64.