From: Vincent Bernat Date: Fri, 4 May 2012 06:11:36 +0000 (+0200) Subject: Don't mix declarations and statements. X-Git-Tag: 0.6.0~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5fd6695c090ddecb77e8324b6d6fb8b8fe43860a;p=thirdparty%2Flldpd.git Don't mix declarations and statements. Also enable warnings when we try to. Compatibility with gcc 2.96 requires that. --- diff --git a/configure.ac b/configure.ac index 7737fb8e..db7840fe 100644 --- a/configure.ac +++ b/configure.ac @@ -50,6 +50,7 @@ AX_CFLAGS_GCC_OPTION([-Wcast-align]) AX_CFLAGS_GCC_OPTION([-Winline]) AX_CFLAGS_GCC_OPTION([-fstack-protector]) AX_CFLAGS_GCC_OPTION([-D_FORTIFY_SOURCE=2]) +AX_CFLAGS_GCC_OPTION([-Wdeclaration-after-statement]) AX_CFLAGS_GCC_OPTION([-Wno-unused-parameter]) AX_CFLAGS_GCC_OPTION([-Wno-sign-compare]) dnl Should be fixed later AX_LDFLAGS_OPTION([-Wl,-z,relro]) diff --git a/src/agent.c b/src/agent.c index 0f37ca7f..c76af5a3 100644 --- a/src/agent.c +++ b/src/agent.c @@ -162,14 +162,15 @@ header_pmedindexed_policy_table(struct variable *vp, oid *name, size_t *length, { struct lldpd_hardware *hardware; int i; + oid index[2]; if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { for (i = 0; i < LLDPMED_APPTYPE_LAST; i++) { if (hardware->h_lport.p_med_policy[i].type != i+1) continue; - oid index[2] = { hardware->h_ifindex, - i + 1 }; + index[0] = hardware->h_ifindex; + index[1] = i + 1; if (header_index_add(index, 2, &hardware->h_lport.p_med_policy[i])) return &hardware->h_lport.p_med_policy[i]; @@ -184,14 +185,15 @@ header_pmedindexed_location_table(struct variable *vp, oid *name, size_t *length { struct lldpd_hardware *hardware; int i; + oid index[2]; if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { for (i = 0; i < LLDPMED_LOCFORMAT_LAST; i++) { if (hardware->h_lport.p_med_location[i].format != i+1) continue; - oid index[2] = { hardware->h_ifindex, - i + 2 }; + index[0] = hardware->h_ifindex; + index[1] = i + 2; if (header_index_add(index, 2, &hardware->h_lport.p_med_location[i])) return &hardware->h_lport.p_med_location[i]; @@ -208,15 +210,16 @@ header_tprindexed_table(struct variable *vp, oid *name, size_t *length, { struct lldpd_hardware *hardware; struct lldpd_port *port; + oid index[3]; if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; if (withmed && !port->p_chassis->c_med_cap_available) continue; - oid index[3] = { lastchange(port), - hardware->h_ifindex, - port->p_chassis->c_index }; + index[0] = lastchange(port); + index[1] = hardware->h_ifindex; + index[2] = port->p_chassis->c_index; if (header_index_add(index, 3, port)) return port; @@ -298,6 +301,7 @@ header_tprmedindexed_table(struct variable *vp, oid *name, size_t *length, struct lldpd_hardware *hardware; struct lldpd_port *port; int j; + oid index[4]; if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { @@ -311,10 +315,10 @@ header_tprmedindexed_table(struct variable *vp, oid *name, size_t *length, j++) { if (port->p_med_policy[j].type != j+1) continue; - oid index[4] = { lastchange(port), - hardware->h_ifindex, - port->p_chassis->c_index, - j+1 }; + index[0] = lastchange(port); + index[1] = hardware->h_ifindex; + index[2] = port->p_chassis->c_index; + index[3] = j+1; if (header_index_add(index, 4, &port->p_med_policy[j])) return &port->p_med_policy[j]; @@ -326,10 +330,10 @@ header_tprmedindexed_table(struct variable *vp, oid *name, size_t *length, j++) { if (port->p_med_location[j].format != j+1) continue; - oid index[4] = { lastchange(port), - hardware->h_ifindex, - port->p_chassis->c_index, - j+2 }; + index[0] = lastchange(port); + index[1] = hardware->h_ifindex; + index[2] = port->p_chassis->c_index; + index[3] = j+2; if (header_index_add(index, 4, &port->p_med_location[j])) return &port->p_med_location[j]; @@ -736,6 +740,10 @@ static u_char* agent_h_local_med_power(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { + struct lldpd_med_power *power = NULL; + struct lldpd_hardware *hardware; + int pse = 0; + if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) return NULL; if (header_generic(vp, name, length, exact, var_len, write_method)) @@ -746,9 +754,6 @@ agent_h_local_med_power(struct variable *vp, oid *name, size_t *length, least, all PD values are global and not per-port. We try to do our best. For device type, we decide on the number of PD/PSE ports. */ - struct lldpd_med_power *power = NULL; - struct lldpd_hardware *hardware; - int pse = 0; TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { if (hardware->h_lport.p_med_power.devicetype == LLDPMED_POW_TYPE_PSE) { @@ -774,12 +779,12 @@ agent_h_remote_med_power(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct lldpd_port *port; + u_char *a; if ((port = header_tprindexed_table(vp, name, length, exact, var_len, write_method, 1)) == NULL) return NULL; - u_char *a; if ((a = agent_v_med_power(vp, var_len, &port->p_med_power)) != NULL) return a; TRYNEXT(agent_h_remote_med_power); @@ -839,12 +844,13 @@ static u_char* agent_h_local_med(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { + u_char *a; + if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) return NULL; if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL; - u_char *a; if ((a = agent_v_med(vp, var_len, LOCAL_CHASSIS(scfg), NULL)) != NULL) return a; @@ -856,12 +862,12 @@ agent_h_remote_med(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct lldpd_port *port; + u_char *a; if ((port = header_tprindexed_table(vp, name, length, exact, var_len, write_method, 1)) == NULL) return NULL; - u_char *a; if ((a = agent_v_med(vp, var_len, port->p_chassis, port)) != NULL) return a; @@ -1664,9 +1670,9 @@ size_t agent_lldp_vars_size(void) { static int agent_log_callback(int major, int minor, void *serverarg, void *clientarg) { - (void)major; (void)minor; (void)clientarg; struct snmp_log_message *slm = (struct snmp_log_message *)serverarg; char *msg = strdup(slm->msg); + (void)major; (void)minor; (void)clientarg; if (msg) msg[strlen(msg)-1] = '\0'; switch (slm->priority) { case LOG_EMERG: log_warnx("snmp[emerg]: %s", msg?msg:slm->msg); break; diff --git a/src/cdp.c b/src/cdp.c index fd6df4aa..8d168c39 100644 --- a/src/cdp.c +++ b/src/cdp.c @@ -30,6 +30,7 @@ static int cdp_send(struct lldpd *global, struct lldpd_hardware *hardware, int version) { + const char *platform = "Linux"; struct lldpd_chassis *chassis; struct lldpd_mgmt *mgmt; u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR; @@ -187,7 +188,6 @@ cdp_send(struct lldpd *global, goto toobig; /* Platform */ - char *platform = "Linux"; if (global && global->g_platform_override) platform = global->g_platform_override; if (!( POKE_START_CDP_TLV(CDP_TLV_PLATFORM) && diff --git a/src/client.c b/src/client.c index d32b4490..eab132e3 100644 --- a/src/client.c +++ b/src/client.c @@ -35,6 +35,7 @@ client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, { struct lldpd_interface *iff, *iff_next; struct lldpd_hardware *hardware; + int output_len; /* Build the list of interfaces */ struct lldpd_interface_list ifs; @@ -47,7 +48,7 @@ client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, TAILQ_INSERT_TAIL(&ifs, iff, next); } - int output_len = marshal_serialize(lldpd_interface_list, &ifs, output); + output_len = marshal_serialize(lldpd_interface_list, &ifs, output); if (output_len <= 0) { output_len = 0; *type = NONE; @@ -73,15 +74,16 @@ static int client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output) { - /* Get name of the interface */ char *name; + struct lldpd_hardware *hardware; + + /* Get name of the interface */ if (marshal_unserialize(string, input, input_len, &name) <= 0) { *type = NONE; return 0; } /* Search appropriate hardware */ - struct lldpd_hardware *hardware; TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) if (!strcmp(hardware->h_ifname, name)) { int output_len = marshal_serialize(lldpd_hardware, hardware, output); @@ -109,7 +111,9 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, void **output) { int ret = 0; - struct lldpd_port_set *set; + struct lldpd_port_set *set = NULL; + struct lldpd_hardware *hardware = NULL; + struct lldpd_med_loc *loc = NULL; if (marshal_unserialize(lldpd_port_set, input, input_len, &set) <= 0) { *type = NONE; @@ -121,7 +125,6 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, } /* Search the appropriate hardware */ - struct lldpd_hardware *hardware; TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) if (!strcmp(hardware->h_ifname, set->ifname)) { struct lldpd_port *port = &hardware->h_lport; @@ -142,7 +145,7 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, set->med_location->format); goto set_port_finished; } - struct lldpd_med_loc *loc = \ + loc = \ &port->p_med_location[set->med_location->format - 1]; free(loc->data); memcpy(loc, set->med_location, sizeof(struct lldpd_med_loc)); diff --git a/src/ctl.c b/src/ctl.c index 050b7c01..f7f0ddae 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -90,9 +90,9 @@ int ctl_msg_recv(int fd, enum hmsg_type *type, void **t) { int n, flags = -1; + struct hmsg_header hdr; *type = NONE; *t = NULL; /* First, we read the header to know the size of the message */ - struct hmsg_header hdr; if ((n = read(fd, &hdr, sizeof(struct hmsg_header))) == -1) { LLOG_WARN("unable to read message header"); return -1; diff --git a/src/display.c b/src/display.c index 14b34f71..b2cbd8ad 100644 --- a/src/display.c +++ b/src/display.c @@ -938,6 +938,13 @@ display_interfaces(int s, const char * fmt, int hidden, int argc, char *argv[]) { int i; struct writer * w; + char sep[80]; + struct lldpd_interface *iff; + struct lldpd_interface_list *ifs; + struct lldpd_port *port; + struct lldpd_chassis *chassis; + struct lldpd_hardware *hardware; + if ( strcmp(fmt,"plain") == 0 ) { w = txt_init( stdout ); } else if (strcmp(fmt, "keyvalue") == 0) { @@ -952,12 +959,10 @@ display_interfaces(int s, const char * fmt, int hidden, int argc, char *argv[]) w = txt_init( stdout ); } - char sep[80]; memset(sep, '-', 79); sep[79] = 0; - struct lldpd_interface *iff; - struct lldpd_interface_list *ifs = get_interfaces(s); + ifs = get_interfaces(s); tag_start(w, "lldp", "LLDP neighbors"); TAILQ_FOREACH(iff, ifs, next) { @@ -969,9 +974,7 @@ display_interfaces(int s, const char * fmt, int hidden, int argc, char *argv[]) continue; } - struct lldpd_port *port; - struct lldpd_chassis *chassis; - struct lldpd_hardware *hardware = get_interface(s, iff->name); + hardware = get_interface(s, iff->name); if (TAILQ_EMPTY(&hardware->h_rports)) continue; TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { diff --git a/src/event.c b/src/event.c index 3666e340..376b1e2a 100644 --- a/src/event.c +++ b/src/event.c @@ -57,9 +57,9 @@ static void levent_snmp_update(struct lldpd *); static void levent_snmp_read(evutil_socket_t fd, short what, void *arg) { - (void)what; struct lldpd *cfg = arg; fd_set fdset; + (void)what; FD_ZERO(&fdset); FD_SET(fd, &fdset); snmp_read(&fdset); @@ -74,8 +74,8 @@ levent_snmp_read(evutil_socket_t fd, short what, void *arg) static void levent_snmp_timeout(evutil_socket_t fd, short what, void *arg) { - (void)what; (void)fd; struct lldpd *cfg = arg; + (void)what; (void)fd; snmp_timeout(); run_alarms(); levent_snmp_update(cfg); @@ -135,6 +135,8 @@ levent_snmp_update(struct lldpd *cfg) fd_set fdset; struct timeval timeout; static int howmany = 0; + int added = 0, removed = 0, current = 0; + struct lldpd_events *snmpfd, *snmpfd_next; /* snmp_select_info() can be tricky to understand. We set `block` to 1 to means that we don't request a timeout. snmp_select_info() @@ -150,8 +152,6 @@ levent_snmp_update(struct lldpd *cfg) /* We need to untrack any event whose FD is not in `fdset` anymore */ - int added = 0, removed = 0, current = 0; - struct lldpd_events *snmpfd, *snmpfd_next; for (snmpfd = TAILQ_FIRST(levent_snmp_fds(cfg)); snmpfd; snmpfd = snmpfd_next) { @@ -196,11 +196,11 @@ struct lldpd_one_client { static void levent_ctl_recv(evutil_socket_t fd, short what, void *arg) { - (void)what; struct lldpd_one_client *client = arg; enum hmsg_type type; void *buffer = NULL; int n; + (void)what; if ((n = ctl_msg_recv(fd, &type, &buffer)) == -1 || client_handle_client(client->cfg, fd, type, buffer, n) == -1) { @@ -214,10 +214,11 @@ levent_ctl_recv(evutil_socket_t fd, short what, void *arg) static void levent_ctl_accept(evutil_socket_t fd, short what, void *arg) { - (void)what; struct lldpd *cfg = arg; struct lldpd_one_client *client = NULL; int s; + (void)what; + if ((s = accept(fd, NULL, NULL)) == -1) { LLOG_WARN("unable to accept connection from socket"); return; @@ -250,24 +251,24 @@ accept_failed: static void levent_dump(evutil_socket_t fd, short what, void *arg) { - (void)fd; (void)what; struct event_base *base = arg; + (void)fd; (void)what; event_base_dump_events(base, stderr); } static void levent_stop(evutil_socket_t fd, short what, void *arg) { - (void)fd; (void)what; struct event_base *base = arg; + (void)fd; (void)what; event_base_loopbreak(base); } static void levent_update_and_send(evutil_socket_t fd, short what, void *arg) { - (void)fd; (void)what; struct lldpd *cfg = arg; struct timeval tv = {cfg->g_delay, 0}; + (void)fd; (void)what; lldpd_loop(cfg); event_add(cfg->g_main_loop, &tv); } @@ -362,9 +363,9 @@ levent_loop(struct lldpd *cfg) static void levent_hardware_recv(evutil_socket_t fd, short what, void *arg) { - (void)what; struct lldpd_hardware *hardware = arg; struct lldpd *cfg = hardware->h_cfg; + (void)what; lldpd_recv(cfg, hardware, fd); } @@ -383,9 +384,10 @@ levent_hardware_init(struct lldpd_hardware *hardware) void levent_hardware_add_fd(struct lldpd_hardware *hardware, int fd) { + struct lldpd_events *hfd = NULL; if (!hardware->h_recv) return; - struct lldpd_events *hfd = calloc(1, sizeof(struct lldpd_events)); + hfd = calloc(1, sizeof(struct lldpd_events)); if (!hfd) { LLOG_WARNX("unable to allocate new event for %s", hardware->h_ifname); @@ -414,9 +416,9 @@ levent_hardware_add_fd(struct lldpd_hardware *hardware, int fd) void levent_hardware_release(struct lldpd_hardware *hardware) { + struct lldpd_events *ev, *ev_next; if (!hardware->h_recv) return; - struct lldpd_events *ev, *ev_next; for (ev = TAILQ_FIRST(levent_hardware_fds(hardware)); ev; ev = ev_next) { diff --git a/src/interfaces.c b/src/interfaces.c index df54f17e..a99125dd 100644 --- a/src/interfaces.c +++ b/src/interfaces.c @@ -1130,6 +1130,7 @@ lldpd_ifh_chassis(struct lldpd *cfg, struct ifaddrs *ifap) { struct ifaddrs *ifa; struct lldpd_hardware *hardware; + char *name = NULL; if (LOCAL_CHASSIS(cfg)->c_id != NULL && LOCAL_CHASSIS(cfg)->c_id_subtype == LLDP_CHASSISID_SUBTYPE_LLADDR) @@ -1147,7 +1148,7 @@ lldpd_ifh_chassis(struct lldpd *cfg, struct ifaddrs *ifap) /* That's odd. Let's skip. */ continue; - char *name = malloc(sizeof(hardware->h_lladdr)); + name = malloc(sizeof(hardware->h_lladdr)); if (!name) { LLOG_WARN("Not enough memory for chassis ID"); return; diff --git a/src/lldpctl.c b/src/lldpctl.c index 045e8bfc..d4ff8d88 100644 --- a/src/lldpctl.c +++ b/src/lldpctl.c @@ -594,6 +594,10 @@ set_port(int s, int argc, char *argv[], int action) int done; int skip[4] = {0, 0, 0, 0}; int skip_[4]; + struct lldpd_interface *iff; + struct lldpd_interface_list *ifs; + struct lldpd_port_set set; + int i; redo_set_port: memcpy(skip_, skip, sizeof(skip)); @@ -645,9 +649,7 @@ set_port(int s, int argc, char *argv[], int action) } if (done) return; - struct lldpd_interface *iff; - struct lldpd_interface_list *ifs = get_interfaces(s); - int i; + ifs = get_interfaces(s); TAILQ_FOREACH(iff, ifs, next) { if (optind < argc) { for (i = optind; i < argc; i++) @@ -657,7 +659,6 @@ set_port(int s, int argc, char *argv[], int action) continue; } - struct lldpd_port_set set; memset(&set, 0, sizeof(struct lldpd_port_set)); set.ifname = iff->name; #ifdef ENABLE_LLDPMED diff --git a/src/lldpd.c b/src/lldpd.c index 685c50a6..52e04574 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -360,6 +360,8 @@ lldpd_cleanup(struct lldpd *cfg) static void lldpd_move_chassis(struct lldpd_chassis *ochassis, struct lldpd_chassis *chassis) { + struct lldpd_mgmt *mgmt, *mgmt_next; + /* We want to keep refcount, index and list stuff from the current * chassis */ TAILQ_ENTRY(lldpd_chassis) entries; @@ -376,7 +378,6 @@ lldpd_move_chassis(struct lldpd_chassis *ochassis, TAILQ_INIT(&ochassis->c_mgmt); /* Copy of management addresses */ - struct lldpd_mgmt *mgmt, *mgmt_next; for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); mgmt != NULL; mgmt = mgmt_next) { diff --git a/src/marshal.c b/src/marshal.c index 8463ce59..ba03950d 100644 --- a/src/marshal.c +++ b/src/marshal.c @@ -51,9 +51,15 @@ TAILQ_HEAD(ref_l, ref); size_t marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, int skip, void *_refs, int osize) -{ - /* Check if we have already serialized this one. */ +{ struct ref_l *refs = _refs; + struct ref *cref; + int size; + size_t len; + struct marshal_subinfo *current; + struct marshal_serialized *new = NULL, *serialized = NULL; + + /* Check if we have already serialized this one. */ if (!refs) { refs = calloc(1, sizeof(struct ref_l)); if (!refs) { @@ -62,22 +68,21 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, } TAILQ_INIT(refs); } - struct ref *cref; TAILQ_FOREACH(cref, refs, next) { if (unserialized == cref->pointer) return 0; } /* Handle special cases. */ - int size = mi->size; + size = mi->size; if (!strcmp(mi->name, "null string")) size = strlen((char *)unserialized) + 1; else if (!strcmp(mi->name, "fixed string")) size = osize; /* Allocate serialized structure */ - size_t len = sizeof(struct marshal_serialized) + (skip?0:size); - struct marshal_serialized *serialized = calloc(1, len); + len = sizeof(struct marshal_serialized) + (skip?0:size); + serialized = calloc(1, len); if (!serialized) { LLOG_WARNX("unable to allocate memory to serialize structure %s", mi->name); @@ -101,7 +106,6 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, memcpy(serialized->object, unserialized, size); /* Then, serialize inner structures */ - struct marshal_subinfo *current; for (current = mi->pointers; current->mi; current++) { size_t sublen; void *source; @@ -127,7 +131,7 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, } if (sublen == 0) continue; /* This was already serialized */ /* Append the result */ - struct marshal_serialized *new = realloc(serialized, len + sublen); + new = realloc(serialized, len + sublen); if (!new) { LLOG_WARNX("unable to allocate more memory to serialize structure %s", mi->name); @@ -170,9 +174,10 @@ TAILQ_HEAD(gc_l, gc); static void* marshal_alloc(struct gc_l *pointers, size_t len, void *orig) { + struct gc *gpointer = NULL; + void *result = malloc(len); if (!result) return NULL; - struct gc *gpointer = NULL; if ((gpointer = (struct gc *)calloc(1, sizeof(struct gc))) == NULL) { free(result); @@ -206,6 +211,12 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o { int total_len = sizeof(struct marshal_serialized) + (skip?0:mi->size); struct marshal_serialized *serialized = buffer; + struct gc_l *pointers = _pointers; + int size, already; + void *new; + struct marshal_subinfo *current; + struct gc *apointer; + if (len < sizeof(struct marshal_serialized) || len < total_len) { LLOG_WARNX("data to deserialize is too small for structure %s", mi->name); @@ -213,7 +224,6 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o } /* Initialize garbage collection */ - struct gc_l *pointers = _pointers; if (!pointers) { pointers = calloc(1, sizeof(struct gc_l)); if (!pointers) { @@ -224,7 +234,7 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o } /* Special cases */ - int size = mi->size; + size = mi->size; if (!strcmp(mi->name, "null string") || !strcmp(mi->name, "fixed string")) { switch (mi->name[0]) { case 'n': size = strnlen((char *)serialized->object, @@ -251,10 +261,9 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o } /* Then, each substructure */ - struct marshal_subinfo *current; for (current = mi->pointers; current->mi; current++) { size_t sublen; - void *new = (unsigned char *)*output + current->offset; + new = (unsigned char *)*output + current->offset; if (current->kind == ignore) { memset((unsigned char *)*output + current->offset, 0, sizeof(void *)); @@ -264,12 +273,11 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o if (*(void **)new == NULL) continue; /* Did we already see this reference? */ - struct gc *pointer; - int already = 0; - TAILQ_FOREACH(pointer, pointers, next) - if (pointer->orig == *(void **)new) { + already = 0; + TAILQ_FOREACH(apointer, pointers, next) + if (apointer->orig == *(void **)new) { memcpy((unsigned char *)*output + current->offset, - &pointer->pointer, sizeof(void *)); + &apointer->pointer, sizeof(void *)); already = 1; break; } diff --git a/tests/check_cdp.c b/tests/check_cdp.c index ab40cc1d..7ad844f0 100644 --- a/tests/check_cdp.c +++ b/tests/check_cdp.c @@ -90,6 +90,8 @@ Cisco Discovery Protocol 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00, 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 }; struct packet *pkt; + in_addr_t addr; + struct lldpd_mgmt *mgmt; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; @@ -103,8 +105,8 @@ Cisco Discovery Protocol chassis.c_descr = "Chassis description"; chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER; TAILQ_INIT(&chassis.c_mgmt); - in_addr_t addr = inet_addr("172.17.142.37"); - struct lldpd_mgmt *mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, + addr = inet_addr("172.17.142.37"); + mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr, sizeof(in_addr_t), 0); if (mgmt == NULL) ck_abort(); @@ -215,6 +217,10 @@ Cisco Discovery Protocol 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00, 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 }; struct packet *pkt; + in_addr_t addr1; + in_addr_t addr2; + struct lldpd_mgmt *mgmt1; + struct lldpd_mgmt *mgmt2; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR; @@ -229,12 +235,12 @@ Cisco Discovery Protocol chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE; TAILQ_INIT(&chassis.c_mgmt); - in_addr_t addr1 = inet_addr("172.17.142.36"); - in_addr_t addr2 = inet_addr("172.17.142.38"); - struct lldpd_mgmt *mgmt1 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, - &addr1, sizeof(in_addr_t), 0); - struct lldpd_mgmt *mgmt2 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, - &addr2, sizeof(in_addr_t), 0); + addr1 = inet_addr("172.17.142.36"); + addr2 = inet_addr("172.17.142.38"); + mgmt1 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, + &addr1, sizeof(in_addr_t), 0); + mgmt2 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, + &addr2, sizeof(in_addr_t), 0); if (mgmt1 == NULL || mgmt2 == NULL) ck_abort(); TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt1, m_entries); @@ -547,12 +553,13 @@ cdp_suite(void) #ifdef ENABLE_CDP TCase *tc_send = tcase_create("Send CDP packets"); + TCase *tc_receive = tcase_create("Receive CDP packets"); + tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown); tcase_add_test(tc_send, test_send_cdpv1); tcase_add_test(tc_send, test_send_cdpv2); suite_add_tcase(s, tc_send); - TCase *tc_receive = tcase_create("Receive CDP packets"); tcase_add_test(tc_receive, test_recv_cdpv1); tcase_add_test(tc_receive, test_recv_cdpv2); suite_add_tcase(s, tc_receive); diff --git a/tests/check_edp.c b/tests/check_edp.c index 8fc65333..3a6b627f 100644 --- a/tests/check_edp.c +++ b/tests/check_edp.c @@ -574,6 +574,8 @@ edp_suite(void) #ifdef ENABLE_EDP TCase *tc_send = tcase_create("Send EDP packets"); + TCase *tc_receive = tcase_create("Receive EDP packets"); + tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown); tcase_add_test(tc_send, test_send_basic); #ifdef ENABLE_DOT1 @@ -581,7 +583,6 @@ edp_suite(void) #endif suite_add_tcase(s, tc_send); - TCase *tc_receive = tcase_create("Receive EDP packets"); tcase_add_test(tc_receive, test_recv_edp); suite_add_tcase(s, tc_receive); #endif diff --git a/tests/check_lldp.c b/tests/check_lldp.c index 45c1597d..87e6ba44 100644 --- a/tests/check_lldp.c +++ b/tests/check_lldp.c @@ -740,6 +740,8 @@ Suite * lldp_suite(void) { Suite *s = suite_create("LLDP"); + TCase *tc_send = tcase_create("Send LLDP packets"); + TCase *tc_receive = tcase_create("Receive LLDP packets"); /* Send tests are first run without knowing the result. The result is then checked with: @@ -750,7 +752,6 @@ lldp_suite(void) be able to do this). */ - TCase *tc_send = tcase_create("Send LLDP packets"); tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown); tcase_add_test(tc_send, test_send_rcv_basic); #ifdef ENABLE_DOT1 @@ -764,7 +765,6 @@ lldp_suite(void) #endif suite_add_tcase(s, tc_send); - TCase *tc_receive = tcase_create("Receive LLDP packets"); tcase_add_test(tc_receive, test_recv_min); tcase_add_test(tc_receive, test_recv_lldpd); suite_add_tcase(s, tc_receive); diff --git a/tests/check_marshal.c b/tests/check_marshal.c index a2bf6dc1..61afb51e 100644 --- a/tests/check_marshal.c +++ b/tests/check_marshal.c @@ -391,13 +391,13 @@ START_TEST(test_too_small_unmarshal) { struct struct_nestedpointers *destination; void *buffer; size_t len, len2; + int i, j; len = marshal_serialize(struct_nestedpointers, &source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source_simple1, 0, sizeof(struct struct_simple)); memset(&source_onepointer, 0, sizeof(struct struct_onepointer)); memset(&source, 0, sizeof(struct struct_nestedpointers)); - int i, j; /* Loop 30 times to ease debugging leaks with valgrind */ for (j = 0; j < 30; j++) { for (i = 0; i < len; i++) { @@ -452,15 +452,18 @@ START_TEST(test_simple_list) { .g1 = -47, .g2 = &source_simple, }; + struct list_simple *destination; + void *buffer; + size_t len, len2; + struct struct_simpleentry *e1, *e2; + struct struct_simple *s; + TAILQ_INIT(&source); TAILQ_INSERT_TAIL(&source, &entry1, s_entries); TAILQ_INSERT_TAIL(&source, &entry2, s_entries); TAILQ_INSERT_TAIL(&source, &entry3, s_entries); TAILQ_INSERT_TAIL(&source, &entry4, s_entries); - struct list_simple *destination; - void *buffer; - size_t len, len2; len = marshal_serialize(list_simple, &source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct list_simple)); @@ -472,8 +475,6 @@ START_TEST(test_simple_list) { fail_unless(len2 > 0, "Unable to deserialize"); free(buffer); - struct struct_simpleentry *e1, *e2; - struct struct_simple *s; e1 = TAILQ_FIRST(destination); ck_assert_int_eq(e1->g1, 47); s = e1->g2; @@ -534,15 +535,18 @@ START_TEST(test_embedded_list) { .g1 = -47, .g2 = &source_simple, }; + struct struct_withlist *destination; + void *buffer; + size_t len, len2; + struct struct_simpleentry *e1, *e2; + struct struct_simple *s; + TAILQ_INIT(&source.i2); TAILQ_INSERT_TAIL(&source.i2, &entry1, s_entries); TAILQ_INSERT_TAIL(&source.i2, &entry2, s_entries); TAILQ_INSERT_TAIL(&source.i2, &entry3, s_entries); TAILQ_INSERT_TAIL(&source.i2, &entry4, s_entries); - struct struct_withlist *destination; - void *buffer; - size_t len, len2; len = marshal_serialize(struct_withlist, &source, &buffer); fail_unless(len > 0, "Unable to serialize"); memset(&source, 0, sizeof(struct list_simple)); @@ -556,8 +560,6 @@ START_TEST(test_embedded_list) { ck_assert_int_eq(destination->i1, 45424); ck_assert_int_eq(destination->i3, 4542); - struct struct_simpleentry *e1, *e2; - struct struct_simple *s; e1 = TAILQ_FIRST(&destination->i2); ck_assert_int_eq(e1->g1, 47); ck_assert_int_eq(e1->g2->a4, 74); diff --git a/tests/check_snmp.c b/tests/check_snmp.c index c986f29a..8d26d10e 100644 --- a/tests/check_snmp.c +++ b/tests/check_snmp.c @@ -318,10 +318,11 @@ snmp_oidrepr(oid *name, size_t namelen) { static char *buffer[4] = {NULL, NULL, NULL, NULL}; static int current = 0; + int i; + current = (current + 1)%4; if (buffer[current]) free(buffer[current]); buffer[current] = NULL; - int i; for (i = 0; i < namelen; i++) { /* Not very efficient... */ char *newbuffer = NULL; diff --git a/tests/check_sonmp.c b/tests/check_sonmp.c index b6175e2c..72ae3131 100644 --- a/tests/check_sonmp.c +++ b/tests/check_sonmp.c @@ -72,6 +72,8 @@ Nortel Networks / SynOptics Network Management Protocol 0x8e, 0x25, 0x00, 0x00, 0x04, 0x01, 0x0c, 0x03, 0x01 }; struct packet *pkt; + in_addr_t addr; + struct lldpd_mgmt *mgmt; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; @@ -81,9 +83,9 @@ Nortel Networks / SynOptics Network Management Protocol chassis.c_id = macaddress; chassis.c_id_len = ETH_ALEN; TAILQ_INIT(&chassis.c_mgmt); - in_addr_t addr = inet_addr("172.17.142.37"); - struct lldpd_mgmt *mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, - &addr, sizeof(in_addr_t), 0); + addr = inet_addr("172.17.142.37"); + mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, + &addr, sizeof(in_addr_t), 0); if (mgmt == NULL) ck_abort(); TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt, m_entries); @@ -189,11 +191,12 @@ sonmp_suite(void) #ifdef ENABLE_SONMP TCase *tc_send = tcase_create("Send SONMP packets"); + TCase *tc_receive = tcase_create("Receive SONMP packets"); + tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown); tcase_add_test(tc_send, test_send_sonmp); suite_add_tcase(s, tc_send); - TCase *tc_receive = tcase_create("Receive SONMP packets"); tcase_add_test(tc_receive, test_recv_sonmp); suite_add_tcase(s, tc_receive); #endif