Tue Sep 17 11:04:50 1996 James G. Smith <jsmith@cygnus.co.uk>
authorJackie Smith Cashion <jsmith@redhat.com>
Tue, 17 Sep 1996 10:10:35 +0000 (10:10 +0000)
committerJackie Smith Cashion <jsmith@redhat.com>
Tue, 17 Sep 1996 10:10:35 +0000 (10:10 +0000)
* run.c (main): Explicitly cast malloc() parameter.

This is needed because for certain builds the size field being given
to malloc() is actually 64bits long, and without a cast or malloc
prototype the resulting value used by malloc() depended on the host
endianness, and how long long paramaters are passed into functions.

sim/common/ChangeLog
sim/common/run.c

index 8d825a7bb29e60dfbe193363e401b38ccf57d3cc..502ba653e2819b8c7aba1c39bc35e3beff33b671 100644 (file)
@@ -1,3 +1,7 @@
+Tue Sep 17 11:04:50 1996  James G. Smith  <jsmith@cygnus.co.uk>
+
+       * run.c (main): Explicitly cast malloc() parameter.
+
 Thu Sep 12 11:27:21 1996  Michael Meissner  <meissner@tiktok.cygnus.com>
 
        * run.c (sim_bfd): New global to hold the bfd pointer for the
index 982d99c7ad88a734c225181d4695be3819332a20..76cc48a5dea88762530b7adeddae0ab4d87d0cd9 100644 (file)
@@ -112,13 +112,22 @@ main (ac, av)
   for (s = abfd->sections; s; s = s->next)
   if (abfd && (s->flags & SEC_LOAD))
     {
-      unsigned char *buffer = (unsigned char *)malloc (bfd_section_size (abfd, s));
-      bfd_get_section_contents (abfd,
-                               s,
-                               buffer,
-                               0,
-                               bfd_section_size (abfd, s));
-      sim_write (s->vma, buffer, bfd_section_size (abfd, s));
+      unsigned char *buffer = (unsigned char *)malloc ((size_t)(bfd_section_size (abfd, s)));
+      if (buffer != NULL)
+        {
+          bfd_get_section_contents (abfd,
+                                    s,
+                                    buffer,
+                                    0,
+                                    bfd_section_size (abfd, s));
+          sim_write (s->vma, buffer, bfd_section_size (abfd, s));
+        }
+      else
+        {
+          fprintf (stderr, "run: failed to allocate section buffer: %s\n", 
+                   bfd_errmsg(bfd_get_error()));
+          exit (1);
+        }
     }
 
   start_address = bfd_get_start_address (abfd);