I'm looking at this to allow non-zero tail array only when the layout
provides for it.  I think all the internal uses of structs have no
tail array (and a zero size) so that should all be ok.  Dunno if
anyone else might have used the tail size to get some sneaky extra
space.  Sounds like the wrong thing to do, but could always be
loosened up again later.

--- struct.c.~1.111.2.4.~	2007-02-22 09:37:43.000000000 +1100
+++ struct.c	2007-02-26 10:40:36.000000000 +1100
@@ -430,6 +430,27 @@
   layout = SCM_PACK (SCM_STRUCT_DATA (vtable) [scm_vtable_index_layout]);
   basic_size = scm_i_symbol_length (layout) / 2;
   tail_elts = scm_to_size_t (tail_array_size);
+
+  /* A tail array is only allowed if the layout fields string ends in "R",
+     "W" or "O". */
+  if (tail_elts != 0)
+    {
+      SCM layout_str, last_char;
+      int last_c;
+      
+      if (basic_size == 0)
+        {
+        bad_tail_size: 
+          SCM_MISC_ERROR ("tail array not allowed unless layout ends R, W, or O", SCM_EOL);
+        }
+
+      layout_str = scm_symbol_to_string (layout);
+      last_char = scm_string_ref (layout_str,
+                                  scm_from_size_t (2 * basic_size - 1));
+      if (! SCM_LAYOUT_TAILP (SCM_CHAR (last_char)))
+        goto bad_tail_size;
+    }
+    
   SCM_CRITICAL_SECTION_START;
   if (SCM_STRUCT_DATA (vtable)[scm_struct_i_flags] & SCM_STRUCTF_ENTITY)
     {
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel

Reply via email to