pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:8844:    if (args<=3 &&    (Pike_sp[1-args].type==T_INT &&    Pike_sp[2-args].type==T_INT))    {    INT_TYPE step,start;       get_all_args("enumerate", args, "%i%i%i", &n, &step, &start);    if (n<0)    SIMPLE_BAD_ARG_ERROR("enumerate",1,"int(0..)");    + #ifdef AUTO_BIGNUM +  { +  INT_TYPE tmp; +  +  /* this checks if +  * (n - 1) * step + start +  * will overflow. if it does, we continue with the slow path. If it does not, +  * adding step to start repeatedly will not overflow below. This check has +  * false positives, but is much simpler to check than e.g. doing one check +  * for every iteration +  */ +  if (DO_INT_TYPE_MUL_OVERFLOW(n-1, step, &tmp) || INT_TYPE_ADD_OVERFLOW(tmp, start)) +  goto slow_path; +  } + #endif +     pop_n_elems(args);    push_array(d=allocate_array(n));    for (i=0; i<n; i++)    {    ITEM(d)[i].u.integer=start; - #ifdef AUTO_BIGNUM -  if ((step>0 && start+step<start) || -  (step<0 && start+step>start)) /* overflow */ -  { -  pop_stack(); -  push_int(n); -  push_int(step); -  convert_stack_top_to_bignum(); -  push_int(start); -  convert_stack_top_to_bignum(); -  f_enumerate(3); -  return; -  } - #endif +     start+=step;    }    d->type_field = BIT_INT;    }    else if (args<=3 &&    ((Pike_sp[1-args].type==T_INT ||    Pike_sp[1-args].type==T_FLOAT) &&    (Pike_sp[2-args].type==T_INT ||    Pike_sp[2-args].type==T_FLOAT) ) )    {
pike.git/src/builtin_functions.c:8892:    for (i=0; i<n; i++)    {    d->item[i].u.float_number=start;    d->item[i].type=T_FLOAT;    start+=step;    }    d->type_field = BIT_FLOAT;    }    else    { -  TYPE_FIELD types = 0; +  TYPE_FIELD types; + slow_path: +  types = 0;    get_all_args("enumerate", args, "%i", &n);    if (n<0) SIMPLE_BAD_ARG_ERROR("enumerate",1,"int(0..)");    if (args>4) pop_n_elems(args-4);    push_array(d=allocate_array(n));    if (args<4)    {    push_svalue(Pike_sp-2); /* start */    for (i=0; i<n; i++)    {    assign_svalue_no_free(ITEM(d)+i,Pike_sp-1);