]> gitweb.hhaalo.de Git - discspan.git/commitdiff
fix: relloc bug of restfiles
authorBastian Dehn <hhaalo@arcor.de>
Sun, 24 Dec 2017 11:44:06 +0000 (12:44 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 24 Dec 2017 11:44:06 +0000 (12:44 +0100)
discspan.c

index f16cb3538e7e775335c71e5f8641d29c99ee5985..f7881fafe75394b1da6e041c69cee73f5323cf44 100644 (file)
@@ -139,14 +139,17 @@ int splitter(struct file_size *input, const char *output,
                }
        }
        fclose(out);
-       restcount--;
 
        printHumanReadSize(output, splitgroesse);
 
-       if(restcount > 0)
+       if(restcount > 0) {
                memcpy(input, rest, length * sizeof(struct file_size));
+               input = (struct file_size *)
+                       realloc(input, restcount * sizeof(struct file_size));
+       }
 
        free(rest);
+       restcount--;
        return restcount;
 }
 
@@ -212,8 +215,6 @@ int main(int argc, char *argv[])
        while(s_length > 0) {
                sprintf(outname, "%s%03d", output, num++);
                s_length = splitter(fs, outname, split, s_length);
-               fs = (struct file_size *)
-                       realloc(fs, s_length * sizeof(struct file_size));
        }
 
        free(fs);