From: Mozejko, MarcinX Date: Mon, 4 Jun 2018 14:13:35 +0000 (+0100) Subject: SNMP Agent plugin: Fix compability with netsnmp library version < 5.4.5 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4367c421fc62bbbb685d491415fe0cca6c990041;p=collectd.git SNMP Agent plugin: Fix compability with netsnmp library version < 5.4.5 Fix valgrind issues in snmp_agent_test.c. Remove unused variable from snmp_agent.c. Change-Id: I201a39743af3b59827acada9b24a15672d97436a Signed-off-by: Mozejko, MarcinX --- diff --git a/configure.ac b/configure.ac index 1e31e218..77451f3e 100644 --- a/configure.ac +++ b/configure.ac @@ -3814,7 +3814,7 @@ if test "x$with_libnetsnmp" = "xyes"; then LDFLAGS="$LDFLAGS $with_libnetsnmp_ldflags" AC_CHECK_LIB([netsnmp], [init_snmp], - [with_libnetsmp="yes"], + [with_libnetsnmp="yes"], [with_libnetsnmp="no (libnetsnmp not found)"] ) @@ -3822,6 +3822,62 @@ if test "x$with_libnetsnmp" = "xyes"; then fi if test "x$with_libnetsnmp" = "xyes"; then + SAVE_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $with_libnetsnmp_ldflags" + + AC_CHECK_LIB([netsnmp], [netsnmp_get_version], + [with_libnetsnmp="yes"], + [with_libnetsnmp="no (couldn't get libnetsnmp version)"] + ) + + LDFLAGS="$SAVE_LDFLAGS" +fi + +if test "x$with_libnetsnmp" = "xyes"; then + SAVE_CPPFLAGS="$CPPFLAGS" + SAVE_LDFLAGS="$LDFLAGS" + SAVE_LIBS="$LIBS" + CPPFLAGS="$CPPFLAGS $with_libnetsnmp_cppflags -Wall -Werror" + LDFLAGS="$LDFLAGS $with_libnetsnmp_ldflags" + LIBS="$LIBS -lnetsnmp" + + AC_CACHE_CHECK([whether netsnmp library has old API], + [c_cv_have_netsnmp_old_api], + [ + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM( + [[ + #include + #include + ]], + [[ + netsnmp_variable_list *key; + int val; + u_char type; + snmp_set_var_value(key, &val, sizeof(val)); + snmp_set_var_typed_value(key, type, &val, sizeof(val)); + return 0; + ]] + ) + ], + [c_cv_have_netsnmp_old_api="no"], + [c_cv_have_netsnmp_old_api="yes"] + ) + ] + ) + + if test "x$c_cv_have_netsnmp_old_api" = "xyes"; then + AC_DEFINE([HAVE_NETSNMP_OLD_API], [1], + ["Define 1 if you have old netsnmp API]") + fi + + CPPFLAGS="$SAVE_CPPFLAGS" + LDFLAGS="$SAVE_LDFLAGS" + LIBS="$SAVE_LIBS" +fi + +if test "x$with_libnetsnmp" = "xyes"; then BUILD_WITH_LIBNETSNMP_CPPFLAGS="$with_libnetsnmp_cppflags" BUILD_WITH_LIBNETSNMP_LDFLAGS="$with_libnetsnmp_ldflags" BUILD_WITH_LIBNETSNMP_LIBS="-lnetsnmp" @@ -3832,7 +3888,7 @@ AC_SUBST([BUILD_WITH_LIBNETSNMP_LDFLAGS]) AC_SUBST([BUILD_WITH_LIBNETSNMP_LIBS]) # }}} -# --with-libnetsmpagent {{{ +# --with-libnetsnmpagent {{{ AC_ARG_WITH([libnetsnmpagent], [AS_HELP_STRING([--with-libnetsnmpagent@<:@=PREFIX@:>@], [Path to libnetsnmpagent.])], [ diff --git a/src/daemon/plugin_mock.c b/src/daemon/plugin_mock.c index 3d5b92d5..a11d4f54 100644 --- a/src/daemon/plugin_mock.c +++ b/src/daemon/plugin_mock.c @@ -56,12 +56,14 @@ int plugin_register_init(const char *name, plugin_init_cb callback) { return ENOTSUP; } -int plugin_register_read(const char *name, int (*callback)(void)) { +int plugin_register_read(__attribute__((unused)) const char *name, + __attribute__((unused)) int (*callback)(void)) { return ENOTSUP; } -int plugin_register_write(const char *name, plugin_write_cb callback, - user_data_t const *ud) { +int plugin_register_write(__attribute__((unused)) const char *name, + __attribute__((unused)) plugin_write_cb callback, + __attribute__((unused)) user_data_t const *ud) { return ENOTSUP; } diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 8f556d85..ef037105 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -340,9 +340,8 @@ static int snmp_agent_validate_config(void) { return 0; } -static int snmp_agent_parse_index_key(const char *input, char *regex, - regex_t *regex_info, int gi, - regmatch_t *m) { +static int snmp_agent_parse_index_key(const char *input, regex_t *regex_info, + int gi, regmatch_t *m) { regmatch_t matches[MAX_MATCHES]; int ret = regexec(regex_info, input, MAX_MATCHES, matches, 0); @@ -526,8 +525,7 @@ static int snmp_agent_fill_index_list(table_definition_t *td, regmatch_t m = {-1, -1}; /* Parsing input string */ - ret = snmp_agent_parse_index_key(ptr, td->index_keys[i].regex, - &td->index_keys[i].regex_info, + ret = snmp_agent_parse_index_key(ptr, &td->index_keys[i].regex_info, td->index_keys[i].group, &m); if (ret != 0) { ERROR(PLUGIN_NAME ": Error executing regex"); @@ -543,11 +541,25 @@ static int snmp_agent_fill_index_list(table_definition_t *td, if (td->index_keys[i].type == ASN_INTEGER) { int val = strtol(ptr + m.rm_so, NULL, 0); + +#ifdef HAVE_NETSNMP_OLD_API + ret = snmp_set_var_value(key, (const u_char *)&val, sizeof(val)); +#else ret = snmp_set_var_value(key, &val, sizeof(val)); +#endif } else +#ifdef HAVE_NETSNMP_OLD_API + ret = snmp_set_var_value(key, (const u_char *)(ptr + m.rm_so), + m.rm_eo - m.rm_so); +#else ret = snmp_set_var_value(key, ptr + m.rm_so, m.rm_eo - m.rm_so); +#endif } else +#ifdef HAVE_NETSNMP_OLD_API + ret = snmp_set_var_value(key, (const u_char *)ptr, strlen(ptr)); +#else ret = snmp_set_var_value(key, ptr, strlen(ptr)); +#endif key = key->next_variable; } @@ -1041,12 +1053,24 @@ static int snmp_agent_form_reply(struct netsnmp_request_info_s *requests, requests->requestvb->type = td->index_keys[dd->index_key_pos].type; if (requests->requestvb->type == ASN_INTEGER) +#ifdef HAVE_NETSNMP_OLD_API + snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, + (const u_char *)key->val.integer, + sizeof(*key->val.integer)); +#else snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, key->val.integer, sizeof(*key->val.integer)); +#endif else /* OCTET_STR */ +#ifdef HAVE_NETSNMP_OLD_API snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, (const u_char *)key->val.string, strlen((const char *)key->val.string)); +#else + snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, + key->val.string, + strlen((const char *)key->val.string)); +#endif pthread_mutex_unlock(&g_agent->lock); diff --git a/src/snmp_agent_test.c b/src/snmp_agent_test.c index de13d2cf..68389fa9 100644 --- a/src/snmp_agent_test.c +++ b/src/snmp_agent_test.c @@ -28,6 +28,12 @@ #include "snmp_agent.c" #include "testing.h" +#define TEST_HOSTNAME "test_hostname" +#define TEST_PLUGIN "test_plugin" +#define TEST_PLUGIN_INST "test_plugin_inst" +#define TEST_TYPE "test_type" +#define TEST_TYPE_INST "test_type_inst" + DEF_TEST(oid_to_string) { oid_t o = {.oid = {1, 2, 3, 4, 5, 6, 7, 8, 9}, .oid_len = 9}; char oid_str[DATA_MAX_NAME_LEN]; @@ -43,10 +49,10 @@ DEF_TEST(oid_to_string) { DEF_TEST(format_name_scalar) { data_definition_t *dd = calloc(1, sizeof(*dd)); - dd->plugin = strdup("test_plugin"); - dd->plugin_instance = strdup("test_plugin_inst"); - dd->type = strdup("test_type"); - dd->type_instance = strdup("test_type_inst"); + dd->plugin = TEST_PLUGIN; + dd->plugin_instance = TEST_PLUGIN_INST; + dd->type = TEST_TYPE; + dd->type_instance = TEST_TYPE_INST; char name[DATA_MAX_NAME_LEN]; int ret = snmp_agent_format_name(name, sizeof(name), dd, NULL); @@ -56,10 +62,6 @@ DEF_TEST(format_name_scalar) { "example.com/test_plugin-test_plugin_inst/test_type-test_type_inst", name); - sfree(dd->plugin); - sfree(dd->plugin_instance); - sfree(dd->type); - sfree(dd->type_instance); sfree(dd); return 0; @@ -77,16 +79,16 @@ DEF_TEST(format_name_simple_index) { td->index_keys[1].source = INDEX_TYPE_INSTANCE; td->index_keys[1].type = ASN_OCTET_STR; dd->table = td; - dd->plugin = strdup("test_plugin"); - dd->type = strdup("test_type"); + dd->plugin = TEST_PLUGIN; + dd->type = TEST_TYPE; - char *plugin_inst = strdup("test_plugin_inst"); - char *type_inst = strdup("test_type_inst"); + const char plugin_inst[] = TEST_PLUGIN_INST; + const char type_inst[] = TEST_TYPE_INST; snmp_varlist_add_variable(&index_list_tmp, NULL, 0, ASN_OCTET_STR, - plugin_inst, strlen(plugin_inst)); - snmp_varlist_add_variable(&index_list_tmp, NULL, 0, ASN_OCTET_STR, type_inst, - strlen(type_inst)); + (const u_char *)plugin_inst, strlen(plugin_inst)); + snmp_varlist_add_variable(&index_list_tmp, NULL, 0, ASN_OCTET_STR, + (const u_char *)type_inst, strlen(type_inst)); build_oid_noalloc(index_oid.oid, sizeof(index_oid.oid), &index_oid.oid_len, NULL, 0, index_list_tmp); @@ -107,12 +109,8 @@ DEF_TEST(format_name_simple_index) { snmp_free_varbind(index_list_tmp); snmp_free_varbind(td->index_list_cont); - sfree(dd->plugin); - sfree(dd->type); sfree(dd); sfree(td); - sfree(plugin_inst); - sfree(type_inst); return 0; } @@ -129,26 +127,27 @@ DEF_TEST(format_name_regex_index) { td->index_keys[0].type = ASN_OCTET_STR; td->index_keys[1].source = INDEX_TYPE_INSTANCE; td->index_keys[1].type = ASN_INTEGER; - td->index_keys[1].regex = strdup("^vcpu_([0-9]{1,3})-cpu_[0-9]{1,3}$"); + td->index_keys[1].regex = "^vcpu_([0-9]{1,3})-cpu_[0-9]{1,3}$"; td->index_keys[1].group = 1; td->index_keys[2].source = INDEX_TYPE_INSTANCE; td->index_keys[2].type = ASN_INTEGER; - td->index_keys[2].regex = strdup("^vcpu_[0-9]{1,3}-cpu_([0-9]{1,3})$"); + td->index_keys[2].regex = "^vcpu_[0-9]{1,3}-cpu_([0-9]{1,3})$"; td->index_keys[2].group = 1; dd->table = td; - dd->plugin = strdup("test_plugin"); - dd->type = strdup("test_type"); + dd->plugin = TEST_PLUGIN; + dd->type = TEST_TYPE; - char *plugin_inst = strdup("test_plugin_inst"); - char *type_inst = strdup("vcpu_1-cpu_10"); + const char plugin_inst[] = TEST_PLUGIN_INST; int vcpu = 1; int cpu = 10; snmp_varlist_add_variable(&index_list_tmp, NULL, 0, ASN_OCTET_STR, - plugin_inst, strlen(plugin_inst)); - snmp_varlist_add_variable(&index_list_tmp, NULL, 0, ASN_INTEGER, &vcpu, 1); - snmp_varlist_add_variable(&index_list_tmp, NULL, 0, ASN_INTEGER, &cpu, 1); + (const u_char *)plugin_inst, strlen(plugin_inst)); + snmp_varlist_add_variable(&index_list_tmp, NULL, 0, ASN_INTEGER, + (const u_char *)&vcpu, 1); + snmp_varlist_add_variable(&index_list_tmp, NULL, 0, ASN_INTEGER, + (const u_char *)&cpu, 1); build_oid_noalloc(index_oid.oid, sizeof(index_oid.oid), &index_oid.oid_len, NULL, 0, index_list_tmp); @@ -194,14 +193,8 @@ DEF_TEST(format_name_regex_index) { c_avl_destroy(td->tokens[INDEX_TYPE_INSTANCE]); snmp_free_varbind(index_list_tmp); snmp_free_varbind(td->index_list_cont); - for (int i = 0; i < td->index_keys_len; i++) - sfree(td->index_keys[i].regex); - sfree(dd->plugin); - sfree(dd->type); sfree(dd); sfree(td); - sfree(plugin_inst); - sfree(type_inst); return 0; } @@ -258,11 +251,11 @@ DEF_TEST(fill_index_list_simple) { /* Preparing value list */ value_list_t *vl = calloc(1, sizeof(*vl)); assert(vl != NULL); - strncpy(vl->host, "test_hostname", DATA_MAX_NAME_LEN); - strncpy(vl->plugin, "test_plugin", DATA_MAX_NAME_LEN); - strncpy(vl->plugin_instance, "test_plugin_inst", DATA_MAX_NAME_LEN); - strncpy(vl->type, "test_type", DATA_MAX_NAME_LEN); - strncpy(vl->type_instance, "test_type_inst", DATA_MAX_NAME_LEN); + strncpy(vl->host, TEST_HOSTNAME, DATA_MAX_NAME_LEN); + strncpy(vl->plugin, TEST_PLUGIN, DATA_MAX_NAME_LEN); + strncpy(vl->plugin_instance, TEST_PLUGIN_INST, DATA_MAX_NAME_LEN); + strncpy(vl->type, TEST_TYPE, DATA_MAX_NAME_LEN); + strncpy(vl->type_instance, TEST_TYPE_INST, DATA_MAX_NAME_LEN); td->index_keys_len = 5; td->index_keys[0].source = INDEX_HOST; @@ -320,7 +313,7 @@ DEF_TEST(fill_index_list_regex) { /* Preparing value list */ value_list_t *vl = calloc(1, sizeof(*vl)); - strncpy(vl->plugin_instance, "test_plugin_inst", DATA_MAX_NAME_LEN); + strncpy(vl->plugin_instance, TEST_PLUGIN_INST, DATA_MAX_NAME_LEN); strncpy(vl->type_instance, "1test2test3", DATA_MAX_NAME_LEN); td->index_keys_len = 4; @@ -328,15 +321,15 @@ DEF_TEST(fill_index_list_regex) { td->index_keys[0].type = ASN_OCTET_STR; td->index_keys[1].source = INDEX_TYPE_INSTANCE; td->index_keys[1].type = ASN_INTEGER; - td->index_keys[1].regex = strdup("^([0-9])test[0-9]test[0-9]$"); + td->index_keys[1].regex = "^([0-9])test[0-9]test[0-9]$"; td->index_keys[1].group = 1; td->index_keys[2].source = INDEX_TYPE_INSTANCE; td->index_keys[2].type = ASN_INTEGER; - td->index_keys[2].regex = strdup("^[0-9]test([0-9])test[0-9]$"); + td->index_keys[2].regex = "^[0-9]test([0-9])test[0-9]$"; td->index_keys[2].group = 1; td->index_keys[3].source = INDEX_TYPE_INSTANCE; td->index_keys[3].type = ASN_INTEGER; - td->index_keys[3].regex = strdup("^[0-9]test[0-9]test([0-9])$"); + td->index_keys[3].regex = "^[0-9]test[0-9]test([0-9])$"; td->index_keys[3].group = 1; td->index_list_cont = NULL; @@ -388,7 +381,6 @@ DEF_TEST(fill_index_list_regex) { sfree(vl); for (int i = 0; i < td->index_keys_len; i++) { - sfree(td->index_keys[i].regex); regfree(&td->index_keys[i].regex_info); } sfree(td); @@ -408,7 +400,7 @@ DEF_TEST(config_index_key_source) { ci->values = calloc(1, sizeof(*ci->values)); assert(ci->values != NULL); ci->values_num = 1; - ci->values->value.string = strdup("PluginInstance"); + ci->values->value.string = "PluginInstance"; ci->values->type = OCONFIG_TYPE_STRING; int ret = snmp_agent_config_index_key_source(td, dd, ci); @@ -420,7 +412,6 @@ DEF_TEST(config_index_key_source) { EXPECT_EQ_INT(GROUP_UNUSED, td->index_keys[0].group); OK(td->index_keys[0].regex == NULL); - sfree(ci->values->value.string); sfree(ci->values); sfree(ci); sfree(td); @@ -445,7 +436,7 @@ DEF_TEST(config_index_key_regex) { ci->values = calloc(1, sizeof(*ci->values)); assert(ci->values != NULL); ci->values_num = 1; - ci->values->value.string = strdup("^([0-9])test[0-9]test[0-9]$"); + ci->values->value.string = "^([0-9])test[0-9]test[0-9]$"; ci->values->type = OCONFIG_TYPE_STRING; int ret = snmp_agent_config_index_key_regex(td, dd, ci); @@ -455,7 +446,6 @@ DEF_TEST(config_index_key_regex) { OK(td->tokens[INDEX_PLUGIN_INSTANCE] != NULL); c_avl_destroy(td->tokens[INDEX_PLUGIN_INSTANCE]); - sfree(ci->values->value.string); sfree(ci->values); sfree(ci); sfree(td->index_keys[0].regex); @@ -478,23 +468,23 @@ DEF_TEST(config_index_key) { ci->children_num = 3; ci->children = calloc(1, sizeof(*ci->children) * ci->children_num); - ci->children[0].key = strdup("Source"); + ci->children[0].key = "Source"; ci->children[0].parent = ci; ci->children[0].values_num = 1; ci->children[0].values = calloc(1, sizeof(*ci->children[0].values)); assert(ci->children[0].values != NULL); - ci->children[0].values->value.string = strdup("PluginInstance"); + ci->children[0].values->value.string = "PluginInstance"; ci->children[0].values->type = OCONFIG_TYPE_STRING; - ci->children[1].key = strdup("Regex"); + ci->children[1].key = "Regex"; ci->children[1].parent = ci; ci->children[1].values_num = 1; ci->children[1].values = calloc(1, sizeof(*ci->children[0].values)); assert(ci->children[1].values != NULL); - ci->children[1].values->value.string = strdup("^([0-9])test[0-9]test[0-9]$"); + ci->children[1].values->value.string = "^([0-9])test[0-9]test[0-9]$"; ci->children[1].values->type = OCONFIG_TYPE_STRING; - ci->children[2].key = strdup("Group"); + ci->children[2].key = "Group"; ci->children[2].parent = ci; ci->children[2].values_num = 1; ci->children[2].values = calloc(1, sizeof(*ci->children[0].values)); @@ -512,16 +502,9 @@ DEF_TEST(config_index_key) { EXPECT_EQ_STR("^([0-9])test[0-9]test[0-9]$", td->index_keys[0].regex); OK(td->tokens[INDEX_PLUGIN_INSTANCE] != NULL); - sfree(ci->children[0].values->value.string); sfree(ci->children[0].values); - sfree(ci->children[0].key); - - sfree(ci->children[1].values->value.string); sfree(ci->children[1].values); - sfree(ci->children[1].key); - sfree(ci->children[2].values); - sfree(ci->children[2].key); sfree(ci->children); sfree(ci); @@ -536,34 +519,29 @@ DEF_TEST(config_index_key) { } DEF_TEST(parse_index_key) { - char *regex = strdup("test-([0-9])-([0-9])"); - char *input = strdup("snmp-test-5-6"); + const char regex[] = "test-([0-9])-([0-9])"; + const char input[] = "snmp-test-5-6"; regex_t regex_info; regmatch_t match; - assert(regex != NULL); - assert(input != NULL); - int ret = regcomp(®ex_info, regex, REG_EXTENDED); EXPECT_EQ_INT(0, ret); - ret = snmp_agent_parse_index_key(input, regex, ®ex_info, 0, &match); + ret = snmp_agent_parse_index_key(input, ®ex_info, 0, &match); EXPECT_EQ_INT(0, ret); EXPECT_EQ_INT(5, match.rm_so); EXPECT_EQ_INT(13, match.rm_eo); - ret = snmp_agent_parse_index_key(input, regex, ®ex_info, 1, &match); + ret = snmp_agent_parse_index_key(input, ®ex_info, 1, &match); EXPECT_EQ_INT(0, ret); EXPECT_EQ_INT(10, match.rm_so); EXPECT_EQ_INT(11, match.rm_eo); - ret = snmp_agent_parse_index_key(input, regex, ®ex_info, 2, &match); + ret = snmp_agent_parse_index_key(input, ®ex_info, 2, &match); EXPECT_EQ_INT(0, ret); EXPECT_EQ_INT(12, match.rm_so); EXPECT_EQ_INT(13, match.rm_eo); - sfree(regex); - sfree(input); regfree(®ex_info); return 0; @@ -572,10 +550,9 @@ DEF_TEST(parse_index_key) { DEF_TEST(create_token) { c_avl_tree_t *tokens = c_avl_create((int (*)(const void *, const void *))num_compare); - char *input = strdup("testA1-testB2"); + const char input[] = "testA1-testB2"; assert(tokens != NULL); - assert(input != NULL); int ret = snmp_agent_create_token(input, 0, 5, tokens, NULL); EXPECT_EQ_INT(0, ret); @@ -606,7 +583,6 @@ DEF_TEST(create_token) { OK(ret != 0); c_avl_destroy(tokens); - sfree(input); return 0; } @@ -614,10 +590,9 @@ DEF_TEST(create_token) { DEF_TEST(delete_token) { c_avl_tree_t *tokens = c_avl_create((int (*)(const void *, const void *))num_compare); - char *input = strdup("testA1-testB2-testC3"); + const char input[] = "testA1-testB2-testC3"; assert(tokens != NULL); - assert(input != NULL); int ret = snmp_agent_create_token(input, 0, 5, tokens, NULL); EXPECT_EQ_INT(0, ret); @@ -652,7 +627,6 @@ DEF_TEST(delete_token) { OK(ret != 0); c_avl_destroy(tokens); - sfree(input); return 0; } @@ -660,10 +634,9 @@ DEF_TEST(delete_token) { DEF_TEST(get_token) { c_avl_tree_t *tokens = c_avl_create((int (*)(const void *, const void *))num_compare); - char *input = strdup("testA1-testB2-testC3"); + const char input[] = "testA1-testB2-testC3"; assert(tokens != NULL); - assert(input != NULL); int ret = snmp_agent_create_token(input, 0, 5, tokens, NULL); EXPECT_EQ_INT(0, ret); @@ -685,7 +658,6 @@ DEF_TEST(get_token) { } c_avl_destroy(tokens); - sfree(input); return 0; } @@ -696,14 +668,13 @@ DEF_TEST(tokenize) { {19, 20}}; /* "3" */ c_avl_tree_t *tokens = c_avl_create((int (*)(const void *, const void *))num_compare); - char *input = strdup("testA1-testB2-testC3"); + const char input[] = "testA1-testB2-testC3"; token_t *token; int *offset; c_avl_iterator_t *it; int ret; assert(tokens != NULL); - assert(input != NULL); /* First pass */ ret = snmp_agent_tokenize(input, tokens, &m[0], NULL); @@ -760,7 +731,6 @@ DEF_TEST(tokenize) { } c_avl_destroy(tokens); - sfree(input); return 0; } @@ -785,8 +755,9 @@ DEF_TEST(build_name) { for (int i = 0; i < 3; i++) { token = malloc(sizeof(*token)); token->str = t[i]; - token->key = snmp_varlist_add_variable(&td->index_list_cont, NULL, 0, - ASN_INTEGER, &n[i], sizeof(n[i])); + token->key = + snmp_varlist_add_variable(&td->index_list_cont, NULL, 0, ASN_INTEGER, + (const u_char *)&n[i], sizeof(n[i])); assert(token->key != NULL); offset = &off[i]; ret = c_avl_insert(tokens, (void *)offset, (void *)token);