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:
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to