Commit 08656747 by Steve Ellcey Committed by Steve Ellcey

transfer.c (us_read): Use memcpy/memset instead of assignment to fill unaligned buffer.

	* libgfortran/io/transfer.c (us_read): Use memcpy/memset
	instead of assignment to fill unaligned buffer.
	(us_write): Ditto.
	(next_record_w): Ditto.

From-SVN: r92143
parent 0cc1b879
2004-12-14 Steve Ellcey <sje@cup.hp.com>
* libgfortran/io/transfer.c (us_read): Use memcpy/memset
instead of assignment to fill unaligned buffer.
(us_write): Ditto.
(next_record_w): Ditto.
2004-12-05 Steven G. Kargl <kargls@comcast.net> 2004-12-05 Steven G. Kargl <kargls@comcast.net>
PR libfortran/18966 PR libfortran/18966
......
...@@ -827,11 +827,12 @@ transfer_complex (void *p, int kind) ...@@ -827,11 +827,12 @@ transfer_complex (void *p, int kind)
static void static void
us_read (void) us_read (void)
{ {
gfc_offset *p; char *p;
int n; int n;
gfc_offset i;
n = sizeof (gfc_offset); n = sizeof (gfc_offset);
p = (gfc_offset *) salloc_r (current_unit->s, &n); p = salloc_r (current_unit->s, &n);
if (p == NULL || n != sizeof (gfc_offset)) if (p == NULL || n != sizeof (gfc_offset))
{ {
...@@ -839,7 +840,8 @@ us_read (void) ...@@ -839,7 +840,8 @@ us_read (void)
return; return;
} }
current_unit->bytes_left = *p; memcpy (&i, p, sizeof (gfc_offset));
current_unit->bytes_left = i;
} }
...@@ -849,11 +851,11 @@ us_read (void) ...@@ -849,11 +851,11 @@ us_read (void)
static void static void
us_write (void) us_write (void)
{ {
gfc_offset *p; char *p;
int length; int length;
length = sizeof (gfc_offset); length = sizeof (gfc_offset);
p = (gfc_offset *) salloc_w (current_unit->s, &length); p = salloc_w (current_unit->s, &length);
if (p == NULL) if (p == NULL)
{ {
...@@ -861,7 +863,7 @@ us_write (void) ...@@ -861,7 +863,7 @@ us_write (void)
return; return;
} }
*p = 0; /* Bogus value for now. */ memset (p, '\0', sizeof (gfc_offset)); /* Bogus value for now. */
if (sfree (current_unit->s) == FAILURE) if (sfree (current_unit->s) == FAILURE)
generate_error (ERROR_OS, NULL); generate_error (ERROR_OS, NULL);
...@@ -1285,7 +1287,7 @@ next_record_w (int done) ...@@ -1285,7 +1287,7 @@ next_record_w (int done)
if (p == NULL) if (p == NULL)
goto io_error; goto io_error;
*((gfc_offset *) p) = m; memcpy (p, &m, sizeof (gfc_offset));
if (sfree (current_unit->s) == FAILURE) if (sfree (current_unit->s) == FAILURE)
goto io_error; goto io_error;
...@@ -1296,7 +1298,7 @@ next_record_w (int done) ...@@ -1296,7 +1298,7 @@ next_record_w (int done)
if (p == NULL) if (p == NULL)
generate_error (ERROR_OS, NULL); generate_error (ERROR_OS, NULL);
*((gfc_offset *) p) = m; memcpy (p, &m, sizeof (gfc_offset));
if (sfree (current_unit->s) == FAILURE) if (sfree (current_unit->s) == FAILURE)
goto io_error; goto io_error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment