From bb2dc792a2bfd24f26184be1e601277807006149 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Mon, 18 Jul 2022 21:21:06 +0000 Subject: [PATCH] fix(storage): no char for `std::uniform_int_distribution` TIL: it is undefined behavior to use `std::uniform_int_distribution<>` with `char`, `unsigned char`, and its aliases. And some platforms enforce this. --- google/cloud/storage/internal/invocation_id_generator.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/google/cloud/storage/internal/invocation_id_generator.cc b/google/cloud/storage/internal/invocation_id_generator.cc index f7838c8adca3c..7534fd470a4e1 100644 --- a/google/cloud/storage/internal/invocation_id_generator.cc +++ b/google/cloud/storage/internal/invocation_id_generator.cc @@ -42,10 +42,11 @@ std::string InvocationIdGenerator::MakeInvocationId() { auto constexpr kIdBitCount = 128; auto constexpr kArraySize = kIdBitCount / 8; std::array buf; - std::uniform_int_distribution d(0, 255); + std::uniform_int_distribution d(0, 255); std::lock_guard lk(mu_); - std::generate(buf.begin(), buf.end(), [&] { return d(generator_); }); + std::generate(buf.begin(), buf.end(), + [&] { return static_cast(d(generator_)); }); return buf; }(); o[kVersionOctet] = (o[kVersionOctet] & kVersionMask) | kVersion;