diff options
author | Charles Longeau <chl@cvs.openbsd.org> | 2012-09-27 17:58:57 +0000 |
---|---|---|
committer | Charles Longeau <chl@cvs.openbsd.org> | 2012-09-27 17:58:57 +0000 |
commit | bad24a20111a04542ef10df25e711086eeee0039 (patch) | |
tree | 7eb665de8ee2e6ab3b99ee7311a92266758d8bcf /usr.sbin | |
parent | 81aae5e403320a67be478330dac28a4b677cf737 (diff) |
simplify calloc() + strlcpy()/memcpy() dance with xmemdup()
use xcalloc() helper
remove newly unused variable
ok gilles@ eric@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/map_db.c | 32 | ||||
-rw-r--r-- | usr.sbin/smtpd/mfa.c | 12 |
2 files changed, 12 insertions, 32 deletions
diff --git a/usr.sbin/smtpd/map_db.c b/usr.sbin/smtpd/map_db.c index 3f77c277e9e..43a2dd573d9 100644 --- a/usr.sbin/smtpd/map_db.c +++ b/usr.sbin/smtpd/map_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map_db.c,v 1.9 2012/09/21 16:40:20 eric Exp $ */ +/* $OpenBSD: map_db.c,v 1.10 2012/09/27 17:58:56 chl Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -123,10 +123,7 @@ map_db_compare(void *hdl, const char *key, enum map_kind kind, for (r = db->seq(db, &dbk, &dbd, R_FIRST); !r; r = db->seq(db, &dbk, &dbd, R_NEXT)) { - buf = calloc(dbk.size+1, 1); - if (buf == NULL) - fatalx("calloc"); - strlcpy(buf, dbk.data, dbk.size+1); + buf = xmemdup(dbk.data, dbk.size + 1, "map_db_compare"); log_debug("key: %s, buf: %s", key, buf); if (func(key, buf)) ret = 1; @@ -144,7 +141,6 @@ map_db_get_entry(void *hdl, const char *key, size_t *len) DBT dbk; DBT dbv; DB *db = hdl; - char *result = NULL; char pkey[MAX_LINE_SIZE]; /* workaround the stupidity of the DB interface */ @@ -156,14 +152,9 @@ map_db_get_entry(void *hdl, const char *key, size_t *len) if ((ret = db->get(db, &dbk, &dbv, 0)) != 0) return NULL; - result = calloc(dbv.size, 1); - if (result == NULL) - fatal("calloc"); - (void)strlcpy(result, dbv.data, dbv.size); - *len = dbv.size; - return result; + return xmemdup(dbv.data, dbv.size, "map_db_get_entry"); } static void * @@ -188,9 +179,8 @@ map_db_credentials(const char *key, char *line, size_t len) return NULL; *p++ = '\0'; - map_credentials = calloc(1, sizeof(struct map_credentials)); - if (map_credentials == NULL) - fatalx("calloc"); + map_credentials = xcalloc(1, sizeof *map_credentials, + "map_db_credentials"); if (strlcpy(map_credentials->username, line, sizeof(map_credentials->username)) >= @@ -217,9 +207,7 @@ map_db_alias(const char *key, char *line, size_t len) struct map_alias *map_alias = NULL; struct expandnode xn; - map_alias = calloc(1, sizeof(struct map_alias)); - if (map_alias == NULL) - fatalx("calloc"); + map_alias = xcalloc(1, sizeof *map_alias, "map_db_alias"); while ((subrcpt = strsep(&line, ",")) != NULL) { /* subrcpt: strip initial whitespace. */ @@ -256,9 +244,7 @@ map_db_virtual(const char *key, char *line, size_t len) struct map_virtual *map_virtual = NULL; struct expandnode xn; - map_virtual = calloc(1, sizeof(struct map_virtual)); - if (map_virtual == NULL) - fatalx("calloc"); + map_virtual = xcalloc(1, sizeof *map_virtual, "map_db_virtual"); /* domain key, discard value */ if (strchr(key, '@') == NULL) @@ -297,9 +283,7 @@ map_db_netaddr(const char *key, char *line, size_t len) { struct map_netaddr *map_netaddr = NULL; - map_netaddr = calloc(1, sizeof(struct map_netaddr)); - if (map_netaddr == NULL) - fatalx("calloc"); + map_netaddr = xcalloc(1, sizeof *map_netaddr, "map_db_netaddr"); if (! text_to_netaddr(&map_netaddr->netaddr, line)) goto error; diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c index 667e333a119..98caa1580c9 100644 --- a/usr.sbin/smtpd/mfa.c +++ b/usr.sbin/smtpd/mfa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfa.c,v 1.69 2012/09/19 19:40:36 eric Exp $ */ +/* $OpenBSD: mfa.c,v 1.70 2012/09/27 17:58:56 chl Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -106,17 +106,13 @@ mfa_imsg(struct imsgev *iev, struct imsg *imsg) if (iev->proc == PROC_PARENT) { switch (imsg->hdr.type) { case IMSG_CONF_START: - env->sc_filters = calloc(1, sizeof *env->sc_filters); - if (env->sc_filters == NULL) - fatal(NULL); + env->sc_filters = xcalloc(1, sizeof *env->sc_filters, + "mfa_imsg"); TAILQ_INIT(env->sc_filters); return; case IMSG_CONF_FILTER: - filter = calloc(1, sizeof *filter); - if (filter == NULL) - fatal(NULL); - memcpy(filter, (struct filter *)imsg->data, sizeof (*filter)); + filter = xmemdup(imsg->data, sizeof *filter, "mfa_imsg"); TAILQ_INSERT_TAIL(env->sc_filters, filter, f_entry); return; |