...
authoralex <[email protected]>
Tue, 23 Nov 2021 07:18:39 +0000 (23:18 -0800)
committeralex <[email protected]>
Tue, 23 Nov 2021 07:18:39 +0000 (23:18 -0800)
src/block.c
src/file.c
test/unit/block.tests.c

index 4c6706257b3f56143ec30d3ad7de16839d21a101..bbff2eafc32299a4fd19850a76f2ead9fd0ce4b8 100644 (file)
@@ -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;
index 9dc7a58d0d8ea5f6a5419b8ba0ba1dfa20f54c0c..e0a279fc25a7d66e278ccb96c3cf6b874b4885ab 100644 (file)
@@ -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; }
index dffd667dbb160035c502b69c45e8af1e99708b72..984bcf9ef9c84ed018f40243d567d8a776435299 100644 (file)
@@ -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;