Branch: Tag:

2005-02-14

2005-02-14 15:54:59 by Martin Stjernholm <mast@lysator.liu.se>

Made array_set_flags more robust when the array is empty.

Rev: src/array.c:1.179

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: array.c,v 1.178 2004/12/22 18:46:14 grubba Exp $ + || $Id: array.c,v 1.179 2005/02/14 15:54:59 mast Exp $   */      #include "global.h"
181:   }      /** -  * Set flags on an array. If the array is empty, +  * Set the flags on an array. If the array is empty then only the +  * weak flag is significant.    */   PMOD_EXPORT struct array *array_set_flags(struct array *a, int flags)   {
189:    a->flags = flags;    else {    free_array(a); -  switch (flags) { -  case 0: -  add_ref(a = &empty_array); break; -  case ARRAY_WEAK_FLAG: -  add_ref(a = &weak_empty_array); break; -  default: -  Pike_fatal("Invalid flags %x\n", flags); +  if (flags & ARRAY_WEAK_FLAG) +  add_ref(a = &weak_empty_array); +  else +  add_ref(a = &empty_array);    } -  } +     return a;   }   
2206:       if (!a->size) {    add_ref(&empty_array); -  return array_set_flags(&empty_array, a->flags & ~ARRAY_LVALUE); +  return array_set_flags(&empty_array, a->flags);    }       ret=allocate_array_no_init(a->size,0);