From: Ivan Maidanski Date: Thu, 20 Jul 2017 08:39:29 +0000 (+0300) Subject: Replace deprecated rewind to fseek in cordxtra X-Git-Tag: v7.6.2~108 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d50d04d99619f68081dbe16a997eec10482c245b;p=gc 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. --- diff --git a/cord/cordxtra.c b/cord/cordxtra.c index 312f47b1..11019642 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 {