Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdio restore change from rev 1.23 "Avoid undefined...
details: https://anonhg.NetBSD.org/src/rev/d8aaf647cd86
branches: trunk
changeset: 980526:d8aaf647cd86
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Sun Feb 07 15:54:09 2021 +0000
description:
restore change from rev 1.23 "Avoid undefined behavior in fread(3)", mistakely
removed as part __SNBF optimization
diffstat:
lib/libc/stdio/fread.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diffs (46 lines):
diff -r 0f37135f8ae0 -r d8aaf647cd86 lib/libc/stdio/fread.c
--- a/lib/libc/stdio/fread.c Sun Feb 07 15:51:11 2021 +0000
+++ b/lib/libc/stdio/fread.c Sun Feb 07 15:54:09 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fread.c,v 1.25 2021/02/01 17:50:53 jdolecek Exp $ */
+/* $NetBSD: fread.c,v 1.26 2021/02/07 15:54:09 jdolecek Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93";
#else
-__RCSID("$NetBSD: fread.c,v 1.25 2021/02/01 17:50:53 jdolecek Exp $");
+__RCSID("$NetBSD: fread.c,v 1.26 2021/02/07 15:54:09 jdolecek Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -81,8 +81,6 @@
_DIAGASSERT(buf != NULL);
FLOCKFILE(fp);
- if (fp->_r < 0)
- fp->_r = 0;
total = resid;
p = buf;
@@ -115,12 +113,18 @@
return (count);
}
+ if (fp->_r <= 0) {
+ /* Nothing to read on enter, refill the buffers. */
+ goto refill;
+ }
+
while (resid > (size_t)(r = fp->_r)) {
(void)memcpy(p, fp->_p, (size_t)r);
fp->_p += r;
/* fp->_r = 0 ... done in __srefill */
p += r;
resid -= r;
+refill:
if (__srefill(fp)) {
/* no more input: return partial result */
FUNLOCKFILE(fp);
Home |
Main Index |
Thread Index |
Old Index