fix a few signedness warnings

This commit is contained in:
Frédéric Mangano-Tarumi 2018-11-11 10:30:48 -05:00
parent 51a3eba093
commit bf386899ae
3 changed files with 14 additions and 10 deletions

View File

@ -36,38 +36,41 @@
ot::status ot::parse_tags(const char *data, long len, opus_tags *tags)
{
long pos;
if (8 > len)
if (len < 0)
return status::int_overflow;
size_t size = static_cast<size_t>(len);
size_t pos = 0;
if (8 > size)
return status::overflowing_magic_number;
if (memcmp(data, "OpusTags", 8) != 0)
return status::bad_magic_number;
// Vendor
pos = 8;
if (pos + 4 > len)
if (pos + 4 > size)
return status::overflowing_vendor_length;
size_t vendor_length = le32toh(*((uint32_t*) (data + pos)));
if (pos + 4 + vendor_length > len)
if (pos + 4 + vendor_length > size)
return status::overflowing_vendor_data;
tags->vendor = std::string(data + pos + 4, vendor_length);
pos += 4 + tags->vendor.size();
// Count
if (pos + 4 > len)
if (pos + 4 > size)
return status::overflowing_comment_count;
uint32_t count = le32toh(*((uint32_t*) (data + pos)));
pos += 4;
// Comments
for (uint32_t i = 0; i < count; ++i) {
if (pos + 4 > len)
if (pos + 4 > size)
return status::overflowing_comment_length;
uint32_t comment_length = le32toh(*((uint32_t*) (data + pos)));
if (pos + 4 + comment_length > len)
if (pos + 4 + comment_length > size)
return status::overflowing_comment_data;
const char *comment_value = data + pos + 4;
tags->comments.emplace_back(comment_value, comment_length);
pos += 4 + comment_length;
}
// Extra data
tags->extra_data = std::string(data + pos, static_cast<size_t>(len - pos));
tags->extra_data = std::string(data + pos, size - pos);
return status::ok;
}

View File

@ -24,6 +24,7 @@ namespace ot {
*/
enum class status {
ok,
int_overflow,
/** On standard error, errno will give more details. */
standard_error,
end_of_file,

View File

@ -147,9 +147,9 @@ static bool recode_padding()
ogg_packet packet;
if (ot::render_tags(&tags, &packet) != 0)
throw failure("ot::render_tags did not return 0");
if (packet.bytes < padded_OpusTags.size())
if (static_cast<size_t>(packet.bytes) < padded_OpusTags.size())
throw failure("the packet was truncated");
if (packet.bytes > padded_OpusTags.size())
if (static_cast<size_t>(packet.bytes) > padded_OpusTags.size())
throw failure("the packet got too big");
if (memcmp(packet.packet, padded_OpusTags.data(), packet.bytes) != 0)
throw failure("the rendered packet is not what we expected");