- /* sign extend if necessary */
- p = (char *) &netnum;
- sign = (0x80 & *(p+diff) );
- if ( sign && ((unsigned) len < sizeof(long)) ) {
- for ( i = 0; i < diff; i++ ) {
- *(p+i) = (unsigned char) 0xff;
+ if( len ) {
+ /* sign extend if necessary */
+ ber_len_t i;
+ ber_int_t netnum = 0x80 & buf[0] ? -1 : 0;
+
+ /* shift in the bytes */
+ for( i=0 ; i<len; i++ ) {
+ netnum = (netnum << 8 ) | buf[i];