guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: struct tail array, compare and segv


From: Kevin Ryde
Subject: Re: struct tail array, compare and segv
Date: Mon, 26 Feb 2007 10:47:11 +1100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

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)
     {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]