]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - libio/iogetdelim.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / libio / iogetdelim.c
index 3ee7eac873d81706ea9066242c9ee0fa8f97f9ca..50fda58e6832d23391d26d3c64c7b66b11d304c3 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (C) 1994,1996-1998,2001,2003,2005,2012
-   Free Software Foundation, Inc.
+/* Copyright (C) 1994-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -13,9 +12,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.
 
    As a special exception, if you link the code in this file with
    files compiled with a GNU compiler to produce an executable,
@@ -30,6 +28,7 @@
 #include "libioP.h"
 #include <string.h>
 #include <errno.h>
+#include <limits.h>
 
 /* Read up to (and including) a TERMINATOR from FP into *LINEPTR
    (and null-terminate it).  *LINEPTR is a pointer returned from malloc (or
    null terminator), or -1 on error or EOF.  */
 
 _IO_ssize_t
-_IO_getdelim (lineptr, n, delimiter, fp)
-     char **lineptr;
-     _IO_size_t *n;
-     int delimiter;
-     _IO_FILE *fp;
+_IO_getdelim (char **lineptr, _IO_size_t *n, int delimiter, _IO_FILE *fp)
 {
   _IO_ssize_t result;
   _IO_ssize_t cur_len = 0;
@@ -90,7 +85,7 @@ _IO_getdelim (lineptr, n, delimiter, fp)
       t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len);
       if (t != NULL)
        len = (t - fp->_IO_read_ptr) + 1;
-      if (__builtin_expect (cur_len + len + 1 < 0, 0))
+      if (__glibc_unlikely (len >= SSIZE_MAX - cur_len))
        {
          __set_errno (EOVERFLOW);
          result = -1;