src/ber_int.c
int ber_decinteger(const char *buf, Odr_int *val, int max)
{
    unsigned long long uval = 0;
    int i, len;
    int res;
    const unsigned char *b = (const unsigned char *) buf;

    if ((res = ber_declen((const char *) b, &len, max)) < 0)
        return -1;
    if (len+res > max || len < 0) /* out of bounds or indefinite encoding */
        return -1;
    if (len > (int) sizeof(uval))  /* let's be reasonable, here */
        return -1;
    b += res;

    if (*b & 0x80)
        for (i = 0; i < (int) sizeof(uval) - len; i++)
            uval = (uval << 8) + 0xFF;
    for (i = 0; i < len; i++)
        uval = (uval << 8) + b[i];
    *val = uval;
    b += len;
    return (const char *) b - buf;
}
/*
 * Returns: Number of bytes read or 0 if no match, -1 if error.
 */
Number of bytes read or 0 if no match, -1 if error.
Number of bytes read or 0 if no match - 1 if error .
int ber_decinteger(const char *buf, Odr_int *val, int max)
{
    unsigned long long uval = 0;
    int i, len;
    int res;
    const unsigned char *b = (const unsigned char *) buf;
    if ((res = ber_declen((const char *) b, &len, max)) < 0)
        return -1;
    if (len+res > max || len < 0) 
        return -1;
    if (len > (int) sizeof(uval))  
        return -1;
    b += res;
    if (*b & 0x80)
        for (i = 0; i < (int) sizeof(uval) - len; i++)
            uval = (uval << 8) + 0xFF;
    for (i = 0; i < len; i++)
        uval = (uval << 8) + b[i];
    *val = uval;
    b += len;
    return (const char *) b - buf;
}
int ber_decinteger ( const char * buf , Odr_int * val , int max ) { unsigned long long uval = 0 ; int i , len ; int res ; const unsigned char * b = ( const unsigned char * ) buf ; if ( ( res = ber_declen ( ( const char * ) b , & len , max ) ) < 0 ) return -1 ; if ( len + res > max || len < 0 ) return -1 ; if ( len > ( int ) sizeof ( uval ) ) return -1 ; b += res ; if ( * b & 0x80 ) for ( i = 0 ; i < ( int ) sizeof ( uval ) - len ; i ++ ) uval = ( uval << 8 ) + 0xFF ; for ( i = 0 ; i < len ; i ++ ) uval = ( uval << 8 ) + b [ i ] ; * val = uval ; b += len ; return ( const char * ) b - buf ; }
Returns: Number of bytes read or 0 if no match, -1 if error.
Returns : Number of bytes read or 0 if no match - 1 if error .
/* out of bounds or indefinite encoding */ /* let's be reasonable, here */