Commit 4e3ae148 authored by wtc's avatar wtc Committed by Commit bot

Apply sizeof to variables instead of types.

Replace hardcoded variable sizes with sizeof.

R=eroman@chromium.org
BUG=none

Review URL: https://codereview.chromium.org/1170493002

Cr-Commit-Position: refs/heads/master@{#333117}
parent 22716c3b
...@@ -112,11 +112,12 @@ static bool DecompressZlib(uint8_t* out, int out_len, base::StringPiece in) { ...@@ -112,11 +112,12 @@ static bool DecompressZlib(uint8_t* out, int out_len, base::StringPiece in) {
// updates |data| to remove the header on return. Caller takes ownership of the // updates |data| to remove the header on return. Caller takes ownership of the
// returned pointer. // returned pointer.
static base::DictionaryValue* ReadHeader(base::StringPiece* data) { static base::DictionaryValue* ReadHeader(base::StringPiece* data) {
if (data->size() < 2)
return NULL;
uint16_t header_len; uint16_t header_len;
memcpy(&header_len, data->data(), 2); // Assumes little-endian. if (data->size() < sizeof(header_len))
data->remove_prefix(2); return NULL;
// Assumes little-endian.
memcpy(&header_len, data->data(), sizeof(header_len));
data->remove_prefix(sizeof(header_len));
if (data->size() < header_len) if (data->size() < header_len)
return NULL; return NULL;
...@@ -145,16 +146,17 @@ static bool ReadCRL(base::StringPiece* data, std::string* out_parent_spki_hash, ...@@ -145,16 +146,17 @@ static bool ReadCRL(base::StringPiece* data, std::string* out_parent_spki_hash,
out_parent_spki_hash->assign(data->data(), crypto::kSHA256Length); out_parent_spki_hash->assign(data->data(), crypto::kSHA256Length);
data->remove_prefix(crypto::kSHA256Length); data->remove_prefix(crypto::kSHA256Length);
if (data->size() < sizeof(uint32_t))
return false;
uint32_t num_serials; uint32_t num_serials;
if (data->size() < sizeof(num_serials))
return false;
// Assumes little endian. // Assumes little endian.
memcpy(&num_serials, data->data(), sizeof(uint32_t)); memcpy(&num_serials, data->data(), sizeof(num_serials));
data->remove_prefix(sizeof(num_serials));
if (num_serials > 32 * 1024 * 1024) // Sanity check. if (num_serials > 32 * 1024 * 1024) // Sanity check.
return false; return false;
out_serials->reserve(num_serials); out_serials->reserve(num_serials);
data->remove_prefix(sizeof(uint32_t));
for (uint32_t i = 0; i < num_serials; ++i) { for (uint32_t i = 0; i < num_serials; ++i) {
if (data->size() < sizeof(uint8_t)) if (data->size() < sizeof(uint8_t))
...@@ -214,13 +216,13 @@ static const unsigned kMaxUncompressedChangesLength = 1024 * 1024; ...@@ -214,13 +216,13 @@ static const unsigned kMaxUncompressedChangesLength = 1024 * 1024;
static bool ReadChanges(base::StringPiece* data, static bool ReadChanges(base::StringPiece* data,
std::vector<uint8_t>* out_changes) { std::vector<uint8_t>* out_changes) {
uint32_t uncompressed_size, compressed_size; uint32_t uncompressed_size, compressed_size;
if (data->size() < 2 * sizeof(uint32_t)) if (data->size() < sizeof(uncompressed_size) + sizeof(compressed_size))
return false; return false;
// Assumes little endian. // Assumes little endian.
memcpy(&uncompressed_size, data->data(), sizeof(uint32_t)); memcpy(&uncompressed_size, data->data(), sizeof(uncompressed_size));
data->remove_prefix(4); data->remove_prefix(sizeof(uncompressed_size));
memcpy(&compressed_size, data->data(), sizeof(uint32_t)); memcpy(&compressed_size, data->data(), sizeof(compressed_size));
data->remove_prefix(4); data->remove_prefix(sizeof(compressed_size));
if (uncompressed_size > kMaxUncompressedChangesLength) if (uncompressed_size > kMaxUncompressedChangesLength)
return false; return false;
...@@ -261,10 +263,9 @@ static bool ReadDeltaCRL(base::StringPiece* data, ...@@ -261,10 +263,9 @@ static bool ReadDeltaCRL(base::StringPiece* data,
out_serials->push_back(old_serials[i]); out_serials->push_back(old_serials[i]);
i++; i++;
} else if (*k == SYMBOL_INSERT) { } else if (*k == SYMBOL_INSERT) {
uint8_t serial_length;
if (data->size() < sizeof(uint8_t)) if (data->size() < sizeof(uint8_t))
return false; return false;
memcpy(&serial_length, data->data(), sizeof(uint8_t)); uint8_t serial_length = data->data()[0];
data->remove_prefix(sizeof(uint8_t)); data->remove_prefix(sizeof(uint8_t));
if (data->size() < serial_length) if (data->size() < serial_length)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment