changeset 23362:ab85bda4a99f

Don't include assert.h. (getstr): Remove warning-evoking assertions. Return -1 if offset parameter is out of bounds. Change the type of a local from int to size_t.
author Jim Meyering <jim@meyering.net>
date Sun, 09 Dec 2001 22:08:19 +0000
parents 945ecbc3142c
children 33c80742b5f2
files lib/getstr.c
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lib/getstr.c	Sun Dec 09 21:02:43 2001 +0000
+++ b/lib/getstr.c	Sun Dec 09 22:08:19 2001 +0000
@@ -25,8 +25,6 @@
 #include <stdio.h>
 #include <sys/types.h>
 
-#include <assert.h>
-
 #if STDC_HEADERS
 # include <stdlib.h>
 #else
@@ -49,7 +47,7 @@
 getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2,
 	size_t offset)
 {
-  int nchars_avail;		/* Allocated but unused chars in *LINEPTR.  */
+  size_t nchars_avail;		/* Allocated but unused chars in *LINEPTR.  */
   char *read_pos;		/* Where we're reading into *LINEPTR. */
   int ret;
 
@@ -64,6 +62,9 @@
 	return -1;
     }
 
+  if (*n < offset)
+    return -1;
+
   nchars_avail = *n - offset;
   read_pos = *lineptr + offset;
 
@@ -75,7 +76,6 @@
 	 always (unless we get an error while reading the first char)
 	 NUL-terminate the line buffer.  */
 
-      assert(*n - nchars_avail == read_pos - *lineptr);
       if (nchars_avail < 2)
 	{
 	  if (*n > MIN_CHUNK)
@@ -88,7 +88,6 @@
 	  if (!*lineptr)
 	    return -1;
 	  read_pos = *n - nchars_avail + *lineptr;
-	  assert(*n - nchars_avail == read_pos - *lineptr);
 	}
 
       if (c == EOF || ferror (stream))