Permalink
Browse files

Handle rounding issue that caused an infinite loop until the kernel e…

…ntropy buffer got past a multiple of 8 bits of entropy.
  • Loading branch information...
1 parent 026a944 commit 953e896a92032f994e2fe30bb09e8858a2f7b8f0 @mikemol mikemol committed Apr 2, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/entbuff.c
View
6 src/entbuff.c
@@ -332,12 +332,14 @@ int main(int argc, char* argv[])
entcnt = check_ent();
if ( (entcnt > entthresh_high) || (entcnt < entthresh_low) )
{
- if(entcnt > entthresh_high)
+ // entcnt and entthresh_* are in bits, but we can only work in multiples
+ // of 8 bits.
+ if(((entcnt - entthresh_high) / 8) > 0)
{
// Let's pull some bytes in for later.
write_to_buffer((entcnt - entthresh_high) / 8);
}
- else if(entcnt < entthresh_low)
+ else if(((entthresh_low - entcnt) / 8) > 0)
{
// Let's get that back up to the threshold.
read_from_buffer((entthresh_low - entcnt) / 8);

0 comments on commit 953e896

Please sign in to comment.