in reply to Re: falling through cases?
in thread falling through cases?
If the input is not a multiple of 12 bytes, it needs to do this (from the original C version):
And you left out the $c += $length (using 32-bit integer overflow).switch(len) /* all the case statements fall through */ { case 11: c+=((ub4)k[10]<<24); case 10: c+=((ub4)k[9]<<16); case 9 : c+=((ub4)k[8]<<8); /* the first byte of c is reserved for the length */ case 8 : b+=((ub4)k[7]<<24); case 7 : b+=((ub4)k[6]<<16); case 6 : b+=((ub4)k[5]<<8); case 5 : b+=k[4]; case 4 : a+=((ub4)k[3]<<24); case 3 : a+=((ub4)k[2]<<16); case 2 : a+=((ub4)k[1]<<8); case 1 : a+=k[0]; /* case 0: nothing left to add */ } mix(a,b,c);
Hmm again... or is the . (chr(0)x11), $p, 12 taking the place of that, to fill out the last "gulp"?
So even if that's not quite right, your answer to how to write such a switch statement is "don't. a more natural way (at a higher level in the algorithm) in Perl suggests itself and prevents the need".
Back to the other thread: thanks for sharing fastest implementation of the mix() function you found in pure Perl.
|
|---|