From d29cb84f52f93e060c2ec0f020f56fea0636428d Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 9 Jun 2015 18:11:34 +1200 Subject: Moved mallocs inside their if()s, various whitespace removals --- fractal-gen.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'fractal-gen.c') diff --git a/fractal-gen.c b/fractal-gen.c index 79f2de7..6ce9867 100644 --- a/fractal-gen.c +++ b/fractal-gen.c @@ -44,11 +44,8 @@ int main(int argc, char **argv) assert(iterat > 0); assert(cores > 0); - // Allocated memory for sections, bailing upon failure - sections = malloc(sizeof(data_section)*cores); - - - if (sections == NULL) + // Allocate memory for sections + if ((sections = malloc(sizeof(data_section)*cores)) == NULL) { perror("malloc"); return EXIT_FAILURE; @@ -65,18 +62,13 @@ int main(int argc, char **argv) sections[i].power = power; sections[i].iterat = iterat; -int s; - // A bit complex, icky, will document later if (i < (size%cores)) - s = (size*((int)(size/cores)+1)); + x = (size*((int)(size/cores)+1)); else - s = (size*(int)(size/cores)); - - sections[i].data = malloc(s); - + x = (size*(int)(size/cores)); - if (sections[i].data == NULL) + if ((sections[i].data = malloc(x)) == NULL) { fprintf(stderr, "\n"); perror("malloc"); @@ -88,7 +80,7 @@ int s; free(sections); return EXIT_FAILURE; } - fprintf(stderr, " -> Thread #%d (%d)\r", i+1, s); + fprintf(stderr, " -> Thread #%d (%d bytes data area)\r", i+1, x); pthread_create(§ions[i].thread, NULL, generator, &(sections[i])); } -- cgit v1.1