Branch: Tag:

2008-05-12

2008-05-12 13:24:44 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed bug in array_insert() where the array size could be reset to zero.
Fixed spello in comment.

Rev: src/array.c:1.208

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.207 2008/05/11 14:55:52 mast Exp $ + || $Id: array.c,v 1.208 2008/05/12 13:24:44 grubba Exp $   */      #include "global.h"
384:   }      /** -  * Insert an svalue into an array and grow the array if nessesary. +  * Insert an svalue into an array and grow the array if necessary.    */   PMOD_EXPORT struct array *array_insert(struct array *v,struct svalue *s,INT32 index)   {
418:    ret->type_field = v->type_field;       MEMCPY(ITEM(ret), ITEM(v), sizeof(struct svalue) * index); -  MEMCPY(ITEM(ret)+index+1, ITEM(v)+index, sizeof(struct svalue) * (v->size-index)); +  MEMCPY(ITEM(ret)+index+1, ITEM(v)+index, +  sizeof(struct svalue) * (v->size-index));    assert_free_svalue (ITEM(ret) + index); -  v->size=0; +  if (v->refs == 1) { +  /* Optimization: Steal the references. */ +  v->size = 0; +  } else if (v->type_field & BIT_REF_TYPES) { +  /* Adjust the references. */ +  int e = v->size; +  struct svalue *s = ITEM(ret); +  while (e--) { +  if (s->type <= MAX_REF_TYPE) add_ref(s->u.dummy); +  s++; +  } +  }    free_array(v);    v=ret;    }