p = p->next;
}
- while(i&&(i&(i-1))) {
+ while((i==1)||(i&&(i&(i-1)))) {
if(block_init(&(p->next))<0) { return -1; }
memset(p->next->hash,0,crypto_hash_sha256_BYTES);
p = p->next;
// pad to appropiate piece layer size
// i.e. so each piece layer tree is balanced
- if(block_pad(layer_p)<0) { return -1; }
+ for(int i=1;i<=ratio;i<<=1) {
+ if(block_pad(layer_p)<0) { return -1; }
+ }
while(ratio>1) {
if(block_merkle_layer(file_p->piece_layers)<0) { return -1; }
assert(block_init(&root)==1);
assert(block_pad(root)==1);
- assert(block_length(root)==1);
-
- assert(block_init(&(root->next))==1);
- assert(block_pad(root)==1);
assert(block_length(root)==2);
p = root->next;