This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [committed] Fix PR pch/14940 on hppa hpux and linux


> On Fri, Dec 10, 2004 at 09:11:55PM -0500, John David Anglin wrote:
> > +  if (read (fd, base, size) == -1)
> > +    return -1;
> 
> Do you need to protect against short reads?  Or at least

While I didn't hit any short reads in testing, it's better to be safe
than sorry.  I also found in testing that I needed to provide a define
for MAP_FAILED on hppa1.1-hp-hpux10.20.

Tested on hppa2.0-hp-hpux11.11, hppa64-hp-hpux11.11, hppa1.1-hp-hpux10.20
and hppa-unknown-linux-gnu.  Committed to trunk.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)

2004-12-14  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

	* pa-host.c (MAP_FAILED): Define if not defined.
	(pa_gt_pch_use_address): Handle short reads.

Index: config/pa/pa-host.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa-host.c,v
retrieving revision 1.2
diff -u -3 -p -r1.2 pa-host.c
--- config/pa/pa-host.c	11 Dec 2004 02:08:26 -0000	1.2
+++ config/pa/pa-host.c	13 Dec 2004 03:06:03 -0000
@@ -26,6 +26,10 @@
 #include "hosthooks.h"
 #include "hosthooks-def.h"
 
+#ifndef MAP_FAILED
+#define MAP_FAILED (void *)-1L
+#endif
+
 static void *pa_gt_pch_get_address (size_t, int);
 static int pa_gt_pch_use_address (void *, size_t, int, size_t);
 
@@ -114,8 +118,16 @@ pa_gt_pch_use_address (void *base, size_
   if (lseek (fd, offset, SEEK_SET) == (off_t)-1)
     return -1;
 
-  if (read (fd, base, size) == -1)
-    return -1;
+  while (size)
+    {
+      ssize_t nbytes;
+
+      nbytes = read (fd, base, MIN (size, SSIZE_MAX));
+      if (nbytes <= 0)
+        return -1;
+      base = (char *) base + nbytes;
+      size -= nbytes;
+    }
 
   return 1;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]