]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change: realloc in main function
authorBastian Dehn <hhaalo@arcor.de>
Sun, 24 Dec 2017 09:22:12 +0000 (10:22 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 24 Dec 2017 09:22:12 +0000 (10:22 +0100)
discspan.c

index 68c2df09f2a314ad82f1e65004d6c84685676e7b..e01c2a9c537b7fffd93f23f95e064e2c1796deee 100644 (file)
@@ -92,7 +92,6 @@ unsigned long fill_array_from_file(FILE *in, struct file_size *fs,
        }
        lines--;
 
-       fs = (struct file_size *)realloc(fs, lines * sizeof(struct file_size));
 
        if(ignore != NULL)
                fclose(ignore);
@@ -142,18 +141,17 @@ int splitter(struct file_size *input, const char *output,
                        rest[restcount++] = input[i];
                }
        }
+       restcount--;
        fclose(out);
 
        printHumanReadSize(output, splitgroesse);
 
        if(restcount > 0) {
                memcpy(input, rest, length * sizeof(struct file_size));
-               input = (struct file_size *)realloc(input, restcount * sizeof(struct file_size));
        }
 
        free(rest);
-       // -1 weil vor Schleifenende nochmal incrementiert wird
-       return restcount - 1;
+       return restcount;
 }
 
 int main(int argc, char *argv[])
@@ -202,6 +200,7 @@ int main(int argc, char *argv[])
        int s_length = get_array_length(in);
        struct file_size *fs = (struct file_size *)malloc((s_length + 1) * sizeof(struct file_size));
        s_length = fill_array_from_file(in, fs, split);
+       fs = (struct file_size *)realloc(fs, s_length * sizeof(struct file_size));
        fclose(in);
 
        // sortieren
@@ -212,6 +211,7 @@ 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);