#include <vector>
#include <stdexcept>
+#include <folly/CPortability.h>
#include <folly/detail/Stats.h>
namespace folly {
: buckets_(bucketSize, min, max, Bucket()) {}
/* Add a data point to the histogram */
- void addValue(ValueType value) {
+ void addValue(ValueType value) UBSAN_DISABLE("signed-integer-overflow")
+ UBSAN_DISABLE("unsigned-integer-overflow") {
Bucket& bucket = buckets_.getByValue(value);
- // TODO: It would be nice to handle overflow here.
+ // NOTE: Overflow is handled elsewhere and tests check this
+ // behavior (see HistogramTest.cpp TestOverflow* tests).
+ // TODO: It would be nice to handle overflow here and redesign this class.
bucket.sum += value;
bucket.count += 1;
}
/* Add multiple same data points to the histogram */
- void addRepeatedValue(ValueType value, uint64_t nSamples) {
+ void addRepeatedValue(ValueType value, uint64_t nSamples)
+ UBSAN_DISABLE("signed-integer-overflow")
+ UBSAN_DISABLE("unsigned-integer-overflow") {
Bucket& bucket = buckets_.getByValue(value);
- // TODO: It would be nice to handle overflow here.
+ // NOTE: Overflow is handled elsewhere and tests check this
+ // behavior (see HistogramTest.cpp TestOverflow* tests).
+ // TODO: It would be nice to handle overflow here and redesign this class.
bucket.sum += value * nSamples;
bucket.count += nSamples;
}
* had previously been added to the histogram; it merely subtracts the
* requested value from the appropriate bucket's sum.
*/
- void removeValue(ValueType value) {
+ void removeValue(ValueType value) UBSAN_DISABLE("signed-integer-overflow")
+ UBSAN_DISABLE("unsigned-integer-overflow") {
Bucket& bucket = buckets_.getByValue(value);
- // TODO: It would be nice to handle overflow here.
+ // NOTE: Overflow is handled elsewhere and tests check this
+ // behavior (see HistogramTest.cpp TestOverflow* tests).
+ // TODO: It would be nice to handle overflow here and redesign this class.
if (bucket.count > 0) {
bucket.sum -= value;
bucket.count -= 1;