Skip to content

Commit

Permalink
Fix unintended sign extensions detected by Coverity.
Browse files Browse the repository at this point in the history
Coverity 700703, 700704, 700705, 700706, 700707, 700708, 700709,
700710, 700711, 700712, 700713, 700714, 700715, 700716, 700717.

Most likely, the uses of "unsigned long" in the code should be changed
to uint32_t (or less likely, uint64_t).
  • Loading branch information
stichnot committed Jun 9, 2013
1 parent 5e020c7 commit 9f900fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 48 deletions.
16 changes: 5 additions & 11 deletions mythtv/libs/libmythtv/dsmcc.cpp
Expand Up @@ -124,8 +124,7 @@ bool Dsmcc::ProcessSectionHeader(DsmccSectionHeader *header,

/* skip to end, read last 4 bytes and store in crc */

header->crc = ((data[crc_offset] << 24) | (data[crc_offset+1] << 16) |
(data[crc_offset+2] << 8) | (data[crc_offset+3]));
header->crc = COMBINE32(data, crc_offset);

return true;
}
Expand Down Expand Up @@ -255,8 +254,7 @@ void Dsmcc::ProcessDownloadInfoIndication(const unsigned char *data,
DsmccDii dii;
int off = 0;

dii.download_id = ((data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | (data[3]));
dii.download_id = COMBINE32(data, 0);

ObjCarousel *car = GetCarouselById(dii.download_id);

Expand All @@ -274,8 +272,7 @@ void Dsmcc::ProcessDownloadInfoIndication(const unsigned char *data,
off += 2;

off += 6; /* not used fields */
dii.tc_download_scenario = ((data[off + 0] << 24) | (data[off + 1] << 16) |
(data[off + 2] << 8) | (data[off + 3]));
dii.tc_download_scenario = COMBINE32(data, off);
off += 4;

/* skip unused compatibility descriptor len */
Expand All @@ -288,9 +285,7 @@ void Dsmcc::ProcessDownloadInfoIndication(const unsigned char *data,
{
dii.modules[i].module_id = (data[off] << 8) | data[off + 1];
off += 2;
dii.modules[i].module_size =
(data[off + 0] << 24) | (data[off + 1] << 16) |
(data[off + 2] << 8) | (data[off + 3]);
dii.modules[i].module_size = COMBINE32(data, off);
off += 4;
dii.modules[i].module_version = data[off++];
dii.modules[i].module_info_len = data[off++];
Expand Down Expand Up @@ -424,8 +419,7 @@ void Dsmcc::ProcessSectionData(const unsigned char *data, int length)
return;
}

unsigned long download_id = ((hdrData[4] << 24) | (hdrData[5] << 16) |
(hdrData[6] << 8) | (hdrData[7]));
unsigned long download_id = COMBINE32(hdrData, 4);
/* skip reserved byte */
// char adaptation_len = hdrData[9];
unsigned message_len = (hdrData[10] << 8) | hdrData[11];
Expand Down
6 changes: 6 additions & 0 deletions mythtv/libs/libmythtv/dsmcc.h
Expand Up @@ -114,4 +114,10 @@ class Dsmcc
unsigned short m_startTag;
};

#define COMBINE32(data, idx) \
((((unsigned)((data)[(idx) + 0])) << 24) | \
(((unsigned)((data)[(idx) + 1])) << 16) | \
(((unsigned)((data)[(idx) + 2])) << 8) | \
(((unsigned)((data)[(idx) + 3]))))

#endif
55 changes: 18 additions & 37 deletions mythtv/libs/libmythtv/dsmccbiop.cpp
Expand Up @@ -188,16 +188,14 @@ bool BiopMessage::ProcessMsgHdr(unsigned char *data, unsigned long *curp)
return false;
}

m_message_size = ((buf[off + 0] << 24) | (buf[off+1] << 16) |
(buf[off + 2] << 8) | (buf[off + 3]));
m_message_size = COMBINE32(buf, off);
off += 4;

uint nObjLen = buf[off++];
m_objkey = DSMCCCacheKey((const char*)buf + off, nObjLen);
off += nObjLen;

m_objkind_len = ((buf[off + 0] << 24) | (buf[off + 1] << 16) |
(buf[off + 2] << 8) | (buf[off + 3]));
m_objkind_len = COMBINE32(buf, off);
off += 4;
m_objkind = (char*) malloc(m_objkind_len);
memcpy(m_objkind, buf + off, m_objkind_len);
Expand Down Expand Up @@ -242,8 +240,7 @@ bool BiopMessage::ProcessDir(
return false; // Error
}

unsigned long msgbody_len = ((buf[off + 0] << 24) | (buf[off + 1] << 16) |
(buf[off + 2] << 8) | (buf[off + 3]));
unsigned long msgbody_len = COMBINE32(buf, off);
off += 4;
int const start = off;

Expand Down Expand Up @@ -313,11 +310,9 @@ bool BiopMessage::ProcessFile(DSMCCCacheModuleData *cachep, DSMCCCache *filecach
return false; // Error
}

msgbody_len = ((buf[off ] << 24) | (buf[off + 1] << 16) |
(buf[off + 2] << 8) | (buf[off + 3]));
msgbody_len = COMBINE32(buf, off);
off += 4;
content_len = ((buf[off ] << 24) | (buf[off + 1] << 16) |
(buf[off + 2] << 8) | (buf[off + 3]));
content_len = COMBINE32(buf, off);
off += 4;
if (content_len + 4 != msgbody_len)
LOG(VB_DSMCC, LOG_WARNING, "[biop] ProcessFile incorrect msgbody_len");
Expand Down Expand Up @@ -362,8 +357,7 @@ void ModuleDescriptorData::Process(const unsigned char *data, int length)
case 0x09: // Compressed.
// Skip the method.
isCompressed = true;
originalSize = ((data[1] << 24) | (data[2] << 16) |
(data[3] << 8) | (data[4]));
originalSize = COMBINE32(data, 1);
break;
default:
break;
Expand All @@ -376,12 +370,9 @@ void ModuleDescriptorData::Process(const unsigned char *data, int length)
int BiopModuleInfo::Process(const unsigned char *data)
{
int off, ret;
mod_timeout = ((data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | (data[3]));
block_timeout = ((data[4] << 24) | (data[5] << 16) |
(data[6] << 8) | (data[7]));
min_blocktime = ((data[8] << 24) | (data[9] << 16) |
(data[10] << 8) | (data[11]));
mod_timeout = COMBINE32(data, 0);
block_timeout = COMBINE32(data, 4);
min_blocktime = COMBINE32(data, 8);

taps_count = data[12];
off = 13;
Expand Down Expand Up @@ -430,11 +421,9 @@ int BiopTap::Process(const unsigned char *data)
if (selector_len >= 10 && selector_type == 0x0001)
{
off += 2;
unsigned long transactionId = ((data[off] << 24) | (data[off + 1] << 16) |
(data[off + 2] << 8) | (data[off + 3]));
unsigned long transactionId = COMBINE32(data, off);
off += 4;
unsigned long timeout = ((data[off] << 24) | (data[off + 1] << 16) |
(data[off + 2] << 8) | (data[off + 3]));
unsigned long timeout = COMBINE32(data, off);
LOG(VB_DSMCC, LOG_DEBUG, QString("[biop] BIOP_DELIVERY_PARA_USE tag %1 id 0x%2 timeout %3uS")
.arg(assoc_tag).arg(transactionId,0,16).arg(timeout));
off += 4;
Expand All @@ -450,8 +439,7 @@ int BiopConnbinder::Process(const unsigned char *data)
{
int off = 0, ret;

component_tag = ((data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | (data[3]));
component_tag = COMBINE32(data, 0);
if (0x49534F40 != component_tag)
{
LOG(VB_DSMCC, LOG_WARNING, "[biop] Invalid Connbinder tag");
Expand Down Expand Up @@ -480,8 +468,7 @@ int BiopObjLocation::Process(const unsigned char *data)
{
int off = 0;

component_tag = ((data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | (data[3]));
component_tag = COMBINE32(data, 0);
if (0x49534F50 != component_tag)
{
LOG(VB_DSMCC, LOG_WARNING, "[biop] Invalid ObjectLocation tag");
Expand All @@ -490,9 +477,7 @@ int BiopObjLocation::Process(const unsigned char *data)
off += 4;

component_data_len = data[off++];
m_Reference.m_nCarouselId =
((data[off ] << 24) | (data[off + 1] << 16) |
(data[off + 2] << 8) | (data[off + 3]));
m_Reference.m_nCarouselId = COMBINE32(data, off);

off += 4;

Expand Down Expand Up @@ -525,8 +510,7 @@ int ProfileBodyFull::Process(const unsigned char *data)
{
int off = 0, ret;

data_len = ((data[off ] << 24) | (data[off + 1] << 16) |
(data[off + 2] << 8) | (data[off + 3]));
data_len = COMBINE32(data, off);
off += 4;

/* bit order */
Expand Down Expand Up @@ -563,24 +547,21 @@ int ProfileBodyFull::Process(const unsigned char *data)
int BiopIor::Process(const unsigned char *data)
{
int off = 0, ret;
type_id_len = ((data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | (data[3]));
type_id_len = COMBINE32(data, 0);
type_id = (char*) malloc(type_id_len);
off += 4;
memcpy(type_id, data + off, type_id_len);
off += type_id_len;

tagged_profiles_count = ((data[off ] << 24) | (data[off + 1] << 16) |
(data[off + 2] << 8) | (data[off + 3]));
tagged_profiles_count = COMBINE32(data, off);
if (tagged_profiles_count < 1)
{
LOG(VB_DSMCC, LOG_WARNING, "[biop] IOR missing taggedProfile");
return 0;
}
off += 4;

profile_id_tag = ((data[off ] << 24) | (data[off + 1] << 16) |
(data[off + 2] << 8) | (data[off + 3]));
profile_id_tag = COMBINE32(data, off);
off += 4;

if (profile_id_tag == 0x49534F06) // profile_id_tag == 0x49534F06
Expand Down

0 comments on commit 9f900fc

Please sign in to comment.