FEC: Fix to coverity issue 14448: unintended sign extension.

Review URL: https://webrtc-codereview.appspot.com/647004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2400 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
marpan@webrtc.org 2012-06-12 20:12:13 +00:00
parent f0d4696ab3
commit c35f1d26c5
2 changed files with 13 additions and 16 deletions

View File

@ -111,8 +111,7 @@ int32_t ForwardErrorCorrection::GenerateFEC(
} }
const uint16_t numMediaPackets = mediaPacketList.size(); const uint16_t numMediaPackets = mediaPacketList.size();
bool lBit = (numMediaPackets > 8 * kMaskSizeLBitClear); bool lBit = (numMediaPackets > 8 * kMaskSizeLBitClear);
uint16_t numMaskBytes = lBit ? int numMaskBytes = lBit ? kMaskSizeLBitSet : kMaskSizeLBitClear;
kMaskSizeLBitSet : kMaskSizeLBitClear;
if (numMediaPackets > kMaxMediaPackets) { if (numMediaPackets > kMaxMediaPackets) {
WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id,
@ -217,19 +216,18 @@ int ForwardErrorCorrection::GetNumberOfFecPackets(int numMediaPackets,
void ForwardErrorCorrection::GenerateFecBitStrings( void ForwardErrorCorrection::GenerateFecBitStrings(
const PacketList& mediaPacketList, const PacketList& mediaPacketList,
uint8_t* packetMask, uint8_t* packetMask,
uint32_t numFecPackets, int numFecPackets,
bool lBit) { bool lBit) {
if (mediaPacketList.empty()) { if (mediaPacketList.empty()) {
return; return;
} }
uint8_t mediaPayloadLength[2]; uint8_t mediaPayloadLength[2];
const uint16_t numMaskBytes = lBit ? const int numMaskBytes = lBit ? kMaskSizeLBitSet : kMaskSizeLBitClear;
kMaskSizeLBitSet : kMaskSizeLBitClear;
const uint16_t ulpHeaderSize = lBit ? const uint16_t ulpHeaderSize = lBit ?
kUlpHeaderSizeLBitSet : kUlpHeaderSizeLBitClear; kUlpHeaderSizeLBitSet : kUlpHeaderSizeLBitClear;
const uint16_t fecRtpOffset = kFecHeaderSize + ulpHeaderSize - kRtpHeaderSize; const uint16_t fecRtpOffset = kFecHeaderSize + ulpHeaderSize - kRtpHeaderSize;
for (uint32_t i = 0; i < numFecPackets; i++) { for (int i = 0; i < numFecPackets; i++) {
PacketList::const_iterator mediaListIt = mediaPacketList.begin(); PacketList::const_iterator mediaListIt = mediaPacketList.begin();
uint32_t pktMaskIdx = i * numMaskBytes; uint32_t pktMaskIdx = i * numMaskBytes;
uint32_t mediaPktIdx = 0; uint32_t mediaPktIdx = 0;
@ -304,8 +302,8 @@ void ForwardErrorCorrection::GenerateFecBitStrings(
int ForwardErrorCorrection::InsertZerosInBitMasks( int ForwardErrorCorrection::InsertZerosInBitMasks(
const PacketList& media_packets, const PacketList& media_packets,
uint8_t* packet_mask, uint8_t* packet_mask,
uint16_t num_mask_bytes, int num_mask_bytes,
uint32_t num_fec_packets) { int num_fec_packets) {
uint8_t* new_mask = NULL; uint8_t* new_mask = NULL;
if (media_packets.size() <= 1) { if (media_packets.size() <= 1) {
return media_packets.size(); return media_packets.size();
@ -406,7 +404,7 @@ void ForwardErrorCorrection::GenerateFecUlpHeaders(
const PacketList& mediaPacketList, const PacketList& mediaPacketList,
uint8_t* packetMask, uint8_t* packetMask,
bool lBit, bool lBit,
uint32_t numFecPackets) { int numFecPackets) {
// -- Generate FEC and ULP headers -- // -- Generate FEC and ULP headers --
// //
// FEC Header, 10 bytes // FEC Header, 10 bytes
@ -431,12 +429,11 @@ void ForwardErrorCorrection::GenerateFecUlpHeaders(
PacketList::const_iterator mediaListIt = mediaPacketList.begin(); PacketList::const_iterator mediaListIt = mediaPacketList.begin();
Packet* mediaPacket = *mediaListIt; Packet* mediaPacket = *mediaListIt;
assert(mediaPacket != NULL); assert(mediaPacket != NULL);
const uint16_t numMaskBytes = lBit ? int numMaskBytes = lBit ? kMaskSizeLBitSet : kMaskSizeLBitClear;
kMaskSizeLBitSet : kMaskSizeLBitClear;
const uint16_t ulpHeaderSize = lBit ? const uint16_t ulpHeaderSize = lBit ?
kUlpHeaderSizeLBitSet : kUlpHeaderSizeLBitClear; kUlpHeaderSizeLBitSet : kUlpHeaderSizeLBitClear;
for (uint32_t i = 0; i < numFecPackets; i++) { for (int i = 0; i < numFecPackets; i++) {
// -- FEC header -- // -- FEC header --
_generatedFecPackets[i].data[0] &= 0x7f; // Set E to zero. _generatedFecPackets[i].data[0] &= 0x7f; // Set E to zero.
if (lBit == 0) { if (lBit == 0) {

View File

@ -238,7 +238,7 @@ class ForwardErrorCorrection {
void GenerateFecUlpHeaders(const PacketList& mediaPacketList, void GenerateFecUlpHeaders(const PacketList& mediaPacketList,
uint8_t* packetMask, uint8_t* packetMask,
bool lBit, bool lBit,
uint32_t numFecPackets); int numFecPackets);
// Analyzes |media_packets| for holes in the sequence and inserts zero columns // Analyzes |media_packets| for holes in the sequence and inserts zero columns
// into the |packet_mask| where those holes are found. Zero columns means that // into the |packet_mask| where those holes are found. Zero columns means that
@ -248,8 +248,8 @@ class ForwardErrorCorrection {
// allocated. // allocated.
int InsertZerosInBitMasks(const PacketList& media_packets, int InsertZerosInBitMasks(const PacketList& media_packets,
uint8_t* packet_mask, uint8_t* packet_mask,
uint16_t num_mask_bytes, int num_mask_bytes,
uint32_t num_fec_packets); int num_fec_packets);
// Inserts |num_zeros| zero columns into |new_mask| at position // Inserts |num_zeros| zero columns into |new_mask| at position
// |new_bit_index|. If the current byte of |new_mask| can't fit all zeros, the // |new_bit_index|. If the current byte of |new_mask| can't fit all zeros, the
@ -279,7 +279,7 @@ class ForwardErrorCorrection {
void GenerateFecBitStrings(const PacketList& mediaPacketList, void GenerateFecBitStrings(const PacketList& mediaPacketList,
uint8_t* packetMask, uint8_t* packetMask,
uint32_t numFecPackets, int numFecPackets,
bool lBit); bool lBit);
// Insert received packets into FEC or recovered list. // Insert received packets into FEC or recovered list.