Module Name:    src
Committed By:   roy
Date:           Thu Oct 15 00:36:24 UTC 2009

Modified Files:
        src/lib/libc/stdio: fgetstr.c

Log Message:
Handle errors from getdelim better.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdio/fgetstr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdio/fgetstr.c
diff -u src/lib/libc/stdio/fgetstr.c:1.7 src/lib/libc/stdio/fgetstr.c:1.8
--- src/lib/libc/stdio/fgetstr.c:1.7	Wed Oct 14 20:54:51 2009
+++ src/lib/libc/stdio/fgetstr.c	Thu Oct 15 00:36:24 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: fgetstr.c,v 1.7 2009/10/14 20:54:51 roy Exp $	*/
+/* $NetBSD: fgetstr.c,v 1.8 2009/10/15 00:36:24 roy Exp $	*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fgetstr.c,v 1.7 2009/10/14 20:54:51 roy Exp $");
+__RCSID("$NetBSD: fgetstr.c,v 1.8 2009/10/15 00:36:24 roy Exp $");
 
 #include "namespace.h"
 
@@ -58,17 +58,15 @@
 	p = (char *)fp->_lb._base;
 	size = fp->_lb._size;
 	*lenp = __getdelim(&p, &size, sep, fp);
+	fp->_lb._base = (unsigned char *)p;
 	/* The struct size variable is only an int ..... */
 	if (size > INT_MAX) {
 		fp->_lb._size = INT_MAX;
 		errno = EOVERFLOW;
 		goto error;
 	}
-	fp->_lb._base = (unsigned char *)p;
 	fp->_lb._size = (int)size;
-	if (*lenp == 0)
-		return NULL;
-	if (*lenp < SIZE_MAX)
+	if (*lenp != 0 && *lenp < SIZE_MAX - 1)
 		return p;
 error:
 	*lenp = 0;

Reply via email to