From: Madhu Challa <cha...@noironetworks.com> Remove hard coded array index and make it dependent on the array size.
Signed-off-by: Madhu Challa <cha...@noironetworks.com> Co-authored-by: Ben Pfaff <b...@nicira.com> Signed-off-by: Ben Pfaff <b...@nicira.com> --- lib/learn.c | 6 ++++-- lib/meta-flow.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/learn.c b/lib/learn.c index e93015c..50ffd6f 100644 --- a/lib/learn.c +++ b/lib/learn.c @@ -147,7 +147,8 @@ learn_execute(const struct ofpact_learn *learn, const struct flow *flow, case NX_LEARN_DST_OUTPUT: if (spec->n_bits <= 16 || is_all_zeros(value.u8, sizeof value - 2)) { - ofp_port_t port = u16_to_ofp(ntohs(value.be16[7])); + ovs_be16 *last_be16 = &value.be16[ARRAY_SIZE(value.be16) - 1]; + ofp_port_t port = u16_to_ofp(ntohs(*last_be16)); if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX) || port == OFPP_IN_PORT @@ -209,7 +210,8 @@ learn_parse_load_immediate(const char *s, struct ofpact_learn_spec *spec) } s = arrow; } else { - imm.be64[1] = htonll(strtoull(s, (char **) &s, 0)); + ovs_be64 *last_be64 = &imm.be64[ARRAY_SIZE(imm.be64) - 1]; + *last_be64 = htonll(strtoull(s, (char **) &s, 0)); } if (strncmp(s, "->", 2)) { diff --git a/lib/meta-flow.h b/lib/meta-flow.h index 1659522..1646995 100644 --- a/lib/meta-flow.h +++ b/lib/meta-flow.h @@ -1503,7 +1503,9 @@ union mf_value { }; BUILD_ASSERT_DECL(sizeof(union mf_value) == 16); +/* An all-1-bits mf_value. Needs to be updated if struct mf_value grows.*/ #define MF_EXACT_MASK_INITIALIZER { IN6ADDR_EXACT_INIT } +BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof(struct in6_addr)); /* Part of a field. */ struct mf_subfield { -- 2.1.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev