Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Aug 2016 09:58:06 +0000 (UTC)
From:      "Andrey A. Chernov" <ache@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r304888 - stable/10/lib/libc/stdio
Message-ID:  <201608270958.u7R9w6VH082397@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ache
Date: Sat Aug 27 09:58:06 2016
New Revision: 304888
URL: https://svnweb.freebsd.org/changeset/base/304888

Log:
  MFC r304810
  
  Don't check for __SERR which may stick from one of any previous stdio
  functions.
  __SERR is for user and the rest of stdio code do not check it
  for error sensing internally, only set it.
  In vf(w)printf.c here it is more easy to save __SERR, clear and restore it.

Modified:
  stable/10/lib/libc/stdio/getdelim.c
  stable/10/lib/libc/stdio/vfprintf.c
  stable/10/lib/libc/stdio/vfwprintf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/stdio/getdelim.c
==============================================================================
--- stable/10/lib/libc/stdio/getdelim.c	Sat Aug 27 09:51:57 2016	(r304887)
+++ stable/10/lib/libc/stdio/getdelim.c	Sat Aug 27 09:58:06 2016	(r304888)
@@ -125,7 +125,7 @@ getdelim(char ** __restrict linep, size_
 
 	if (fp->_r <= 0 && __srefill(fp)) {
 		/* If fp is at EOF already, we just need space for the NUL. */
-		if (__sferror(fp) || expandtofit(linep, 1, linecapp))
+		if (!__sfeof(fp) || expandtofit(linep, 1, linecapp))
 			goto error;
 		FUNLOCKFILE(fp);
 		(*linep)[0] = '\0';
@@ -137,7 +137,7 @@ getdelim(char ** __restrict linep, size_
 		if (sappend(linep, &linelen, linecapp, fp->_p, fp->_r))
 			goto error;
 		if (__srefill(fp)) {
-			if (__sferror(fp))
+			if (!__sfeof(fp))
 				goto error;
 			goto done;	/* hit EOF */
 		}

Modified: stable/10/lib/libc/stdio/vfprintf.c
==============================================================================
--- stable/10/lib/libc/stdio/vfprintf.c	Sat Aug 27 09:51:57 2016	(r304887)
+++ stable/10/lib/libc/stdio/vfprintf.c	Sat Aug 27 09:58:06 2016	(r304888)
@@ -364,6 +364,7 @@ __vfprintf(FILE *fp, locale_t locale, co
 	int nextarg;            /* 1-based argument index */
 	va_list orgap;          /* original argument pointer */
 	char *convbuf;		/* wide to multibyte conversion result */
+	int savserr;
 
 	static const char xdigs_lower[16] = "0123456789abcdef";
 	static const char xdigs_upper[16] = "0123456789ABCDEF";
@@ -460,6 +461,9 @@ __vfprintf(FILE *fp, locale_t locale, co
 		return (EOF);
 	}
 
+	savserr = fp->_flags & __SERR;
+	fp->_flags &= ~__SERR;
+
 	convbuf = NULL;
 	fmt = (char *)fmt0;
 	argtable = NULL;
@@ -1031,6 +1035,8 @@ error:
 		free(convbuf);
 	if (__sferror(fp))
 		ret = EOF;
+	else
+		fp->_flags |= savserr;
 	if ((argtable != NULL) && (argtable != statargtable))
 		free (argtable);
 	return (ret);

Modified: stable/10/lib/libc/stdio/vfwprintf.c
==============================================================================
--- stable/10/lib/libc/stdio/vfwprintf.c	Sat Aug 27 09:51:57 2016	(r304887)
+++ stable/10/lib/libc/stdio/vfwprintf.c	Sat Aug 27 09:58:06 2016	(r304888)
@@ -444,6 +444,7 @@ __vfwprintf(FILE *fp, locale_t locale, c
 	int nextarg;		/* 1-based argument index */
 	va_list orgap;		/* original argument pointer */
 	wchar_t *convbuf;	/* multibyte to wide conversion result */
+	int savserr;
 
 	static const char xdigs_lower[16] = "0123456789abcdef";
 	static const char xdigs_upper[16] = "0123456789ABCDEF";
@@ -536,6 +537,9 @@ __vfwprintf(FILE *fp, locale_t locale, c
 		return (EOF);
 	}
 
+	savserr = fp->_flags & __SERR;
+	fp->_flags &= ~__SERR;
+
 	convbuf = NULL;
 	fmt = (wchar_t *)fmt0;
 	argtable = NULL;
@@ -1096,6 +1100,8 @@ error:
 		free(convbuf);
 	if (__sferror(fp))
 		ret = EOF;
+	else
+		fp->_flags |= savserr;
 	if ((argtable != NULL) && (argtable != statargtable))
 		free (argtable);
 	return (ret);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608270958.u7R9w6VH082397>