Browse Source

fix failure of getdelim to set stream orientation on error

if EINVAL or ENOMEM happened before the first getc_unlocked, it was
possible that the stream orientation had not yet been set.
Rich Felker 6 years ago
parent
commit
5cd309f0cc
1 changed files with 2 additions and 0 deletions
  1. 2 0
      src/stdio/getdelim.c

+ 2 - 0
src/stdio/getdelim.c

@@ -15,6 +15,7 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
 	FLOCK(f);
 	FLOCK(f);
 
 
 	if (!n || !s) {
 	if (!n || !s) {
+		f->mode |= f->mode-1;
 		f->flags |= F_ERR;
 		f->flags |= F_ERR;
 		FUNLOCK(f);
 		FUNLOCK(f);
 		errno = EINVAL;
 		errno = EINVAL;
@@ -58,6 +59,7 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
 
 
 	return i;
 	return i;
 oom:
 oom:
+	f->mode |= f->mode-1;
 	f->flags |= F_ERR;
 	f->flags |= F_ERR;
 	FUNLOCK(f);
 	FUNLOCK(f);
 	errno = ENOMEM;
 	errno = ENOMEM;