X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fhmap.c;h=71943a74e6e092f5c2f2aba4fac1be4f52137b49;hb=c6278d208924bb04c41266ddca276712f95533bc;hp=d66cf271a27e492f3b030d0aeabdeffb241d49f2;hpb=63e60b866ffee6895e1772da2c48591ab2767aa7;p=openvswitch diff --git a/lib/hmap.c b/lib/hmap.c index d66cf271..71943a74 100644 --- a/lib/hmap.c +++ b/lib/hmap.c @@ -48,11 +48,17 @@ hmap_swap(struct hmap *a, struct hmap *b) struct hmap tmp = *a; *a = *b; *b = tmp; - if (a->buckets == &b->one) { - a->buckets = &a->one; - } - if (b->buckets == &a->one) { - b->buckets = &b->one; + hmap_moved(a); + hmap_moved(b); +} + +/* Adjusts 'hmap' to compensate for having moved position in memory (e.g. due + * to realloc()). */ +void +hmap_moved(struct hmap *hmap) +{ + if (!hmap->mask) { + hmap->buckets = &hmap->one; } }