mirror of
https://github.com/coreutils/coreutils.git
synced 2024-11-28 20:44:42 +08:00
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.
This commit is contained in:
parent
26061de96f
commit
923091ff96
@ -25,8 +25,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#if STDC_HEADERS
|
#if STDC_HEADERS
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#else
|
#else
|
||||||
@ -49,7 +47,7 @@ int
|
|||||||
getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2,
|
getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2,
|
||||||
size_t offset)
|
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. */
|
char *read_pos; /* Where we're reading into *LINEPTR. */
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -64,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;
|
nchars_avail = *n - offset;
|
||||||
read_pos = *lineptr + offset;
|
read_pos = *lineptr + offset;
|
||||||
|
|
||||||
@ -75,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)
|
always (unless we get an error while reading the first char)
|
||||||
NUL-terminate the line buffer. */
|
NUL-terminate the line buffer. */
|
||||||
|
|
||||||
assert(*n - nchars_avail == read_pos - *lineptr);
|
|
||||||
if (nchars_avail < 2)
|
if (nchars_avail < 2)
|
||||||
{
|
{
|
||||||
if (*n > MIN_CHUNK)
|
if (*n > MIN_CHUNK)
|
||||||
@ -88,7 +88,6 @@ getstr (char **lineptr, size_t *n, FILE *stream, int delim1, int delim2,
|
|||||||
if (!*lineptr)
|
if (!*lineptr)
|
||||||
return -1;
|
return -1;
|
||||||
read_pos = *n - nchars_avail + *lineptr;
|
read_pos = *n - nchars_avail + *lineptr;
|
||||||
assert(*n - nchars_avail == read_pos - *lineptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == EOF || ferror (stream))
|
if (c == EOF || ferror (stream))
|
||||||
|
Loading…
Reference in New Issue
Block a user