-/* 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
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,
#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;
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;