pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:19:   #include "error.h"      #ifdef _AIX   #include <net/nh.h>   #endif      #ifdef HAVE_NETINET_IN_H   #include <netinet/in.h>   #endif    + #include <math.h> +    struct encode_data   {    struct svalue counter;    struct mapping *encoded;    dynamic_buffer buf;   };      #define addstr(s, l) low_my_binary_strcat((s), (l), &(data->buf))   #define addchar(t) low_my_putchar((t),&(data->buf))      /* Current encoding: ┬Âik0 */   #define T_AGAIN 15   #define T_MASK 15 - #define T_NEG 32 - #define T_SMALL 64 + #define T_NEG 16 + #define T_SMALL 32   #define SIZE_SHIFT 6   #define MAX_SMALL (1<<(8-SIZE_SHIFT))   #define COUNTER_START -MAX_SMALL      /* Let's cram those bits... */   static void code_entry(int type, INT32 num, struct encode_data *data)   {    int t;    if(num<0)    {
pike.git/src/encode.c:109:    break;       case T_FLOAT:    {    if(val->u.float_number==0.0)    {    code_entry(T_FLOAT,0,data);    code_entry(T_FLOAT,0,data);    }else{    INT32 x,y; -  y=(int)ceil(log(val->u.float_number)/log(2.0))-31; +  y=(int)ceil(log(val->u.float_number)/log(2.0))-30;    x=(int)((val->u.float_number)*pow(2.0,(float)-y));    while(x && y && !(x&1))    {    x>>=1;    y++;    }    code_entry(T_FLOAT,x,data);    code_entry(T_FLOAT,y,data);    } -  +  break;    }       case T_ARRAY:    code_entry(T_ARRAY, val->u.array->size, data);    for(i=0; i<val->u.array->size; i++)    encode_value2(ITEM(val->u.array)+i, data);    break;       case T_MAPPING:    check_stack(2);
pike.git/src/encode.c:205:   {    unsigned char *data;    INT32 len;    INT32 ptr;    struct mapping *decoded;    struct svalue counter;   };      static int my_extract_char(struct decode_data *data)   { -  if(data->len >= data->ptr) +  if(data->ptr >= data->len)    error("Format error, not enough data in string.\n");    return data->data [ data->ptr++ ];   }      #define GETC() my_extract_char(data)      #define DECODE() \    what=GETC(); \    e=what>>SIZE_SHIFT; \    if(what & T_SMALL) { \
pike.git/src/encode.c:256:       case T_INT:    tmp=data->counter;    data->counter.u.integer++;    push_int(num);    break;       case T_STRING:    tmp=data->counter;    data->counter.u.integer++; -  if(data->ptr + num >= data->len) +  if(data->ptr + num > data->len)    error("Failed to decode string. (string range error)\n");    push_string(make_shared_binary_string(data->data + data->ptr, num));    data->ptr+=num;    break;       case T_FLOAT:    {    INT32 num2=num;       tmp=data->counter;    data->counter.u.integer++;       DECODE();    push_float(num2 * pow(2.0, (double) num));    break;    } -  +     case T_ARRAY:    {    struct array *a=allocate_array(num);    tmp.type=T_ARRAY;    tmp.u.array=a;    mapping_insert(data->decoded, & data->counter, &tmp);    data->counter.u.integer++;       /* Since a reference to the array is stored in the mapping, we can    * safely decrease this reference here. Thus it will be automatically
pike.git/src/encode.c:379:   {    ONERROR err;    struct decode_data d, *data;    data=&d;    data->counter.type=T_INT;    data->counter.u.integer=COUNTER_START;    data->data=tmp->str;    data->len=tmp->len;    data->ptr=0;    -  +  if(data->len < 5) return 0;    if(GETC() != 182 ||    GETC() != 'k' ||    GETC() != 'e' ||    GETC() != '0')    return 0;       data->decoded=allocate_mapping(128);       SET_ONERROR(err, free_decode_data, data);    decode_value2(data);