Code:
int bnum_op_shl( bnum_t num, bnum_t const val ) {
int ret = bnum_mem_chk( num );
size_t mov, bit, i;
bnum_t max = {bnum_init};
bit_t n, v;
if ( ret != 0 ) return ret;
ret = bnum_mem_chk( val );
if ( ret != 0 ) return ret;
if ( bnum_op_nil( val ) )
return 0;
max = int2bnum( &mov, sizeof(size_t), 0 );
mov = num.width;
if ( bnum_op_gte( val, max ) )
return bnum_op_muv( num, 0 );
/* Here onwards should be the only faulty code */
mov = B_WIDTH;
n = v = num.stop;
while ( bnum_op_gth( val, max ) ) {
v.byte--;
v.b -= B_WIDTH;
mov += B_WIDTH;
}
--mov;
while ( bnum_op_lth( val, max ) ) {
v = bit_op_dec(v);
--mov;
}
while ( v.b ) {
n = bit_op_dec(n);
v = bit_op_dec(v);
if ( val.value[v.byte] & v.bit )
num.value[n.byte] |= n.bit;
else if ( num.value[n.bit] & n.bit )
num.value[n.byte] ^= n.bit;
}
while ( n.b ) {
n = bit_op_dec(n);
if ( num.value[n.bit] & n.bit )
num.value[n.byte] ^= n.bit;
}
return 0;
}
And if you're curious the full output:
Code:
make run (in directory: /media/lee/ZXUIJI_1TB/github/code/bnum)
gcc -o ../code.elf ../print.o ../predef.o ../chk.o ../add.o ../code.o ../open.o ../mem_inc.o ../shut.o ../init_and_term.o ../get.o ../bnum/bit.o ../bnum/cmp.o ../bnum/math.o ../bnum/div.o
./../code.elf
Testing Integer Comparisons...
comparison( 846930886, 'n', 1804289383 ) call 0
rstarted 570; rstopped 570, nstarted 570, nstopped 571
!num 0, 0
comparison( 1714636915, '=', 1681692777 ) call 1
rstarted 573; rstopped 574, nstarted 574, nstopped 575
num == val 0, 0
comparison( 424238335, '!', 1957747793 ) call 2
rstarted 576; rstopped 577, nstarted 577, nstopped 578
num != val 1, 1
comparison( 1649760492, '>', 719885386 ) call 3
rstarted 579; rstopped 579, nstarted 580, nstopped 580
num >= val 1, 1
comparison( 1189641421, 'g', 596516649 ) call 4
rstarted 582; rstopped 582, nstarted 582, nstopped 583
num > val 1, 1
comparison( 1350490027, '<', 1025202362 ) call 5
rstarted 584; rstopped 585, nstarted 585, nstopped 586
num <= val 0, 0
comparison( 1102520059, 'l', 783368690 ) call 6
rstarted 587; rstopped 587, nstarted 588, nstopped 588
num < val 0, 0
Testing Single Integer Operations...
operation1('~',2044897763) call 0
rstarted 590, rstopped 590, nstarted 590, nstopped 591
~num -2044897764, -2044897764
operation1('+',1967513926) call 1
rstarted 593, rstopped 593, nstarted 593, nstopped 594
++num 1967513927, 1967513927
operation1('-',1365180540) call 2
rstarted 595, rstopped 596, nstarted 596, nstopped 597
--num 1365180539, 1365180539
Testing Double Integer Operations...
operation2(304089172,'&',1540383426) call 0
rstarted 598, rstopped 599, nstarted 599, nstopped 600
num & val 301989952, 301989952
operation2(35005211,'|',1303455736) call 1
rstarted 602, rstopped 602, nstarted 602, nstopped 604
num | val 1337403387, 1337403387
operation2(294702567,'^',521595368) call 2
rstarted 605, rstopped 606, nstarted 606, nstopped 607
num ^ val 243672079, 243672079
operation2(336465782,'<',5) call 3
rstarted 605, rstopped 606, nstarted 606, nstopped 607
num << val 336465782, 336465782
Operation not permitted
../makefile:15: recipe for target 'run' failed
make: *** [run] Error 1
Compilation failed.