projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*** empty log message ***
[gnulib.git]
/
lib
/
getstr.c
diff --git
a/lib/getstr.c
b/lib/getstr.c
index
66e44fe
..
6e748a4
100644
(file)
--- a/
lib/getstr.c
+++ b/
lib/getstr.c
@@
-1,6
+1,6
@@
/* getstr.c -- core function for GNU C library getline replacement function
/* getstr.c -- core function for GNU C library getline replacement function
- Copyright (C) 1993, 1996-200
0
Free Software Foundation, Inc.
+ Copyright (C) 1993, 1996-200
1
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@
-25,14
+25,14
@@
#include <stdio.h>
#include <sys/types.h>
#include <stdio.h>
#include <sys/types.h>
-#include <assert.h>
-
#if STDC_HEADERS
# include <stdlib.h>
#else
char *malloc (), *realloc ();
#endif
#if STDC_HEADERS
# include <stdlib.h>
#else
char *malloc (), *realloc ();
#endif
+#include "unlocked-io.h"
+
/* Always add at least this many bytes when extending the buffer. */
#define MIN_CHUNK 64
/* Always add at least this many bytes when extending the buffer. */
#define MIN_CHUNK 64
@@
-47,7
+47,7
@@
int
getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2,
size_t offset)
{
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;
char *read_pos; /* Where we're reading into *LINEPTR. */
int ret;
@@
-62,6
+62,9
@@
getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2,
return -1;
}
return -1;
}
+ if (*n < offset)
+ return -1;
+
nchars_avail = *n - offset;
read_pos = *lineptr + offset;
nchars_avail = *n - offset;
read_pos = *lineptr + offset;
@@
-73,7
+76,6
@@
getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2,
always (unless we get an error while reading the first char)
NUL-terminate the line buffer. */
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)
if (nchars_avail < 2)
{
if (*n > MIN_CHUNK)
@@
-86,7
+88,6
@@
getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2,
if (!*lineptr)
return -1;
read_pos = *n - nchars_avail + *lineptr;
if (!*lineptr)
return -1;
read_pos = *n - nchars_avail + *lineptr;
- assert(*n - nchars_avail == read_pos - *lineptr);
}
if (c == EOF || ferror (stream))
}
if (c == EOF || ferror (stream))