pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:12:   #include "pike_memory.h"   #include "pike_error.h"   #include "gc.h"   #include "bignum.h"   #include "interpret.h"   #include "operators.h"   #include "pike_float.h"   #include "pike_types.h"   #include "block_allocator.h"   #include "whitespace.h" + #include "stuff.h"      #include <errno.h>   #include <ctype.h>      #define SET_HSIZE(X) htable_mask=(htable_size=(X))-1   #define HMODULO(X) ((X) & (htable_mask))      static unsigned INT32 htable_mask;      #if (SIZEOF_LONG == 4) && defined(_LP64)
pike.git/src/stralloc.c:3239:   {    switch(ptr.shift)    {    case 0: return MKPCHARP(memchr(ptr.ptr,chr,len),0);    case 1: return MKPCHARP(MEMCHR1((p_wchar1 *)ptr.ptr,chr,len),1);    case 2: return MKPCHARP(MEMCHR2((p_wchar2 *)ptr.ptr,chr,len),2);    }    UNREACHABLE(MKPCHARP(0,0));   }    - #define DIGIT(x) (WIDE_ISDIGIT(x) ? (x) - '0' : \ -  WIDE_ISLOWER(x) ? (x) + 10 - 'a' : (x) + 10 - 'A') + #define DIGIT(x) ( (x)<256 ? hexdecode[x] : 16 )   #define MBASE ('z' - 'a' + 1 + 10)    - PMOD_EXPORT long STRTOL_PCHARP(PCHARP str, PCHARP *ptr, int base) + PMOD_EXPORT long STRTOL_PCHARP(PCHARP str, PCHARP *ptr, unsigned int base)   {    /* Note: Code duplication in strtol and pcharp_to_svalue_inumber. */       unsigned long val, mul_limit;    int c; -  int xx, neg = 0, add_limit, overflow = 0; +  unsigned add_limit, xx; +  int neg = 0, overflow = 0;       if (ptr) *ptr = str; -  if (base < 0 || base > MBASE) return 0; +  if (base > MBASE) return 0;    if (!WIDE_ISALNUM(c = EXTRACT_PCHARP(str)))    {    while (wide_isspace(c))    {    INC_PCHARP(str,1);    c=EXTRACT_PCHARP(str);    }    switch (c)    {    case '-':
pike.git/src/stralloc.c:3281:    if (!base)    {    if (c != '0')    base = 10;    else if (INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X')    base = 16;    else    base = 8;    }    -  if (!WIDE_ISALNUM(c) || (xx = DIGIT(c)) >= base) +  if ((val = DIGIT(c)) >= base)    return 0; /* no number formed */    if (base == 16 && c == '0' && isxdigit(INDEX_PCHARP(str,2)) &&    (INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X'))    {    INC_PCHARP(str,2);    c = EXTRACT_PCHARP(str); /* skip over leading "0x" or "0X" */ -  +  if ((val = DIGIT(c)) >= base) +  return 0; /* no number formed */    }       mul_limit = ((unsigned long)LONG_MAX)/base;    add_limit = (int) (LONG_MAX % base);    if (neg) {    if (++add_limit == base) {    add_limit = 0;    mul_limit++;    }    }    -  val=DIGIT(c); +     while(1)    {    INC_PCHARP(str,1);    c=EXTRACT_PCHARP(str); -  if(!(WIDE_ISALNUM(c) && (xx=DIGIT(c)) < base)) break; +  if((xx=DIGIT(c)) >= base) break;    if (val > mul_limit || (val == mul_limit && xx > add_limit)) {    overflow = 1;    } else    val = base * val + xx;    }       if (ptr) *ptr = str;    if (overflow) {    errno = ERANGE;    return neg ? LONG_MIN : LONG_MAX;
pike.git/src/stralloc.c:3376:    base,    maxlength);    UNSETJMP (recovery);    if(ptr) *(p_wchar0 **)ptr=tmp.ptr;    return ret;   }      PMOD_EXPORT int pcharp_to_svalue_inumber(struct svalue *r,    PCHARP str,    PCHARP *ptr, -  int base, +  unsigned int base,    ptrdiff_t maxlength)   {    /* Note: Code duplication in strtol and STRTOL_PCHARP. */       PCHARP str_start;       unsigned INT_TYPE val, mul_limit;    int c; -  int xx, neg = 0, add_limit, overflow = 0; +  unsigned int xx, add_limit; +  int neg = 0, overflow = 0;       maxlength--; /* max_length <= 0 means no max length. */    str_start = str;       /* In case no number is formed. */    SET_SVAL(*r, T_INT, NUMBER_NUMBER, integer, 0);    if(ptr != 0)    *ptr = str;    -  if(base < 0 || MBASE < base) +  if(MBASE < base)    return 0;       if(!WIDE_ISALNUM(c = EXTRACT_PCHARP(str)))    {    while(wide_isspace(c))    {    INC_PCHARP(str,1);    c = EXTRACT_PCHARP(str);    }   
pike.git/src/stralloc.c:3429:    if(c != '0')    base = 10;    else if(INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X')    base = 16;    else if(INDEX_PCHARP(str,1) == 'b' || INDEX_PCHARP(str,1) == 'B')    base = 2;    else    base = 8;    }    -  /* -  * For any base > 10, the digits incrementally following -  * 9 are assumed to be "abc...z" or "ABC...Z". -  */ -  if(!WIDE_ISALNUM(c) || (xx = DIGIT(c)) >= base) +  if((val=DIGIT(c)) >= base)    return 0; /* No number formed. */       if(c == '0' &&    ((base==16 && (INDEX_PCHARP(str,1)=='x' || INDEX_PCHARP(str,1)=='X')) ||    (base==2 && (INDEX_PCHARP(str,1)=='b' || INDEX_PCHARP(str,1)=='B'))) &&    INDEX_PCHARP(str,2) < 256 && /* Don't trust isxdigit... */    isxdigit(INDEX_PCHARP(str,2)))    {    /* Skip over leading "0x", "0X", "0b" or "0B". */    INC_PCHARP(str,2);    c=EXTRACT_PCHARP(str); -  +  if((val=DIGIT(c)) >= base) +  return 0; /* No number formed. */    }    str_start=str;       if (neg) {    mul_limit = (unsigned INT_TYPE) MIN_INT_TYPE / base;    add_limit = (int) ((unsigned INT_TYPE) MIN_INT_TYPE % base);    }    else {    mul_limit = MAX_INT_TYPE / base;    add_limit = (int) (MAX_INT_TYPE % base);    }    -  for(val = DIGIT(c); +  for(;    (INC_PCHARP(str,1), WIDE_ISALNUM(c = EXTRACT_PCHARP(str) )) &&    (xx = DIGIT(c)) < base &&    0 != maxlength--; )    {    if (val > mul_limit || (val == mul_limit && xx > add_limit))    overflow = 1;    else    val = base * val + xx;    }   
pike.git/src/stralloc.c:3556:    sign = EXTRACT_PCHARP(s) == '-' ? -1 : 1;    if (EXTRACT_PCHARP(s) == '-' || EXTRACT_PCHARP(s) == '+')    INC_PCHARP(s,1);       num = 0.0;    got_dot = 0;    got_digit = 0;    exponent = 0;    for (;; INC_PCHARP(s,1))    { -  if (EXTRACT_PCHARP(s)<256 && WIDE_ISDIGIT (EXTRACT_PCHARP(s))) +  if (EXTRACT_PCHARP(s)<256 && hexdecode[EXTRACT_PCHARP(s)])    {    got_digit = 1;       /* Make sure that multiplication by 10 will not overflow. */    if (num > DBL_MAX * 0.1)    /* The value of the digit doesn't matter, since we have already    gotten as many digits as can be represented in a `double'.    This doesn't necessarily mean the result will overflow.    The exponent may reduce it to within range.