Date: Mon, 5 Sep 2016 06:10:51 +0000 (UTC) From: "Andrey A. Chernov" <ache@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305412 - head/lib/libc/stdio Message-ID: <201609050610.u856AphK033741@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ache Date: Mon Sep 5 06:10:51 2016 New Revision: 305412 URL: https://svnweb.freebsd.org/changeset/base/305412 Log: Fix n == 1 case. Here should be no physical read (fill buffer) attempt (we read n - 1 chars with the room for NUL, see fgets()), and no NULL return. MFC after: 3 days Modified: head/lib/libc/stdio/fgetws.c Modified: head/lib/libc/stdio/fgetws.c ============================================================================== --- head/lib/libc/stdio/fgetws.c Mon Sep 5 05:07:40 2016 (r305411) +++ head/lib/libc/stdio/fgetws.c Mon Sep 5 06:10:51 2016 (r305412) @@ -62,10 +62,14 @@ fgetws_l(wchar_t * __restrict ws, int n, goto error; } + wsp = ws; + if (n == 1) + goto ok; + if (fp->_r <= 0 && __srefill(fp)) /* EOF or ferror */ goto error; - wsp = ws; + sret = 0; do { src = fp->_p; @@ -107,9 +111,9 @@ fgetws_l(wchar_t * __restrict ws, int n, if (wsp == ws) /* EOF */ goto error; +ok: *wsp = L'\0'; FUNLOCKFILE(fp); - return (ws); error:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201609050610.u856AphK033741>