From owner-svn-src-head@freebsd.org Mon Sep 5 06:10:53 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0D70DB96601; Mon, 5 Sep 2016 06:10:53 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C5C24973; Mon, 5 Sep 2016 06:10:52 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u856ApTi033742; Mon, 5 Sep 2016 06:10:51 GMT (envelope-from ache@FreeBSD.org) Received: (from ache@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u856AphK033741; Mon, 5 Sep 2016 06:10:51 GMT (envelope-from ache@FreeBSD.org) Message-Id: <201609050610.u856AphK033741@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ache set sender to ache@FreeBSD.org using -f From: "Andrey A. Chernov" Date: Mon, 5 Sep 2016 06:10:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305412 - head/lib/libc/stdio X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Sep 2016 06:10:53 -0000 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: