diff options
| author | Ben Pfaff <blp@nicira.com> | 2010-10-06 14:21:47 -0700 |
|---|---|---|
| committer | Ben Pfaff <blp@nicira.com> | 2010-10-06 14:21:47 -0700 |
| commit | 3dffcf0701f7e7753710348d34eb5be007525877 (patch) | |
| tree | 40c4dbdbf08f9290836935dbe01c4333b4fce509 /lib/ofp-util.c | |
| parent | b8dcf5e9c554e2c5fc35a68a086d304fc0cea59a (diff) | |
| download | openvswitch-3dffcf0701f7e7753710348d34eb5be007525877.tar.gz | |
ofproto: Avoid wasting memory malloc()'ing empty action sets for subrules.
GNU libc treats malloc(0) as malloc(1). Subrules always have an n_actions
of 0, so this code was wasting time and memory for subrules. This commit
stops doing that.
Also audits and fixes some very pedantic potential problems with null
pointers; e.g. the C standard says that NULL may not be compared with the
< operator, even if both arguments are null, and it also says that a null
pointer may not be passed to memcpy() or memcmp(), even if the length is
zero.
Diffstat (limited to 'lib/ofp-util.c')
| -rw-r--r-- | lib/ofp-util.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 7a2e17cb2..6d0458673 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -619,9 +619,10 @@ int validate_actions(const union ofp_action *actions, size_t n_actions, int max_ports) { - const union ofp_action *a; + size_t i; - for (a = actions; a < &actions[n_actions]; ) { + for (i = 0; i < n_actions; ) { + const union ofp_action *a = &actions[i]; unsigned int len = ntohs(a->header.len); unsigned int n_slots = len / ACTION_ALIGNMENT; unsigned int slots_left = &actions[n_actions] - a; @@ -645,7 +646,7 @@ validate_actions(const union ofp_action *actions, size_t n_actions, if (error) { return error; } - a += n_slots; + i += n_slots; } return 0; } @@ -679,7 +680,7 @@ actions_first(struct actions_iterator *iter, const union ofp_action * actions_next(struct actions_iterator *iter) { - if (iter->pos < iter->end) { + if (iter->pos != iter->end) { const union ofp_action *a = iter->pos; unsigned int len = ntohs(a->header.len); iter->pos += len / ACTION_ALIGNMENT; |
