Skip to content

Commit 398c6dd

Browse files
yfeldblummeta-codesync[bot]
authored andcommitted
use explicit types in Cursor::write in ti/
Summary: Addresses problems like this: ``` void* buf = /*...*/; uint16_t word = /*...*/; cursor.write(word & 0xffff); // oops, 32-bit store due to implicit integer promotion ``` Differential Revision: D94252970 fbshipit-source-id: c7caa45e204b3c8975e18145b07c3d1c9a578009
1 parent 6cd12c8 commit 398c6dd

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

moxygen/MoQFramer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3429,7 +3429,7 @@ void writeVarint(
34293429
}
34303430
folly::io::QueueAppender appender(&buf, kMaxFrameHeaderSize);
34313431
auto appenderOp = [appender = std::move(appender)](auto val) mutable {
3432-
appender.writeBE(val);
3432+
appender.writeBE(folly::tag<decltype(val)>, val);
34333433
};
34343434
auto res = quic::encodeQuicInteger(value, appenderOp);
34353435
if (res.hasError()) {

moxygen/moq_mi/MoQMi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void MoQMi::writeVarint(
442442
}
443443
folly::io::QueueAppender appender(&buf, MoQMi::kMaxQuicIntSize);
444444
auto appenderOp = [appender = std::move(appender)](auto val) mutable {
445-
appender.writeBE(val);
445+
appender.writeBE(folly::tag<decltype(val)>, val);
446446
};
447447
auto res = quic::encodeQuicInteger(value, appenderOp);
448448
if (res.hasError()) {

moxygen/samples/hack/MoQVideoPublisher.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ std::unique_ptr<folly::IOBuf> serializeAVCDecoderConfigurationRecord(
9292
folly::io::Appender appender(configRecord.get(), 1024);
9393

9494
// Configuration record header (ISO/IEC 14496-15 AVC file format)
95-
appender.writeBE<uint8_t>(1); // configurationVersion_
95+
appender.writeBE<uint8_t>(static_cast<uint8_t>(1)); // configurationVersion_
9696

9797
// Get profile/level from first SPS
9898
folly::io::Cursor spsCursor(spsNalus.data());
@@ -107,21 +107,24 @@ std::unique_ptr<folly::IOBuf> serializeAVCDecoderConfigurationRecord(
107107

108108
// 6 bits reserved (111111 = 0xFC) + 2 bits NAL length size - 1
109109
const uint8_t lengthSizeMinusOne = 3; // Using 4 byte NAL length size
110-
appender.writeBE<uint8_t>(0xFC | lengthSizeMinusOne);
110+
appender.writeBE<uint8_t>(static_cast<uint8_t>(0xFC | lengthSizeMinusOne));
111111

112112
// 3 bits reserved (111 = 0xE0) + 5 bits number of SPS NALUs
113-
appender.writeBE<uint8_t>(0xE0 | (spsNalus.size() & 0x1F));
113+
appender.writeBE<uint8_t>(
114+
static_cast<uint8_t>(0xE0 | (spsNalus.size() & 0x1F)));
114115

115116
// Write SPS NALUs
116117
for (const auto& sps : spsNalus) {
117-
appender.writeBE<uint16_t>(sps.computeChainDataLength());
118+
appender.writeBE<uint16_t>(
119+
static_cast<uint16_t>(sps.computeChainDataLength()));
118120
appender.push(sps.data(), sps.computeChainDataLength());
119121
}
120122

121123
// Write PPS count and NALUs
122-
appender.writeBE<uint8_t>(ppsNalus.size());
124+
appender.writeBE<uint8_t>(static_cast<uint8_t>(ppsNalus.size()));
123125
for (const auto& pps : ppsNalus) {
124-
appender.writeBE<uint16_t>(pps.computeChainDataLength());
126+
appender.writeBE<uint16_t>(
127+
static_cast<uint16_t>(pps.computeChainDataLength()));
125128
appender.push(pps.data(), pps.computeChainDataLength());
126129
}
127130

@@ -130,13 +133,13 @@ std::unique_ptr<folly::IOBuf> serializeAVCDecoderConfigurationRecord(
130133
AVCProfileIndication != 77 && // Main
131134
AVCProfileIndication != 88) { // Extended
132135
// 6 bits reserved (111111) + 2 bits chroma format (typically 1 = 4:2:0)
133-
appender.writeBE<uint8_t>(0xFC | 1);
136+
appender.writeBE<uint8_t>(static_cast<uint8_t>(0xFC | 1));
134137
// 5 bits reserved (11111) + 3 bits bit depth luma minus 8 (typically 0)
135-
appender.writeBE<uint8_t>(0xF8);
138+
appender.writeBE<uint8_t>(static_cast<uint8_t>(0xF8));
136139
// 5 bits reserved (11111) + 3 bits bit depth chroma minus 8 (typically 0)
137-
appender.writeBE<uint8_t>(0xF8);
140+
appender.writeBE<uint8_t>(static_cast<uint8_t>(0xF8));
138141
// Number of SPS Ext NALUs (typically 0)
139-
appender.writeBE<uint8_t>(0);
142+
appender.writeBE<uint8_t>(static_cast<uint8_t>(0));
140143
}
141144

142145
return configRecord;

moxygen/test/MoQFramerTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace {
2020
inline void writeVarintTo(folly::IOBufQueue& q, uint64_t v) {
2121
folly::io::QueueAppender appender(&q, kMaxFrameHeaderSize);
2222
auto appenderOp = [appender = std::move(appender)](auto val) mutable {
23-
appender.writeBE(val);
23+
appender.writeBE(folly::tag<decltype(val)>, val);
2424
};
2525
(void)quic::encodeQuicInteger(v, appenderOp);
2626
}
@@ -475,7 +475,7 @@ TEST(MoQFramerTest, ParseClientSetupWithUnknownAndSupportedVersions) {
475475
folly::IOBufQueue patchBuf{folly::IOBufQueue::cacheChainLength()};
476476
folly::io::QueueAppender appender(&patchBuf, kMaxFrameHeaderSize);
477477
XCHECK(quic::encodeQuicInteger(kVersionDraft03, [&](auto val) {
478-
appender.writeBE(val);
478+
appender.writeBE(folly::tag<decltype(val)>, val);
479479
}));
480480
auto patchIOBuf = patchBuf.move();
481481

@@ -570,7 +570,7 @@ TEST_P(MoQFramerTest, parseFixedString) {
570570
CHECK(
571571
quic::encodeQuicInteger(
572572
s.length(), [appender = std::move(appender)](auto val) mutable {
573-
appender.writeBE(val);
573+
appender.writeBE(folly::tag<decltype(val)>, val);
574574
}));
575575

576576
// Write a blob of bytes to buffer

0 commit comments

Comments
 (0)