don't allow file pointer to fall off file table
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Tue, 13 Sep 1983 07:23:52 +0000 (23:23 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Tue, 13 Sep 1983 07:23:52 +0000 (23:23 -0800)
SCCS-vsn: lib/libc/stdio/fopen.c 4.3
SCCS-vsn: lib/libc/stdio/fdopen.c 4.4

usr/src/lib/libc/stdio/fdopen.c
usr/src/lib/libc/stdio/fopen.c

index 442c9f5..122c07e 100644 (file)
@@ -1,4 +1,4 @@
-/* @(#)fdopen.c        4.3 (Berkeley) %G% */
+/* @(#)fdopen.c        4.4 (Berkeley) %G% */
 /*
  * Unix routine to do an "fopen" on file descriptor
  * The mode has to be repeated because you can't query its
 /*
  * Unix routine to do an "fopen" on file descriptor
  * The mode has to be repeated because you can't query its
@@ -18,8 +18,8 @@ register char *mode;
 
        if ((unsigned)fd >= getdtablesize())
                return (NULL);
 
        if ((unsigned)fd >= getdtablesize())
                return (NULL);
-       for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT|_IORW); iop++)
-               if (iop >= _lastbuf)
+       for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT|_IORW); )
+               if (++iop >= _lastbuf)
                        return(NULL);
        iop->_cnt = 0;
        iop->_file = fd;
                        return(NULL);
        iop->_cnt = 0;
        iop->_file = fd;
index fce66f5..9a8031c 100644 (file)
@@ -12,8 +12,8 @@ register char *mode;
        register FILE *iop;
        extern FILE *_lastbuf;
 
        register FILE *iop;
        extern FILE *_lastbuf;
 
-       for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT|_IORW); iop++)
-               if (iop >= _lastbuf)
+       for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT|_IORW); )
+               if (++iop >= _lastbuf)
                        return(NULL);
 
        rw = mode[1] == '+';
                        return(NULL);
 
        rw = mode[1] == '+';