public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] toplev.c: Process the failure when read fails for random_seed
@ 2014-12-29  4:05 Chen Gang S
  2014-12-29  8:23 ` Chen Gang S
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Chen Gang S @ 2014-12-29  4:05 UTC (permalink / raw)
  To: gcc-patches List, Jeff Law, Joseph S. Myers

[-- Attachment #1: Type: text/plain, Size: 1775 bytes --]

When failure occurs, random_seed may not be 0, so need reset it to 0
manually, or will let the next call init_random_seed() incorrect.  The
related warning:

  g++ -c  -DTARGET_NAME=\"parisc-gchen-linux\" -g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. -I../../gcc/gcc/../include -I../../gcc/gcc/../libcpp/include  -I../../gcc/gcc/../libdecnumber -I../../gcc/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc/gcc/../libbacktrace   -o toplev.o -MT toplev.o -MMD -MP -MF ./.deps/toplev.TPo ../../gcc/gcc/toplev.c
  ../../gcc/gcc/toplev.c: In function 'void init_local_tick()':
  ../../gcc/gcc/toplev.c:276:56: warning: ignoring return value of 'ssize_t read(int, void*, size_t)', declared with attribute warn_unused_result [-Wunused-result]

It passes testsuite under x86_64-apple-darwin14.0.0

/gcc
2014-12-27  Chen Gang  <gang.chen.5i5j@gmail.com>

	* toplev.c (init_local_tick): Process the failure when read
	fails for random_seed.
---
 gcc/toplev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/toplev.c b/gcc/toplev.c
index 7e06247..e5262be 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -273,7 +273,9 @@ init_local_tick (void)
       int fd = open ("/dev/urandom", O_RDONLY);
       if (fd >= 0)
         {
-          read (fd, &random_seed, sizeof (random_seed));
+          if (read (fd, &random_seed, sizeof (random_seed))
+              != sizeof (random_seed))
+            random_seed = 0;
           close (fd);
         }
 
-- 
1.9.3 (Apple Git-50)

[-- Attachment #2: 0001-toplev.c-Process-the-failure-when-read-fails-for-ran.patch --]
[-- Type: text/plain, Size: 2007 bytes --]

From 05faeede37f6e383f69a1398d355ea8ce3687583 Mon Sep 17 00:00:00 2001
From: Chen Gang <gang.chen@sunrus.com.cn>
Date: Sat, 27 Dec 2014 15:55:57 +0800
Subject: [PATCH] toplev.c: Process the failure when read fails for random_seed

When failure occurs, random_seed may not be 0, so need reset it to 0
manually, or will let the next call init_random_seed() incorrect.  The
related warning:

  g++ -c  -DTARGET_NAME=\"parisc-gchen-linux\" -g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. -I../../gcc/gcc/../include -I../../gcc/gcc/../libcpp/include  -I../../gcc/gcc/../libdecnumber -I../../gcc/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc/gcc/../libbacktrace   -o toplev.o -MT toplev.o -MMD -MP -MF ./.deps/toplev.TPo ../../gcc/gcc/toplev.c
  ../../gcc/gcc/toplev.c: In function 'void init_local_tick()':
  ../../gcc/gcc/toplev.c:276:56: warning: ignoring return value of 'ssize_t read(int, void*, size_t)', declared with attribute warn_unused_result [-Wunused-result]

It passes testsuite under x86_64-apple-darwin14.0.0

/gcc
2014-12-27  Chen Gang  <gang.chen.5i5j@gmail.com>

	* toplev.c (init_local_tick): Process the failure when read
	fails for random_seed.
---
 gcc/toplev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/toplev.c b/gcc/toplev.c
index 7e06247..e5262be 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -273,7 +273,9 @@ init_local_tick (void)
       int fd = open ("/dev/urandom", O_RDONLY);
       if (fd >= 0)
         {
-          read (fd, &random_seed, sizeof (random_seed));
+          if (read (fd, &random_seed, sizeof (random_seed))
+              != sizeof (random_seed))
+            random_seed = 0;
           close (fd);
         }
 
-- 
1.9.3 (Apple Git-50)


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2015-01-26 22:51 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-29  4:05 [PATCH] toplev.c: Process the failure when read fails for random_seed Chen Gang S
2014-12-29  8:23 ` Chen Gang S
2014-12-30 22:40   ` Joseph Myers
2014-12-31  5:28     ` Chen Gang S
2015-01-19 16:29     ` Chen Gang S
2015-01-20  2:34       ` Joseph Myers
2015-01-20  8:51         ` Chen Gang S
2014-12-30 22:26 ` Joseph Myers
2015-01-05 20:07 ` Jeff Law
2015-01-06  2:20   ` Chen Gang S
2015-01-21 10:43   ` Chen Gang S
2015-01-21 19:46     ` Mike Stump
2015-01-22 13:32       ` Chen Gang S
2015-01-22 17:11         ` Jeff Law
2015-01-22 20:28           ` Chen Gang S
2015-01-22 20:36             ` Jeff Law
2015-01-22 21:31               ` Chen Gang S
2015-01-25 22:07                 ` Gerald Pfeifer
2015-01-25 23:10                   ` Chen Gang S
2015-01-26 22:21                 ` Jeff Law
2015-01-26 23:57                   ` Chen Gang S

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).