svn commit: r305412 - head/lib/libc/stdio

Andrey A. Chernov ache at FreeBSD.org
Mon Sep 5 06:10:53 UTC 2016


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:


More information about the svn-src-all mailing list