From 40147a74e792373a0d2a27b301820c4070cfcaac Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 20 Jul 2017 11:39:29 +0300 Subject: [PATCH] Replace deprecated rewind to fseek in cordxtra rewind (unlike fseek) does not report whether the operation failed. * cord/cordxtra.c (CORD_from_file_lazy_inner, CORD_from_file_lazy, CORD_from_file): Replace rewind(f) to fseek(f, 0l, SEEK_SET) with error checking; adjust ABORT message in case of fseek and ftell failure. --- cord/cordxtra.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/cord/cordxtra.c b/cord/cordxtra.c index 751b2ed..8a66799 100644 --- a/cord/cordxtra.c +++ b/cord/cordxtra.c @@ -592,11 +592,10 @@ CORD CORD_from_file_lazy_inner(FILE * f, size_t len) /* world is multi-threaded. */ char buf[1]; - if (fread(buf, 1, 1, f) > 1) { - /* Just to suppress "unused result" compiler warning. */ - ABORT("fread unexpected result"); + if (fread(buf, 1, 1, f) > 1 + || fseek(f, 0l, SEEK_SET) != 0) { + ABORT("Bad f argument or I/O failure"); } - rewind(f); } state -> lf_file = f; for (i = 0; i < CACHE_SZ/LINE_SZ; i++) { @@ -611,13 +610,11 @@ CORD CORD_from_file_lazy(FILE * f) { register long len; - if (fseek(f, 0l, SEEK_END) != 0) { - ABORT("Bad fd argument - fseek failed"); + if (fseek(f, 0l, SEEK_END) != 0 + || (len = ftell(f)) < 0 + || fseek(f, 0l, SEEK_SET) != 0) { + ABORT("Bad f argument or I/O failure"); } - if ((len = ftell(f)) < 0) { - ABORT("Bad fd argument - ftell failed"); - } - rewind(f); return(CORD_from_file_lazy_inner(f, (size_t)len)); } @@ -627,13 +624,11 @@ CORD CORD_from_file(FILE * f) { register long len; - if (fseek(f, 0l, SEEK_END) != 0) { - ABORT("Bad fd argument - fseek failed"); - } - if ((len = ftell(f)) < 0) { - ABORT("Bad fd argument - ftell failed"); + if (fseek(f, 0l, SEEK_END) != 0 + || (len = ftell(f)) < 0 + || fseek(f, 0l, SEEK_SET) != 0) { + ABORT("Bad f argument or I/O failure"); } - rewind(f); if (len < LAZY_THRESHOLD) { return(CORD_from_file_eager(f)); } else { -- 2.7.4