diff src/lstream.c @ 456:e7ef97881643 r21-2-43

Import from CVS: tag r21-2-43
author cvs
date Mon, 13 Aug 2007 11:41:24 +0200
parents 576fb035e263
children 0784d089fdc9
line wrap: on
line diff
--- a/src/lstream.c	Mon Aug 13 11:40:56 2007 +0200
+++ b/src/lstream.c	Mon Aug 13 11:41:24 2007 +0200
@@ -179,11 +179,17 @@
     }
 }
 
+inline static size_t
+aligned_sizeof_lstream (size_t lstream_type_specific_size)
+{
+  return ALIGN_SIZE (offsetof (Lstream, data) + lstream_type_specific_size,
+		     ALIGNOF (max_align_t));
+}
+
 static size_t
 sizeof_lstream (const void *header)
 {
-  const Lstream *lstr = (const Lstream *) header;
-  return sizeof (*lstr) + lstr->imp->size - 1;
+  return aligned_sizeof_lstream (((const Lstream *) header)->imp->size);
 }
 
 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("stream", lstream,
@@ -231,15 +237,15 @@
       assert (lstream_type_count < countof (lstream_types));
       lstream_types[lstream_type_count] = imp;
       Vlstream_free_list[lstream_type_count] =
-	make_lcrecord_list (sizeof (*p) + imp->size - 1,
+	make_lcrecord_list (aligned_sizeof_lstream (imp->size),
 			    &lrecord_lstream);
       lstream_type_count++;
     }
 
   p = XLSTREAM (allocate_managed_lcrecord (Vlstream_free_list[i]));
   /* Zero it out, except the header. */
-  memset ((char *) p + sizeof (p->header), 0,
-	  sizeof (*p) - sizeof (p->header) + imp->size - 1);
+  memset ((char *) p + sizeof (p->header), '\0',
+	  aligned_sizeof_lstream (imp->size) - sizeof (p->header));
   p->imp = imp;
   Lstream_set_buffering (p, LSTREAM_BLOCK_BUFFERED, 0);
   p->flags = LSTREAM_FL_IS_OPEN;