Fixes a segv in inc (and occasionally other programs). Originally from
Ruud de Rooij <r.c.m.derooij@twi.tudelft.nl>
bp = sp = (unsigned char *) iob->_ptr - 1;
j = (cnt = iob->_cnt+1) < i ? cnt : i;
#endif
- while ((c = *bp++) != ':' && c != '\n' && --j >= 0)
+ while (--j >= 0 && (c = *bp++) != ':' && c != '\n')
*cp++ = c;
j = bp - sp;
;
#else /* RPATHS */
cp = unixbuf;
- while ((c = getc (iob)) != '\n')
+ while ((c = getc (iob)) != '\n' && cp - unixbuf < BUFSIZ - 1)
*cp++ = c;
*cp = 0;
#endif /* RPATHS */
break;
#else /* RPATHS */
cp = unixbuf;
- while ((c = getc (iob)) != '\n' && c >= 0)
+ while ((c = getc (iob)) != '\n' && c >= 0 && cp - unixbuf < BUFSIZ - 1)
*cp++ = c;
*cp = 0;
#endif /* RPATHS */