[net.sources.bugs] Bug in

john@xanth.UUCP (03/24/87)

There is a bug in the System V port of ARC 5.12; in the gocode()
function of arclzw.c, getc_unp(), which returns an int, is called, and
the return value is assigned to an unsigned.  The result of this is
then checked against EOF.  The new Sun C compiler loudly complains
(with a verbose, 3-line, warning message for each assignment).
ANSI-compliant C compilers will likely complain as well (at least for
libraries where EOF == -1 !).

The fixes are below, in context diff form, suitable for patching.

*** /tmp/,RCSt1a03521	Tue Mar 24 14:38:19 1987
--- arclzw.c	Tue Mar 24 14:37:53 1987
***************
*** 674,680
  static INT gocode(fd)                      /* read in a twelve bit code */
  FILE *fd;                              /* file to get code from */
  {
!     unsigned INT localbuf, returnval;
  
      if(inbuf==EMPTY)                   /* if on a code boundary */
      {    if((localbuf=getc_unp(fd))==EOF)   /* get start of next code */

--- 674,680 -----
  static INT gocode(fd)                      /* read in a twelve bit code */
  FILE *fd;                              /* file to get code from */
  {
!     INT localbuf, returnval, intemp;
  
      if(inbuf==EMPTY)                   /* if on a code boundary */
      {    if((localbuf=getc_unp(fd))==EOF)   /* get start of next code */
***************
*** 680,688
      {    if((localbuf=getc_unp(fd))==EOF)   /* get start of next code */
                return EOF;              /* pass back end of file status */
           localbuf &= 0xFF;             /* mask down to true byte value */
!          if((inbuf=getc_unp(fd))==EOF) /* get end of code, start of next */
!               return EOF;              /* this should never happen */
!          inbuf &= 0xFF;                /* mask down to true byte value */
  
           returnval = ((localbuf<<4)&0xFF0) + ((inbuf>>4)&0x00F);
           inbuf &= 0x000F;              /* leave partial code pending */

--- 680,688 -----
      {    if((localbuf=getc_unp(fd))==EOF)   /* get start of next code */
                return EOF;              /* pass back end of file status */
           localbuf &= 0xFF;             /* mask down to true byte value */
!          if((intemp=getc_unp(fd))==EOF) /* get end of code, start of next */
!               {inbuf=intemp; return EOF;}     /* this should never happen */
!          inbuf = intemp & 0xFF;           /* mask down to true byte value */
  
           returnval = ((localbuf<<4)&0xFF0) + ((inbuf>>4)&0x00F);
           inbuf &= 0x000F;              /* leave partial code pending */


-- 
John Owens		Old Dominion University - Norfolk, Virginia, USA
john@ODU.EDU		old arpa: john%odu.edu@RELAY.CS.NET
+1 804 440 3915		old uucp: {seismo,harvard,sun,hoptoad}!xanth!john