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: Neil Jerram
Subject: Re: struct tail array, compare and segv
Date: Mon, 26 Feb 2007 20:01:29 +0000
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Kevin Ryde <address@hidden> writes:

> 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.

Looks good, except I'm not keen on the "goto bad_tail_size;".  It
would be marginally more friendly to have different error messages for
the two cases anyway.  (e.g. as below and "tail array not allowed if
struct has a zero length layout")

Regards,
        Neil

>
> --- 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]