summaryrefslogtreecommitdiff
path: root/usr.bin/make/meta.c
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-12-20 22:36:40 +0000
committerrillig <rillig@NetBSD.org>2020-12-20 22:36:40 +0000
commit683e06eed55345caaffbf0dece32da4f3200663e (patch)
treeca45f26aa1aff2bc914a6ce534a04452b536073a /usr.bin/make/meta.c
parentfdf38b65a43637883471ca5b58ea4259929704d0 (diff)
make(1): fix undefined behavior in meta_oodate
Do not increment a null pointer. Do not assign to a variable twice in the same statement. To be fair, this may be safe because of the sequence point when the function is called, but anyway, it looks too close to undefined behavior.
Diffstat (limited to 'usr.bin/make/meta.c')
-rw-r--r--usr.bin/make/meta.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.bin/make/meta.c b/usr.bin/make/meta.c
index 0342fc0a3fc..d0260db3a2b 100644
--- a/usr.bin/make/meta.c
+++ b/usr.bin/make/meta.c
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.163 2020/12/20 22:12:36 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.164 2020/12/20 22:36:40 rillig Exp $ */
/*
* Implement 'meta' mode.
@@ -820,9 +820,10 @@ meta_job_output(Job *job, char *cp, const char *nl)
meta_prefix_len = strlen(meta_prefix);
}
if (strncmp(cp, meta_prefix, meta_prefix_len) == 0) {
- cp = strchr(cp+1, '\n');
- if (!cp++)
+ cp = strchr(cp + 1, '\n');
+ if (cp == NULL)
return;
+ cp++;
}
}
fprintf(pbm->mfp, "%s%s", cp, nl);
@@ -1527,7 +1528,7 @@ meta_oodate(GNode *gn, Boolean oodate)
warnx("%s: %d: line truncated at %u", fname, lineno, x);
break;
}
- cp = strchr(++cp, '\n');
+ cp = strchr(cp + 1, '\n');
} while (cp != NULL);
if (buf[x - 1] == '\n')
buf[x - 1] = '\0';