Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!sdd.hp.com!apollo!keil
From: keil@apollo.hp.com (Mark Keil)
Subject: A bugfix for jgets
Lines: 35
Message-ID: <1992Mar4.055403.12697@apollo.hp.com>
Keywords: J bug
Sender: netnews@apollo.hp.com (USENET posting account)
Nntp-Posting-Host: thor.ch.apollo.hp.com
Organization: Someday
Date: Wed, 4 Mar 1992 05:54:03 GMT

 The problem is that in a small number of cases the byte just before s
 can be 0x04. (^d) 
 It only shows up when just a return is entered. In this case the
 character at s+n (s+1) gets zeroed, and n decremented to 0. Then when
 the ^d check is done, the byte at s+0-1 is checked, and is sometimes 0x04.
 I added a check for n>0 and it fixed the problem.
 I also note that a ^d at the end of a line of input text will cause
 termination without execution of the last input text. I will leave it to
 Roger to decide what to do about that case.

-Mark

 Here is jgets

A jgets(){C c,*s=inbuf;I k=0,n;
 if(infile==stdin){if(sesm)jsti(NINPUT,s); else RZ(fgets(s,NINPUT,stdin));}
 else{do RZ(fgets(s,NINPUT,infile))while(COUT==*s); k=strspn(s," ");}
 n=strlen(s); if(c=*(s+n-1),CLF==c||CCR==c){--n; *(s+n)=0;}
 if(infile!=stdin){jputs(k+s); jputc(CNL);}
 else if(outfile){fputs(k+s,outfile); fputc(CNL,outfile);}
 if(CCTRLD==*(s+n-1))joff();
 R str(n,s);
}

 I made the following change.

96c96
<  if(CCTRLD==*(s+n-1))joff();
---
>  if((n>0)&&(CCTRLD==*(s+n-1)))joff();

-- 
 Mark Keil               HP/Apollo Computer,  Chelmsford MA 01824
 +1 508-256-6600 x4542   keil@apollo.hp.com  /  {decvax,mit-erl,yale}!apollo!keil

