summaryrefslogtreecommitdiff
path: root/src/stdio/getdelim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio/getdelim.c')
-rw-r--r--src/stdio/getdelim.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c
index 60c6cc18..c313775d 100644
--- a/src/stdio/getdelim.c
+++ b/src/stdio/getdelim.c
@@ -25,8 +25,13 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
if (!*s) *n=0;
for (;;) {
- z = memchr(f->rpos, delim, f->rend - f->rpos);
- k = z ? z - f->rpos + 1 : f->rend - f->rpos;
+ if (f->rpos != f->rend) {
+ z = memchr(f->rpos, delim, f->rend - f->rpos);
+ k = z ? z - f->rpos + 1 : f->rend - f->rpos;
+ } else {
+ z = 0;
+ k = 0;
+ }
if (i+k+1 >= *n) {
if (k >= SIZE_MAX/2-i) goto oom;
size_t m = i+k+2;