aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-09 21:55:48 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-09 22:01:31 +0200
commitda540383a99d13009e66e34bce13804647e264bc (patch)
treecd35661db4bfd796b5ea3980d7862a68973138ab
parentb9dde5d325655037ab804469a1557c7c4a4dcfc6 (diff)
downloadbuild-da540383a99d13009e66e34bce13804647e264bc.tar.gz
Allocate inside condition
-rw-r--r--build.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/build.c b/build.c
index f0b497e..4efcede 100644
--- a/build.c
+++ b/build.c
@@ -38,14 +38,13 @@ main(int argc, char *argv[])
struct stat sb, ssb;
/* Allocate memory. */
- for (i = 0; i < MAXCMDS; i++) {
- cmd[i] = malloc(MAXCMD*sizeof(char));
- if (!cmd[i]) err(1, "malloc");
- }
- dep = malloc(MAXDEP*sizeof(char));
- if (!dep) err(1, "malloc");
- tgt = malloc(MAXTGT*sizeof(char));
- if (!tgt) err(1, "malloc");
+ for (i = 0; i < MAXCMDS; i++)
+ if (!(cmd[i] = malloc(MAXCMD)))
+ err(1, "malloc");
+ if (!(dep = malloc(MAXDEP)))
+ err(1, "malloc");
+ if (!(tgt = malloc(MAXTGT)))
+ err(1, "malloc");
tgt[0] = dep[0] = 0;
@@ -73,8 +72,8 @@ main(int argc, char *argv[])
/* Process dependencies and commands in each file. */
for (i = icmd = 0; i < argc; i++, icmd = 0) {
- fp = fopen(argv[i], "r");
- if (!fp) err(1, "fopen");
+ if (!(fp = fopen(argv[i], "r")))
+ err(1, "fopen");
/* Read line by line, at most twenty. */
for (j = 0; j < 20 && fgets(buf, MAXBUF, fp); j++) {