Skip to content

Commit 6b5199f

Browse files
committed
MB-67564: Fix narrowing conversion in Histogram
When we compile Magma with MSVC with `/we4267 /we4244` enabled, we see the following error: ``` C:\...\platform\include\platform/histogram.h(157): error C4244: '=': conversion from 'T' to 'double', possible loss of data with [ T=size_t ] ``` This patch aims to fix this by using a `gsl::narrow_cast`. Change-Id: Idfcd5d6a7adff6781f4fe48dd9d065ee20f20cfa Reviewed-on: https://review.couchbase.org/c/platform/+/231522 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Jim Walker <jim@couchbase.com>
1 parent 05d0272 commit 6b5199f

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

include/platform/histogram.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <memory>
2020
#include <numeric>
2121
#include <vector>
22+
#include <gsl/gsl-lite.hpp>
2223

2324
// Custom microseconds duration used for measuring histogram stats.
2425
// Stats will never be negative, so an unsigned Rep is used.
@@ -154,7 +155,7 @@ class GrowingWidthGenerator {
154155
: _growth(growth),
155156
_start(start) {
156157
// Dividing two durations returns a value of the underlying Rep.
157-
_width = width / T(1);
158+
_width = gsl::narrow_cast<double>(width / T(1));
158159
}
159160

160161
/**

0 commit comments

Comments
 (0)