diff options
author | Ben Pfaff <blp@ovn.org> | 2017-05-26 21:50:36 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-06-01 20:47:22 -0700 |
commit | 6513cb3d6dbf4479ee19b29ba4d8a3c4f71a709c (patch) | |
tree | 568686e8b11af636ee40cd96cd963295a3ed7610 /tests | |
parent | caaabd191d04dfb810771a3e2dcbcd532a66fb09 (diff) | |
download | openvswitch-6513cb3d6dbf4479ee19b29ba4d8a3c4f71a709c.tar.gz |
test-cmap: Avoid shift by full width of type in find_batch().
In C, it is undefined to shift an N-bit value by N. This fixes the
problem in find_batch() for the case where i == 0.
Found by Coverity.
Reported-at: https://scan3.coverity.com/reports.htm#v16889/p10449/fileInstanceId=14763098&defectInstanceId=4304031&mergedDefectId=68209
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Justin Pettit <jpettit@ovn.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-cmap.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/tests/test-cmap.c b/tests/test-cmap.c index e159a164f..2c6fa89eb 100644 --- a/tests/test-cmap.c +++ b/tests/test-cmap.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2013, 2014, 2016 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2013, 2014, 2016, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -412,7 +412,6 @@ find_batch(const struct cmap *cmap, const int value) { size_t i, ret; const size_t end = MIN(n_batch, n_elems - value); - unsigned long map = ~0; uint32_t hashes[N_BATCH_MAX]; const struct cmap_node *nodes[N_BATCH_MAX]; @@ -431,7 +430,7 @@ find_batch(const struct cmap *cmap, const int value) ret = i; - map >>= BITMAP_ULONG_BITS - i; /* Clear excess bits. */ + unsigned long map = i ? ~0UL >> (BITMAP_ULONG_BITS - i) : 0; map = cmap_find_batch(cmap, map, hashes, nodes); ULLONG_FOR_EACH_1(i, map) { |