This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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]

[PATCH] Fix FILE structure alignment


A recent change turned the offset field of the FILE structure from a
32-bit integer into a 64-bit integer on some platforms.  On some
architectures this results in a wrong alignment of the FILE structure
allocated by __sfmoreglue().  On SPARC for example you can get now an
aligment exception.

newlib/
2013-03-15  Sebastian Huber <sebastian.huber@embedded-brains.de>

	* newlib/libc/stdio/findfp.c (glue_with_file): New.
	(__sfmoreglue): Use glue_with_file to avoid alignment problems.
---
 newlib/libc/stdio/findfp.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 0beb1e5..7ab3bdb 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -77,23 +77,27 @@ _DEFUN(std, (ptr, flags, file, data),
 #endif
 }
 
+struct glue_with_file {
+  struct _glue glue;
+  FILE file;
+};
+
 struct _glue *
 _DEFUN(__sfmoreglue, (d, n),
        struct _reent *d _AND
        register int n)
 {
-  struct _glue *g;
-  FILE *p;
+  struct glue_with_file *g;
 
-  g = (struct _glue *) _malloc_r (d, sizeof (*g) + n * sizeof (FILE));
+  g = (struct glue_with_file *)
+    _malloc_r (d, sizeof (*g) + (n - 1) * sizeof (FILE));
   if (g == NULL)
     return NULL;
-  p = (FILE *) (g + 1);
-  g->_next = NULL;
-  g->_niobs = n;
-  g->_iobs = p;
-  memset (p, 0, n * sizeof (FILE));
-  return g;
+  g->glue._next = NULL;
+  g->glue._niobs = n;
+  g->glue._iobs = &g->file;
+  memset (&g->file, 0, n * sizeof (FILE));
+  return &g->glue;
 }
 
 /*
-- 
1.7.7


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