summaryrefslogtreecommitdiffstats
path: root/contrib/bmake/parse.c
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2017-06-13 00:22:15 +0000
committersjg <sjg@FreeBSD.org>2017-06-13 00:22:15 +0000
commit288f3738be6e27e220023bc4b7657fe85362d81d (patch)
tree40cf6f102891991aa2f8a183d5abb857ef42e453 /contrib/bmake/parse.c
parent1017c991b1cd2684dcf01ef4801db4bfe18320b4 (diff)
downloadFreeBSD-src-288f3738be6e27e220023bc4b7657fe85362d81d.zip
FreeBSD-src-288f3738be6e27e220023bc4b7657fe85362d81d.tar.gz
Update bmake to 20170510
Approved by: re@
Diffstat (limited to 'contrib/bmake/parse.c')
-rw-r--r--contrib/bmake/parse.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/contrib/bmake/parse.c b/contrib/bmake/parse.c
index 6d2cfb4..b351fe1 100644
--- a/contrib/bmake/parse.c
+++ b/contrib/bmake/parse.c
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.214 2016/04/06 09:57:00 gson Exp $ */
+/* $NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.214 2016/04/06 09:57:00 gson Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: parse.c,v 1.214 2016/04/06 09:57:00 gson Exp $");
+__RCSID("$NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $");
#endif
#endif /* not lint */
#endif
@@ -138,6 +138,10 @@ __RCSID("$NetBSD: parse.c,v 1.214 2016/04/06 09:57:00 gson Exp $");
#include "buf.h"
#include "pathnames.h"
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#ifdef HAVE_MMAP
#include <sys/mman.h>
@@ -184,6 +188,7 @@ typedef struct IFile {
typedef enum {
Begin, /* .BEGIN */
Default, /* .DEFAULT */
+ DeleteOnError, /* .DELETE_ON_ERROR */
End, /* .END */
dotError, /* .ERROR */
Ignore, /* .IGNORE */
@@ -301,6 +306,7 @@ static const struct {
} parseKeywords[] = {
{ ".BEGIN", Begin, 0 },
{ ".DEFAULT", Default, 0 },
+{ ".DELETE_ON_ERROR", DeleteOnError, 0 },
{ ".END", End, 0 },
{ ".ERROR", dotError, 0 },
{ ".EXEC", Attribute, OP_EXEC },
@@ -537,7 +543,7 @@ loadfile(const char *path, int fd)
if (lf->buf != MAP_FAILED) {
/* succeeded */
if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') {
- char *b = malloc(lf->len + 1);
+ char *b = bmake_malloc(lf->len + 1);
b[lf->len] = '\n';
memcpy(b, lf->buf, lf->len++);
munmap(lf->buf, lf->maplen);
@@ -558,9 +564,15 @@ loadfile(const char *path, int fd)
while (1) {
assert(bufpos <= lf->len);
if (bufpos == lf->len) {
+ if (lf->len > SIZE_MAX/2) {
+ errno = EFBIG;
+ Error("%s: file too large", path);
+ exit(1);
+ }
lf->len *= 2;
lf->buf = bmake_realloc(lf->buf, lf->len);
}
+ assert(bufpos < lf->len);
result = read(fd, lf->buf + bufpos, lf->len - bufpos);
if (result < 0) {
Error("%s: read error: %s", path, strerror(errno));
@@ -576,7 +588,11 @@ loadfile(const char *path, int fd)
/* truncate malloc region to actual length (maybe not useful) */
if (lf->len > 0) {
+ /* as for mmap case, ensure trailing \n */
+ if (lf->buf[lf->len - 1] != '\n')
+ lf->len++;
lf->buf = bmake_realloc(lf->buf, lf->len);
+ lf->buf[lf->len - 1] = '\n';
}
#ifdef HAVE_MMAP
@@ -1093,15 +1109,15 @@ ParseDoSrc(int tOp, const char *src)
*-----------------------------------------------------------------------
*/
static int
-ParseFindMain(void *gnp, void *dummy)
+ParseFindMain(void *gnp, void *dummy MAKE_ATTR_UNUSED)
{
GNode *gn = (GNode *)gnp;
if ((gn->type & OP_NOTARGET) == 0) {
mainNode = gn;
Targ_SetMain(gn);
- return (dummy ? 1 : 1);
+ return 1;
} else {
- return (dummy ? 0 : 0);
+ return 0;
}
}
@@ -1139,10 +1155,10 @@ ParseAddDir(void *path, void *name)
*-----------------------------------------------------------------------
*/
static int
-ParseClearPath(void *path, void *dummy)
+ParseClearPath(void *path, void *dummy MAKE_ATTR_UNUSED)
{
Dir_ClearPath((Lst) path);
- return(dummy ? 0 : 0);
+ return 0;
}
/*-
@@ -1334,6 +1350,7 @@ ParseDoDependency(char *line)
* .BEGIN
* .END
* .ERROR
+ * .DELETE_ON_ERROR
* .INTERRUPT Are not to be considered the
* main target.
* .NOTPARALLEL Make only one target at a time.
@@ -1369,6 +1386,9 @@ ParseDoDependency(char *line)
(void)Lst_AtEnd(targets, gn);
DEFAULT = gn;
break;
+ case DeleteOnError:
+ deleteOnError = TRUE;
+ break;
case NotParallel:
maxJobs = 1;
break;
@@ -1597,7 +1617,8 @@ ParseDoDependency(char *line)
goto out;
}
*line = '\0';
- } else if ((specType == NotParallel) || (specType == SingleShell)) {
+ } else if ((specType == NotParallel) || (specType == SingleShell) ||
+ (specType == DeleteOnError)) {
*line = '\0';
}
@@ -1658,7 +1679,7 @@ ParseDoDependency(char *line)
Suff_SetNull(line);
break;
case ExObjdir:
- Main_SetObjdir(line);
+ Main_SetObjdir("%s", line);
break;
default:
break;
@@ -1674,10 +1695,12 @@ ParseDoDependency(char *line)
}
if (paths) {
Lst_Destroy(paths, NULL);
+ paths = NULL;
}
if (specType == ExPath)
Dir_SetPATH();
} else {
+ assert(paths == NULL);
while (*line) {
/*
* The targets take real sources, so we must beware of archive
@@ -1736,6 +1759,7 @@ ParseDoDependency(char *line)
}
out:
+ assert(paths == NULL);
if (curTargs)
Lst_Destroy(curTargs, NULL);
}
@@ -1858,7 +1882,7 @@ Parse_DoVar(char *line, GNode *ctxt)
* XXX Rather than counting () and {} we should look for $ and
* then expand the variable.
*/
- for (depth = 0, cp = line + 1; depth != 0 || *cp != '='; cp++) {
+ for (depth = 0, cp = line + 1; depth > 0 || *cp != '='; cp++) {
if (*cp == '(' || *cp == '{') {
depth++;
continue;
@@ -2539,7 +2563,7 @@ ParseTraditionalInclude(char *line)
if (*file == '\0') {
Parse_Error(PARSE_FATAL,
"Filename missing from \"include\"");
- return;
+ goto out;
}
for (file = all_files; !done; file = cp + 1) {
@@ -2554,6 +2578,7 @@ ParseTraditionalInclude(char *line)
Parse_include_file(file, FALSE, FALSE, silent);
}
+out:
free(all_files);
}
#endif
@@ -2604,6 +2629,7 @@ ParseGmakeExport(char *line)
*/
value = Var_Subst(NULL, value, VAR_CMD, VARF_WANTRES);
setenv(variable, value, 1);
+ free(value);
}
#endif
OpenPOWER on IntegriCloud