pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:1:   /*   || 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.165 2004/09/16 17:36:42 grubba Exp $ + || $Id: array.c,v 1.166 2004/09/17 14:52:20 nilsson Exp $   */      #include "global.h"   #include "svalue.h"   #include "array.h"   #include "object.h"   #include "las.h"   #include "stralloc.h"   #include "interpret.h"   #include "opcodes.h"
pike.git/src/array.c:20:   #include "pike_memory.h"   #include "gc.h"   #include "main.h"   #include "pike_security.h"   #include "stuff.h"   #include "bignum.h"   #include "cyclic.h"   #include "multiset.h"   #include "mapping.h"    - RCSID("$Id: array.c,v 1.165 2004/09/16 17:36:42 grubba Exp $"); + RCSID("$Id: array.c,v 1.166 2004/09/17 14:52:20 nilsson Exp $");      PMOD_EXPORT struct array empty_array=   {    PIKE_CONSTANT_MEMOBJ_INIT(1), /* Never free */    &weak_empty_array, /* Next */    0, /* previous */    0, /* Size = 0 */    0, /* malloced Size = 0 */    0, /* no types */    0, /* no flags */
pike.git/src/array.c:84:   {    struct array *v;    ptrdiff_t e;       if(size+extra_space == 0)    {    add_ref(&empty_array);    return &empty_array;    }    +  /* Limits size to (1<<29)-4 */    if( (size+extra_space-1) >    (ULONG_MAX-sizeof(struct array))/sizeof(struct svalue) )    Pike_error("Too large array (memory size exceeds size of size_t)\n");    v=(struct array *)malloc(sizeof(struct array)+    (size+extra_space-1)*sizeof(struct svalue));    if(!v)    Pike_error(msg_out_of_mem);       GC_ALLOC(v);   
pike.git/src/array.c:750:   #undef XARGS      /* The sort is stable. */   INT32 *get_order(struct array *v, cmpfun fun)   {    INT32 e, *current_order;    ONERROR tmp;       if(!v->size) return 0;    +  /* Overlow safe: ((1<<29)-4)*4 < ULONG_MAX */    current_order=(INT32 *)xalloc(v->size * sizeof(INT32));    SET_ONERROR(tmp, free, current_order);    for(e=0; e<v->size; e++) current_order[e]=e;       get_order_fsort(current_order,    current_order+v->size-1,    fun,    ITEM(v));       UNSET_ONERROR(tmp);
pike.git/src/array.c:1054:   /* This sort is stable. The return value is like the one from    * get_alpha_order. */   PMOD_EXPORT INT32 *stable_sort_array_destructively(struct array *v)   {    INT32 *current_order;    ONERROR tmp;    int e;       if(!v->size) return NULL;    +  /* Overlow safe: ((1<<29)-4)*4 < ULONG_MAX */    current_order=(INT32 *)xalloc(v->size * sizeof(INT32));    SET_ONERROR(tmp, free, current_order);    for(e=0; e<v->size; e++) current_order[e]=e;       low_stable_sort_svalues (0, v->size - 1, ITEM (v), current_order, v->size);       UNSET_ONERROR (tmp);    return current_order;   }   
pike.git/src/array.c:1321: Inside #if defined(PIKE_DEBUG)
   array_check_type_field(b);    }   #endif    if(!(a->type_field & b->type_field) &&    !((a->type_field | b->type_field) & BIT_OBJECT))    {    /* do smart optimizations */    switch(opcode)    {    case PIKE_ARRAY_OP_AND: +  /* Trivially overflow safe */    ret=(INT32 *)xalloc(sizeof(INT32));    *ret=0;    return ret;       case PIKE_ARRAY_OP_SUB: -  +  /* Overlow safe: ((1<<29)-4+1)*4 < ULONG_MAX */    ptr=ret=(INT32 *)xalloc(sizeof(INT32)*(a->size+1));    *(ptr++)=a->size;    for(i=0;i<a->size;i++) *(ptr++)=i;    return ret;    }    }       /* Note: The following is integer overflow safe as long as    * sizeof(struct svalue) >= 2*sizeof(INT32).    */
pike.git/src/array.c:1622:    }   #endif       SET_ONERROR(r1,do_free_array,a);    SET_ONERROR(r2,do_free_array,b);       if(a->refs==1 || !a->size)    {    arra=ITEM(a);    }else{ +  /* Overlow safe: ((1<<29)-4)*8 < ULONG_MAX */    arra=(struct svalue *)xalloc(a->size*sizeof(struct svalue));    MEMCPY(arra,ITEM(a),a->size*sizeof(struct svalue));    SET_ONERROR(r3,free,arra);    }       if(b->refs==1 || !b->size)    {    arrb=ITEM(b);    }else{ -  +  /* Overlow safe: ((1<<29)-4)*8 < ULONG_MAX */    arrb=(struct svalue *)xalloc(b->size*sizeof(struct svalue));    MEMCPY(arrb,ITEM(b),b->size*sizeof(struct svalue));    SET_ONERROR(r4,free,arrb);    }       set_sort_svalues(arra,arra+a->size-1);    set_sort_svalues(arrb,arrb+b->size-1);       ret=low_allocate_array(0,32);    SET_ONERROR(r5,do_free_array,ret);