From 5562af42b475b5dd9510c3aae83fb5c13b2461aa Mon Sep 17 00:00:00 2001 From: ru Date: Tue, 30 Mar 2010 13:46:40 +0000 Subject: - Handle calloc() allocation failures. - Fixed a comment. - 2 -> EXIT_FAILURE in some places. - errx() -> err() where appropriate. PR: 144644 Submitted by: Garrett Cooper --- usr.sbin/config/config.y | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'usr.sbin/config/config.y') diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y index 9425daf..19f2779 100644 --- a/usr.sbin/config/config.y +++ b/usr.sbin/config/config.y @@ -166,6 +166,8 @@ Config_spec: CPU Save_id { struct cputype *cp = (struct cputype *)calloc(1, sizeof (struct cputype)); + if (cp == NULL) + err(EXIT_FAILURE, "calloc"); cp->cpu_name = $2; SLIST_INSERT_HEAD(&cputype, cp, cpu_next); } | @@ -197,6 +199,8 @@ Config_spec: struct hint *hint; hint = (struct hint *)calloc(1, sizeof (struct hint)); + if (hint == NULL) + err(EXIT_FAILURE, "calloc"); hint->hint_name = $2; STAILQ_INSERT_TAIL(&hints, hint, hint_next); hintmode = 1; @@ -331,6 +335,8 @@ newfile(char *name) struct files_name *nl; nl = (struct files_name *) calloc(1, sizeof *nl); + if (nl == NULL) + err(EXIT_FAILURE, "calloc"); nl->f_name = name; STAILQ_INSERT_TAIL(&fntab, nl, f_next); } @@ -364,6 +370,8 @@ newdev(char *name) } np = (struct device *) calloc(1, sizeof *np); + if (np == NULL) + err(EXIT_FAILURE, "calloc"); np->d_name = name; STAILQ_INSERT_TAIL(&dtab, np, d_next); } @@ -422,6 +430,8 @@ newopt(struct opt_head *list, char *name, char *value, int append) } op = (struct opt *)calloc(1, sizeof (struct opt)); + if (op == NULL) + err(EXIT_FAILURE, "calloc"); op->op_name = name; op->op_ownfile = 0; op->op_value = value; -- cgit v1.1