X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fvlan-bitmap.c;h=4c5c1eb68870d0405505aa23d5f2caf959519dca;hb=1bf2c909685893c75f61c63a41928c9ec11c06f1;hp=94059c75d26200d64aec9c9bfc91542745d29b35;hpb=007948177581f3b3dad188221593d0e4bdca6ba0;p=openvswitch diff --git a/lib/vlan-bitmap.c b/lib/vlan-bitmap.c index 94059c75..4c5c1eb6 100644 --- a/lib/vlan-bitmap.c +++ b/lib/vlan-bitmap.c @@ -24,29 +24,39 @@ unsigned long * vlan_bitmap_from_array(const int64_t *vlans, size_t n_vlans) { unsigned long *b; - size_t i, n; if (!n_vlans) { return NULL; } b = bitmap_allocate(4096); + if (!vlan_bitmap_from_array__(vlans, n_vlans, b)) { + free(b); + return NULL; + } + return b; +} + +/* Adds to 4096-bit VLAN bitmap 'b' a 1-bit in each position in the 'n_vlans' + * bits indicated in 'vlans'. Returns the number of 1-bits added to 'b'. */ +int +vlan_bitmap_from_array__(const int64_t *vlans, size_t n_vlans, + unsigned long int *b) +{ + size_t i; + int n; + n = 0; for (i = 0; i < n_vlans; i++) { int64_t vlan = vlans[i]; - if (vlan >= 0 && vlan < 4096) { + if (vlan >= 0 && vlan < 4096 && !bitmap_is_set(b, vlan)) { bitmap_set1(b, vlan); n++; } } - if (!n) { - free(b); - return NULL; - } - - return b; + return n; } /* Returns true if 'a' and 'b' are the same: either both null or both the same