Commit 0a310d52 authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Prevent AtomicHashArray being contstructed with 0 elements

Summary: An atomic hash array with zero elements isn't useful in any way, not even as an empty set (due to it not being comparable), and there are multiple places that simply crash if you try to use, so just prevent it from being constructed in the first place.

Reviewed By: yfeldblum

Differential Revision: D15789540

fbshipit-source-id: a811f70fb0e9e21a83dc9aea79ec017ae2d7e0a5
parent 6f3d4da9
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <folly/detail/AtomicHashUtils.h> #include <folly/detail/AtomicHashUtils.h>
#include <folly/lang/Bits.h> #include <folly/lang/Bits.h>
#include <folly/lang/Exception.h>
namespace folly { namespace folly {
...@@ -58,7 +59,11 @@ AtomicHashArray< ...@@ -58,7 +59,11 @@ AtomicHashArray<
numEntries_(0, cacheSize), numEntries_(0, cacheSize),
numPendingEntries_(0, cacheSize), numPendingEntries_(0, cacheSize),
isFull_(0), isFull_(0),
numErases_(0) {} numErases_(0) {
if (capacity == 0) {
throw_exception<std::invalid_argument>("capacity");
}
}
/* /*
* findInternal -- * findInternal --
......
...@@ -435,3 +435,7 @@ TEST(Aha, ConstValue) { ...@@ -435,3 +435,7 @@ TEST(Aha, ConstValue) {
auto aha = AHAIntCInt::create(10); auto aha = AHAIntCInt::create(10);
aha->emplace(1, 2); aha->emplace(1, 2);
} }
TEST(Aha, ZeroSizeMapThrows) {
EXPECT_THROW(AHAIntCInt::create(0), std::invalid_argument);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment