From owner-svn-src-all@freebsd.org Mon May 23 06:01:05 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C2900B46C29; Mon, 23 May 2016 06:01:05 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9D6D217A3; Mon, 23 May 2016 06:01:05 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4N614tp001091; Mon, 23 May 2016 06:01:04 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4N6142W001090; Mon, 23 May 2016 06:01:04 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201605230601.u4N6142W001090@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Mon, 23 May 2016 06:01:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r300475 - stable/10/usr.sbin/bsnmpd/tools/libbsnmptools X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2016 06:01:05 -0000 Author: ngie Date: Mon May 23 06:01:04 2016 New Revision: 300475 URL: https://svnweb.freebsd.org/changeset/base/300475 Log: MFC r299710,r299711,r299763,r299783,r299811: r299710: Staticize global variables only used in bsnmpimport.c to fix -Wmissing-variable-declarations warnings r299711: Fold two malloc + memset(.., 0, ..) calls into equivalent calloc calls r299763: Mute -Wstrlcpy-strlcat-size warning by using nitems with the size of the buffer This is a no-op as the malloc above set the size of the buffer to the size used below, but this keeps things consistent in case the malloc call changes somehow. r299783: Convert tok from enum tok to int32_t in function calls get_token(..) returns int32_t, not enum tok, and in many cases tests for items not in enum tok (e.g. '('). Make the typing consistent with get_token, which includes a domino effect of changing enum tok to int32_t. r299811: Use strdup instead of malloc + strlcpy Fix error messages on failure for calloc/strdup Modified: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c ============================================================================== --- stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Mon May 23 05:52:47 2016 (r300474) +++ stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Mon May 23 06:01:04 2016 (r300475) @@ -140,9 +140,9 @@ struct input { LIST_ENTRY(input) link; }; -LIST_HEAD(, input) inputs = LIST_HEAD_INITIALIZER(inputs); -struct input *input = NULL; -int32_t pbchar = -1; +static LIST_HEAD(, input) inputs = LIST_HEAD_INITIALIZER(inputs); +static struct input *input = NULL; +static int32_t pbchar = -1; #define MAX_PATHS 100 @@ -301,18 +301,18 @@ static const struct { { NULL, 0, 0 } }; -struct { +static struct { /* Current OID type, regarding table membership. */ enum snmp_tbl_entry tbl_type; /* A pointer to a structure in table list to add to its members. */ struct snmp_index_entry *table_idx; } table_data; -struct asn_oid current_oid; -char nexttok[MAXSTR]; -u_long val; /* integer values */ -int32_t all_cond; /* all conditions are true */ -int32_t saved_token = -1; +static struct asn_oid current_oid; +static char nexttok[MAXSTR]; +static u_long val; /* integer values */ +static int32_t all_cond; /* all conditions are true */ +static int32_t saved_token = -1; /* Prepare the global data before parsing a new file. */ static void @@ -513,7 +513,7 @@ snmp_import_update_table(enum snmp_tbl_e } static int32_t -parse_enum(struct snmp_toolinfo *snmptoolctx, enum tok *tok, +parse_enum(struct snmp_toolinfo *snmptoolctx, int32_t *tok, struct enum_pairs *enums) { while ((*tok = gettoken(snmptoolctx)) == TOK_STR) { @@ -532,7 +532,7 @@ parse_enum(struct snmp_toolinfo *snmptoo } static int32_t -parse_subtype(struct snmp_toolinfo *snmptoolctx, enum tok *tok, +parse_subtype(struct snmp_toolinfo *snmptoolctx, int32_t *tok, enum snmp_tc *tc) { if ((*tok = gettoken(snmptoolctx)) != TOK_STR) { @@ -547,7 +547,7 @@ parse_subtype(struct snmp_toolinfo *snmp } static int32_t -parse_type(struct snmp_toolinfo *snmptoolctx, enum tok *tok, +parse_type(struct snmp_toolinfo *snmptoolctx, int32_t *tok, enum snmp_tc *tc, struct enum_pairs **snmp_enum) { int32_t syntax, mem; @@ -630,17 +630,15 @@ snmp_import_head(struct snmp_toolinfo *s static int32_t snmp_import_table(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *obj) { - int32_t i; + int32_t i, tok; enum snmp_tc tc; - enum tok tok; struct snmp_index_entry *entry; - if ((entry = malloc(sizeof(struct snmp_index_entry))) == NULL) { + if ((entry = calloc(1, sizeof(struct snmp_index_entry))) == NULL) { syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); return (-1); } - memset(entry, 0, sizeof(struct snmp_index_entry)); STAILQ_INIT(&(entry->index_list)); for (i = 0, tok = gettoken(snmptoolctx); i < SNMP_INDEXES_MAX; i++) { @@ -705,7 +703,7 @@ snmp_import_table(struct snmp_toolinfo * * Read everything after the syntax type that is certainly a leaf OID info. */ static int32_t -snmp_import_leaf(struct snmp_toolinfo *snmptoolctx, enum tok *tok, +snmp_import_leaf(struct snmp_toolinfo *snmptoolctx, int32_t *tok, struct snmp_oid2str *oid2str) { int32_t i, syntax; @@ -758,25 +756,23 @@ snmp_import_object(struct snmp_toolinfo { char *string; int i; - enum tok tok; + int32_t tok; struct snmp_oid2str *oid2str; if (snmp_import_head(snmptoolctx) < 0) return (-1); - if ((oid2str = malloc(sizeof(struct snmp_oid2str))) == NULL) { - syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); + if ((oid2str = calloc(1, sizeof(struct snmp_oid2str))) == NULL) { + syslog(LOG_ERR, "calloc() failed: %s", strerror(errno)); return (-1); } - if ((string = malloc(strlen(nexttok) + 1)) == NULL) { - syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); + if ((string = strdup(nexttok)) == NULL) { + syslog(LOG_ERR, "strdup() failed: %s", strerror(errno)); free(oid2str); return (-1); } - memset(oid2str, 0, sizeof(struct snmp_oid2str)); - strlcpy(string, nexttok, strlen(nexttok) + 1); oid2str->string = string; oid2str->strlen = strlen(nexttok); @@ -857,7 +853,7 @@ error: } static int32_t -snmp_import_tree(struct snmp_toolinfo *snmptoolctx, enum tok *tok) +snmp_import_tree(struct snmp_toolinfo *snmptoolctx, int32_t *tok) { while (*tok != TOK_EOF) { switch (*tok) { @@ -883,7 +879,7 @@ snmp_import_tree(struct snmp_toolinfo *s } static int32_t -snmp_import_top(struct snmp_toolinfo *snmptoolctx, enum tok *tok) +snmp_import_top(struct snmp_toolinfo *snmptoolctx, int32_t *tok) { enum snmp_tc tc; struct enum_type *t; @@ -940,7 +936,7 @@ static int32_t snmp_import(struct snmp_toolinfo *snmptoolctx) { int i; - enum tok tok; + int32_t tok; tok = gettoken(snmptoolctx);