When using clang, switch on -Wc++11-narrowing
See https://clang.llvm.org/docs/DiagnosticsReference.html#wc-11-narrowing for datails. This catches a narrowing bug that broke a downstream project in https://codereview.webrtc.org/2995523002/. BUG=none Review-Url: https://codereview.webrtc.org/2995073002 Cr-Commit-Position: refs/heads/master@{#19366}
This commit is contained in:
parent
3004fd0888
commit
5b9746ef10
@ -161,6 +161,7 @@ config("common_config") {
|
||||
|
||||
if (is_clang) {
|
||||
cflags += [
|
||||
"-Wc++11-narrowing",
|
||||
"-Wimplicit-fallthrough",
|
||||
"-Wthread-safety",
|
||||
"-Winconsistent-missing-override",
|
||||
|
||||
@ -95,8 +95,8 @@ TEST(RtcpPacketSdesTest, CreateAndParseCnameItemWithEmptyString) {
|
||||
}
|
||||
|
||||
TEST(RtcpPacketSdesTest, ParseSkipsNonCNameField) {
|
||||
const char kName[] = "abc";
|
||||
const std::string kCname = "de";
|
||||
const uint8_t kName[] = "abc";
|
||||
const uint8_t kCname[] = "de";
|
||||
const uint8_t kValidPacket[] = {0x81, 202, 0x00, 0x04,
|
||||
0x12, 0x34, 0x56, 0x78,
|
||||
kNameTag, 3, kName[0], kName[1], kName[2],
|
||||
@ -111,13 +111,13 @@ TEST(RtcpPacketSdesTest, ParseSkipsNonCNameField) {
|
||||
|
||||
EXPECT_EQ(1u, parsed.chunks().size());
|
||||
EXPECT_EQ(kSenderSsrc, parsed.chunks()[0].ssrc);
|
||||
EXPECT_EQ(kCname, parsed.chunks()[0].cname);
|
||||
EXPECT_EQ("de", parsed.chunks()[0].cname);
|
||||
}
|
||||
|
||||
TEST(RtcpPacketSdesTest, ParseSkipsChunksWithoutCName) {
|
||||
const char kName[] = "ab";
|
||||
const char kEmail[] = "de";
|
||||
const std::string kCname = "def";
|
||||
const uint8_t kName[] = "ab";
|
||||
const uint8_t kEmail[] = "de";
|
||||
const uint8_t kCname[] = "def";
|
||||
const uint8_t kPacket[] = {0x82, 202, 0x00, 0x07,
|
||||
0x12, 0x34, 0x56, 0x78, // 1st chunk.
|
||||
kNameTag, 3, kName[0], kName[1], kName[2],
|
||||
@ -134,12 +134,12 @@ TEST(RtcpPacketSdesTest, ParseSkipsChunksWithoutCName) {
|
||||
EXPECT_TRUE(test::ParseSinglePacket(kPacket, &parsed));
|
||||
ASSERT_EQ(1u, parsed.chunks().size());
|
||||
EXPECT_EQ(0x23456789u, parsed.chunks()[0].ssrc);
|
||||
EXPECT_EQ(kCname, parsed.chunks()[0].cname);
|
||||
EXPECT_EQ("def", parsed.chunks()[0].cname);
|
||||
}
|
||||
|
||||
TEST(RtcpPacketSdesTest, ParseFailsWithoutChunkItemTerminator) {
|
||||
const char kName[] = "abc";
|
||||
const char kCname[] = "d";
|
||||
const uint8_t kName[] = "abc";
|
||||
const uint8_t kCname[] = "d";
|
||||
// No place for next chunk item.
|
||||
const uint8_t kInvalidPacket[] = {0x81, 202, 0x00, 0x03,
|
||||
0x12, 0x34, 0x56, 0x78,
|
||||
@ -154,8 +154,8 @@ TEST(RtcpPacketSdesTest, ParseFailsWithoutChunkItemTerminator) {
|
||||
}
|
||||
|
||||
TEST(RtcpPacketSdesTest, ParseFailsWithDamagedChunkItem) {
|
||||
const char kName[] = "ab";
|
||||
const char kCname[] = "d";
|
||||
const uint8_t kName[] = "ab";
|
||||
const uint8_t kCname[] = "d";
|
||||
// Next chunk item has non-terminator type, but not the size.
|
||||
const uint8_t kInvalidPacket[] = {0x81, 202, 0x00, 0x03,
|
||||
0x12, 0x34, 0x56, 0x78,
|
||||
@ -171,8 +171,8 @@ TEST(RtcpPacketSdesTest, ParseFailsWithDamagedChunkItem) {
|
||||
}
|
||||
|
||||
TEST(RtcpPacketSdesTest, ParseFailsWithTooLongChunkItem) {
|
||||
const char kName[] = "abc";
|
||||
const char kCname[] = "d";
|
||||
const uint8_t kName[] = "abc";
|
||||
const uint8_t kCname[] = "d";
|
||||
// Last chunk item has length that goes beyond the buffer end.
|
||||
const uint8_t kInvalidPacket[] = {0x81, 202, 0x00, 0x03,
|
||||
0x12, 0x34, 0x56, 0x78,
|
||||
@ -187,8 +187,8 @@ TEST(RtcpPacketSdesTest, ParseFailsWithTooLongChunkItem) {
|
||||
}
|
||||
|
||||
TEST(RtcpPacketSdesTest, ParseFailsWithTwoCNames) {
|
||||
const char kCname1[] = "a";
|
||||
const char kCname2[] = "de";
|
||||
const uint8_t kCname1[] = "a";
|
||||
const uint8_t kCname2[] = "de";
|
||||
const uint8_t kInvalidPacket[] = {0x81, 202, 0x00, 0x03,
|
||||
0x12, 0x34, 0x56, 0x78,
|
||||
kCnameTag, 1, kCname1[0],
|
||||
@ -203,8 +203,8 @@ TEST(RtcpPacketSdesTest, ParseFailsWithTwoCNames) {
|
||||
}
|
||||
|
||||
TEST(RtcpPacketSdesTest, ParseFailsWithTooLittleSpaceForNextChunk) {
|
||||
const char kCname[] = "a";
|
||||
const char kEmail[] = "de";
|
||||
const uint8_t kCname[] = "a";
|
||||
const uint8_t kEmail[] = "de";
|
||||
// Two chunks are promised in the header, but no place for the second chunk.
|
||||
const uint8_t kInvalidPacket[] = {0x82, 202, 0x00, 0x04,
|
||||
0x12, 0x34, 0x56, 0x78, // 1st chunk.
|
||||
|
||||
@ -153,7 +153,8 @@ class TestFrameBuffer2 : public ::testing::Test {
|
||||
T... refs) {
|
||||
static_assert(sizeof...(refs) <= kMaxReferences,
|
||||
"To many references specified for FrameObject.");
|
||||
std::array<uint16_t, sizeof...(refs)> references = {{refs...}};
|
||||
std::array<uint16_t, sizeof...(refs)> references = {
|
||||
{rtc::checked_cast<uint16_t>(refs)...}};
|
||||
|
||||
std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
|
||||
frame->picture_id = picture_id;
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#include "base/third_party/libevent/event.h"
|
||||
#include "webrtc/rtc_base/checks.h"
|
||||
#include "webrtc/rtc_base/logging.h"
|
||||
#include "webrtc/rtc_base/safe_conversions.h"
|
||||
#include "webrtc/rtc_base/task_queue_posix.h"
|
||||
#include "webrtc/rtc_base/timeutils.h"
|
||||
|
||||
@ -317,7 +318,8 @@ void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task,
|
||||
QueueContext* ctx =
|
||||
static_cast<QueueContext*>(pthread_getspecific(GetQueuePtrTls()));
|
||||
ctx->pending_timers_.push_back(timer);
|
||||
timeval tv = {milliseconds / 1000, (milliseconds % 1000) * 1000};
|
||||
timeval tv = {rtc::dchecked_cast<int>(milliseconds / 1000),
|
||||
rtc::dchecked_cast<int>(milliseconds % 1000) * 1000};
|
||||
event_add(&timer->ev, &tv);
|
||||
} else {
|
||||
PostTask(std::unique_ptr<QueuedTask>(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user