Date: Wed, 8 Jun 2016 17:24:57 +0000 (UTC) From: Garrett Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r301652 - stable/9/usr.sbin/bsnmpd/tools/libbsnmptools Message-ID: <201606081724.u58HOvqW028832@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Wed Jun 8 17:24:57 2016 New Revision: 301652 URL: https://svnweb.freebsd.org/changeset/base/301652 Log: MFstable/10 r300475: 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/9/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Directory Properties: stable/9/ (props changed) stable/9/usr.sbin/ (props changed) stable/9/usr.sbin/bsnmpd/ (props changed) Modified: stable/9/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c ============================================================================== --- stable/9/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Wed Jun 8 17:21:15 2016 (r301651) +++ stable/9/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Wed Jun 8 17:24:57 2016 (r301652) @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201606081724.u58HOvqW028832>