From: alex Date: Tue, 23 Nov 2021 07:18:39 +0000 (-0800) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=2e09269cf6b4969c3649cfa196350afded11732a;p=seeder ... --- diff --git a/src/block.c b/src/block.c index 4c67062..bbff2ea 100644 --- a/src/block.c +++ b/src/block.c @@ -123,7 +123,7 @@ int block_pad(struct block *p) { 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; diff --git a/src/file.c b/src/file.c index 9dc7a58..e0a279f 100644 --- a/src/file.c +++ b/src/file.c @@ -81,7 +81,9 @@ int file_hash(struct file *file_p, int piece_length) { // 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; } diff --git a/test/unit/block.tests.c b/test/unit/block.tests.c index dffd667..984bcf9 100644 --- a/test/unit/block.tests.c +++ b/test/unit/block.tests.c @@ -183,10 +183,6 @@ static void block_pad_basic_test() { 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;