diff options
author | wosch <wosch@FreeBSD.org> | 1996-11-17 02:16:34 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1996-11-17 02:16:34 +0000 |
commit | e3484cdbc1de6605c8c37fbdb2e55cfa25913db9 (patch) | |
tree | 2b51dc6511a4fbd68ede15f66c9ce5feb2c134d4 /usr.bin/sed | |
parent | 20b553ba68ba8998038524a15f305a33c733a2b4 (diff) | |
download | FreeBSD-src-e3484cdbc1de6605c8c37fbdb2e55cfa25913db9.zip FreeBSD-src-e3484cdbc1de6605c8c37fbdb2e55cfa25913db9.tar.gz |
fix C programmer's bug number 12.2
submitted by: bruce
Diffstat (limited to 'usr.bin/sed')
-rw-r--r-- | usr.bin/sed/main.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index bed4b18..5324002 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -256,7 +256,8 @@ mf_fgets(sp, spflag) { static FILE *f; /* Current open file */ size_t len; - char c, *p; + char *p; + int c; if (f == NULL) /* Advance to first non-empty file */ @@ -274,7 +275,8 @@ mf_fgets(sp, spflag) err(FATAL, "%s: %s", fname, strerror(errno)); } - if (!feof(f)) { + if ((c = getc(f)) != EOF) { + (void)ungetc(c, f); break; } (void)fclose(f); @@ -288,6 +290,8 @@ mf_fgets(sp, spflag) /* * Use fgetln so that we can handle essentially infinite input data. + * Can't use the pointer into the stdio buffer as the process space + * because the ungetc() can cause it to move. */ p = fgetln(f, &len); if (ferror(f)) @@ -296,7 +300,7 @@ mf_fgets(sp, spflag) linenum++; /* Advance to next non-empty file */ - while (feof(f)) { + while ((c = getc(f)) == EOF) { (void)fclose(f); files = files->next; if (files == NULL) { @@ -312,6 +316,7 @@ mf_fgets(sp, spflag) err(FATAL, "%s: %s", fname, strerror(errno)); } } + (void)ungetc(c, f); return (1); } |