Skip to content

Commit 72edbc0

Browse files
yfeldblummeta-codesync[bot]
authored andcommitted
prep for explicit types in Cursor::write
Summary: Addresses problems like this: ``` void* buf = /*...*/; uint16_t word = /*...*/; cursor.write(word & 0xffff); // oops, 32-bit store due to implicit integer promotion ``` Reviewed By: dmm-fb Differential Revision: D94252971 fbshipit-source-id: 22d05d2bfe6f173e40e4e5dcf81f0bccc74dd1b3
1 parent fb5a7b0 commit 72edbc0

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

third-party/fizz/src/fizz/record/Types-inl.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct Writer {
8282
std::is_enum<T>::value && std::is_same<U, T>::value,
8383
T>::type& in,
8484
folly::io::Appender& appender) {
85-
using UT = typename std::underlying_type<U>::type;
85+
using UT = std::underlying_type_t<U>;
8686
static_assert(
8787
std::is_unsigned<UT>::value,
8888
"enums meant to be serialized should be unsigned");
@@ -233,9 +233,8 @@ inline Status write<Extension>(
233233
Error& err,
234234
const Extension& extension,
235235
folly::io::Appender& out) {
236-
out.writeBE(
237-
static_cast<typename std::underlying_type<ExtensionType>::type>(
238-
extension.extension_type));
236+
using UT = std::underlying_type_t<ExtensionType>;
237+
out.writeBE(static_cast<UT>(extension.extension_type));
239238
FIZZ_RETURN_ON_ERROR(writeBuf<uint16_t>(err, extension.extension_data, out));
240239
return Status::Success;
241240
}

third-party/proxygen/src/proxygen/lib/http/codec/test/HQFramerTest.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ size_t writeFrameHeaderManual(folly::IOBufQueue& queue,
1919
uint64_t decodedType,
2020
uint64_t decodedLength) {
2121
folly::io::QueueAppender appender(&queue, proxygen::hq::kMaxFrameHeaderSize);
22-
auto appenderOp = [&](auto val) { appender.writeBE(val); };
22+
auto appenderOp = [&](auto val) { appender.writeBE<decltype(val)>(val); };
2323
auto typeRes = quic::encodeQuicInteger(decodedType, appenderOp);
2424
CHECK(typeRes.has_value());
2525
auto lengthRes = quic::encodeQuicInteger(decodedLength, appenderOp);
@@ -54,7 +54,7 @@ void writeValidFrame(folly::IOBufQueue& queue, proxygen::hq::FrameType type) {
5454
? maybeDataSize
5555
: 0));
5656
folly::io::QueueAppender appender(&queue, *idSize);
57-
auto appenderOp = [&](auto val) { appender.writeBE(val); };
57+
auto appenderOp = [&](auto val) { appender.writeBE<decltype(val)>(val); };
5858
auto idResult = quic::encodeQuicInteger(id, appenderOp);
5959
CHECK(idResult.has_value());
6060
if (type == proxygen::hq::FrameType::PUSH_PROMISE) {
@@ -84,7 +84,7 @@ void writeValidFrame(folly::IOBufQueue& queue, proxygen::hq::FrameType type) {
8484
static_cast<uint64_t>(type),
8585
*prioritizedIdSize + data->computeChainDataLength());
8686
folly::io::QueueAppender appender(&queue, *prioritizedIdSize);
87-
auto appenderOp = [&](auto val) { appender.writeBE(val); };
87+
auto appenderOp = [&](auto val) { appender.writeBE<decltype(val)>(val); };
8888
auto prioritizedIdResult =
8989
quic::encodeQuicInteger(prioritizedId, appenderOp);
9090
CHECK(prioritizedIdResult.has_value());

0 commit comments

Comments
 (0)