diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index fe6a17b6dad..8a05f7c9c82 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -3402,21 +3402,21 @@ ofpact_put_set_field(struct ofpbuf *ofpacts, const struct mf_field *field, struct ofpact_set_field *sf = ofpact_put_SET_FIELD(ofpacts); sf->field = field; - /* Fill in the value and mask if given, otherwise put zeroes so that the - * caller may fill in the value and mask itself. */ + /* Fill with all zeroes to make sure the padding is initialized. */ + ofpbuf_put_zeros(ofpacts, total_size); + sf = ofpacts->header; + + /* Fill in the value and mask if given, otherwise keep the zeroes + * so that the caller may fill in the value and mask itself. */ if (value) { - ofpbuf_put_uninit(ofpacts, total_size); - sf = ofpacts->header; memcpy(sf->value, value, field->n_bytes); if (mask) { memcpy(ofpact_set_field_mask(sf), mask, field->n_bytes); } else { memset(ofpact_set_field_mask(sf), 0xff, field->n_bytes); } - } else { - ofpbuf_put_zeros(ofpacts, total_size); - sf = ofpacts->header; } + /* Update length. */ ofpact_finish_SET_FIELD(ofpacts, &sf);