Module Name:    src
Committed By:   riastradh
Date:           Mon May 20 11:20:53 UTC 2024

Modified Files:
        src/external/gpl3/gcc/dist/libstdc++-v3/config/io: basic_file_stdio.cc
        src/tests/lib/libstdc++: t_sync_with_stdio.sh

Log Message:
libstdc++: Don't try to fflush stdin.

It doesn't work.  It's undefined behaviour.  On NetBSD, it will fail
with EBADF, if fd 0 isn't open for write, or if fd 0 is open for
write, it will write heap garbage to fd 0.

   If stream points to an output stream or an update stream in which
   the most recent operation was not input, the fflush function causes
   any unwritten data for that stream to be delivered to the host
   environment to be written to the file; otherwise, the behavior is
   undefined.

   (ISO C11 and ISO C17, Sec. 7.21.5.2 `The fflush function')

PR lib/58206
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114879


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.13 -r1.2 \
    src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libstdc++/t_sync_with_stdio.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc
diff -u src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc:1.1.1.13 src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc:1.2
--- src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc:1.1.1.13	Sun Jul 30 05:21:27 2023
+++ src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc	Mon May 20 11:20:53 2024
@@ -204,7 +204,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { this->close(); }
 
   __basic_file<char>*
-  __basic_file<char>::sys_open(__c_file* __file, ios_base::openmode)
+  __basic_file<char>::sys_open(__c_file* __file, ios_base::openmode __mode)
   {
     __basic_file* __ret = NULL;
     if (!this->is_open() && __file)
@@ -213,7 +213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	// POSIX guarantees that fflush sets errno on error, but C doesn't.
 	errno = 0;
 	do
-	  __err = fflush(__file);
+	  __err = (__mode == std::ios_base::in ? 0 : fflush(__file));
 	while (__err && errno == EINTR);
 	errno = __save_errno;
 	if (!__err)

Index: src/tests/lib/libstdc++/t_sync_with_stdio.sh
diff -u src/tests/lib/libstdc++/t_sync_with_stdio.sh:1.1 src/tests/lib/libstdc++/t_sync_with_stdio.sh:1.2
--- src/tests/lib/libstdc++/t_sync_with_stdio.sh:1.1	Sun Apr 28 01:21:27 2024
+++ src/tests/lib/libstdc++/t_sync_with_stdio.sh	Mon May 20 11:20:53 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: t_sync_with_stdio.sh,v 1.1 2024/04/28 01:21:27 riastradh Exp $
+#	$NetBSD: t_sync_with_stdio.sh,v 1.2 2024/05/20 11:20:53 riastradh Exp $
 #
 # Copyright (c) 2024 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -32,7 +32,6 @@ cin_nosync_head()
 cin_nosync_body()
 {
 	echo hello >in
-	atf_expect_fail "PR lib/58206: sync_with_stdio breaks reads from cin"
 	atf_check -o inline:'6\n' "$(atf_get_srcdir)"/h_cin_nosync <in
 }
 

Reply via email to