summaryrefslogtreecommitdiffstats
path: root/freebsd/lib/libc/stdio/fgetln.c
diff options
context:
space:
mode:
Diffstat (limited to 'freebsd/lib/libc/stdio/fgetln.c')
-rw-r--r--freebsd/lib/libc/stdio/fgetln.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/freebsd/lib/libc/stdio/fgetln.c b/freebsd/lib/libc/stdio/fgetln.c
index 1a7b0514..7d9f6a53 100644
--- a/freebsd/lib/libc/stdio/fgetln.c
+++ b/freebsd/lib/libc/stdio/fgetln.c
@@ -15,7 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -39,6 +39,8 @@ static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
__FBSDID("$FreeBSD$");
#include "namespace.h"
+#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -63,6 +65,10 @@ __slbexpand(FILE *fp, size_t newsize)
#endif
if (fp->_lb._size >= newsize)
return (0);
+ if (newsize > INT_MAX) {
+ errno = ENOMEM;
+ return (-1);
+ }
if ((p = realloc(fp->_lb._base, newsize)) == NULL)
return (-1);
fp->_lb._base = p;
@@ -119,7 +125,7 @@ fgetln(FILE *fp, size_t *lenp)
* As a bonus, though, we can leave off the __SMOD.
*
* OPTIMISTIC is length that we (optimistically) expect will
- * accomodate the `rest' of the string, on each trip through the
+ * accommodate the `rest' of the string, on each trip through the
* loop below.
*/
#define OPTIMISTIC 80
@@ -156,13 +162,14 @@ fgetln(FILE *fp, size_t *lenp)
}
*lenp = len;
#ifdef notdef
- fp->_lb._base[len] = 0;
+ fp->_lb._base[len] = '\0';
#endif
FUNLOCKFILE(fp);
return ((char *)fp->_lb._base);
error:
*lenp = 0; /* ??? */
+ fp->_flags |= __SERR;
FUNLOCKFILE(fp);
return (NULL); /* ??? */
}