Merge branch 'mpinjr-fix-ioerrors' into staging
This commit is contained in:
commit
b9c01f5122
5
FIXES
5
FIXES
@ -25,6 +25,11 @@ THIS SOFTWARE.
|
|||||||
This file lists all bug fixes, changes, etc., made since the AWK book
|
This file lists all bug fixes, changes, etc., made since the AWK book
|
||||||
was sent to the printers in August, 1987.
|
was sent to the printers in August, 1987.
|
||||||
|
|
||||||
|
December 8, 2021:
|
||||||
|
The error handling in closefile and closeall was mangled. Long
|
||||||
|
standing warnings had been made fatal and some fatal errors went
|
||||||
|
undetected. Thanks to Miguel Pineiro Jr. <mpj@pineiro.cc>.
|
||||||
|
|
||||||
Nov 03, 2021:
|
Nov 03, 2021:
|
||||||
getline accesses uninitialized data after getrec()
|
getline accesses uninitialized data after getrec()
|
||||||
returns 0 on EOF and leaves the contents of buf unchanged.
|
returns 0 on EOF and leaves the contents of buf unchanged.
|
||||||
|
2
main.c
2
main.c
@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|||||||
THIS SOFTWARE.
|
THIS SOFTWARE.
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
const char *version = "version 20211103";
|
const char *version = "version 20211208";
|
||||||
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
37
run.c
37
run.c
@ -1860,8 +1860,8 @@ const char *filename(FILE *fp)
|
|||||||
return "???";
|
return "???";
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell *closefile(Node **a, int n)
|
Cell *closefile(Node **a, int n)
|
||||||
{
|
{
|
||||||
Cell *x;
|
Cell *x;
|
||||||
size_t i;
|
size_t i;
|
||||||
bool stat;
|
bool stat;
|
||||||
@ -1872,8 +1872,15 @@ const char *filename(FILE *fp)
|
|||||||
for (i = 0; i < nfiles; i++) {
|
for (i = 0; i < nfiles; i++) {
|
||||||
if (!files[i].fname || strcmp(x->sval, files[i].fname) != 0)
|
if (!files[i].fname || strcmp(x->sval, files[i].fname) != 0)
|
||||||
continue;
|
continue;
|
||||||
if (ferror(files[i].fp))
|
if (files[i].mode == GT || files[i].mode == '|')
|
||||||
FATAL("i/o error occurred on %s", files[i].fname);
|
fflush(files[i].fp);
|
||||||
|
if (ferror(files[i].fp)) {
|
||||||
|
if ((files[i].mode == GT && files[i].fp != stderr)
|
||||||
|
|| files[i].mode == '|')
|
||||||
|
FATAL("write error on %s", files[i].fname);
|
||||||
|
else
|
||||||
|
WARNING("i/o error occurred on %s", files[i].fname);
|
||||||
|
}
|
||||||
if (files[i].fp == stdin || files[i].fp == stdout ||
|
if (files[i].fp == stdin || files[i].fp == stdout ||
|
||||||
files[i].fp == stderr)
|
files[i].fp == stderr)
|
||||||
stat = freopen("/dev/null", "r+", files[i].fp) == NULL;
|
stat = freopen("/dev/null", "r+", files[i].fp) == NULL;
|
||||||
@ -1882,7 +1889,7 @@ const char *filename(FILE *fp)
|
|||||||
else
|
else
|
||||||
stat = fclose(files[i].fp) == EOF;
|
stat = fclose(files[i].fp) == EOF;
|
||||||
if (stat)
|
if (stat)
|
||||||
FATAL("i/o error occurred closing %s", files[i].fname);
|
WARNING("i/o error occurred closing %s", files[i].fname);
|
||||||
if (i > 2) /* don't do /dev/std... */
|
if (i > 2) /* don't do /dev/std... */
|
||||||
xfree(files[i].fname);
|
xfree(files[i].fname);
|
||||||
files[i].fname = NULL; /* watch out for ref thru this */
|
files[i].fname = NULL; /* watch out for ref thru this */
|
||||||
@ -1893,7 +1900,7 @@ const char *filename(FILE *fp)
|
|||||||
x = gettemp();
|
x = gettemp();
|
||||||
setfval(x, (Awkfloat) (stat ? -1 : 0));
|
setfval(x, (Awkfloat) (stat ? -1 : 0));
|
||||||
return(x);
|
return(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeall(void)
|
void closeall(void)
|
||||||
{
|
{
|
||||||
@ -1903,18 +1910,24 @@ void closeall(void)
|
|||||||
for (i = 0; i < nfiles; i++) {
|
for (i = 0; i < nfiles; i++) {
|
||||||
if (! files[i].fp)
|
if (! files[i].fp)
|
||||||
continue;
|
continue;
|
||||||
if (ferror(files[i].fp))
|
if (files[i].mode == GT || files[i].mode == '|')
|
||||||
FATAL( "i/o error occurred on %s", files[i].fname );
|
fflush(files[i].fp);
|
||||||
if (files[i].fp == stdin)
|
if (ferror(files[i].fp)) {
|
||||||
|
if ((files[i].mode == GT && files[i].fp != stderr)
|
||||||
|
|| files[i].mode == '|')
|
||||||
|
FATAL("write error on %s", files[i].fname);
|
||||||
|
else
|
||||||
|
WARNING("i/o error occurred on %s", files[i].fname);
|
||||||
|
}
|
||||||
|
if (files[i].fp == stdin || files[i].fp == stdout ||
|
||||||
|
files[i].fp == stderr)
|
||||||
continue;
|
continue;
|
||||||
if (files[i].mode == '|' || files[i].mode == LE)
|
if (files[i].mode == '|' || files[i].mode == LE)
|
||||||
stat = pclose(files[i].fp) == -1;
|
stat = pclose(files[i].fp) == -1;
|
||||||
else if (files[i].fp == stdout || files[i].fp == stderr)
|
|
||||||
stat = fflush(files[i].fp) == EOF;
|
|
||||||
else
|
else
|
||||||
stat = fclose(files[i].fp) == EOF;
|
stat = fclose(files[i].fp) == EOF;
|
||||||
if (stat)
|
if (stat)
|
||||||
FATAL( "i/o error occurred while closing %s", files[i].fname );
|
WARNING("i/o error occurred while closing %s", files[i].fname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user