Skip to content

Commit

Permalink
Changes to eliminate compiler warnings on MSVC
Browse files Browse the repository at this point in the history
This code was not compiling under Visual Studio 2013 with warnings being treated
as errors. Specifically:

1. Changed int -> size_t to eliminate signed/unsigned mismatch warning.
2. Added some missing return values to functions.
3. Inserting character instead of integer literals into strings to avoid type
   conversions.

A=cmumford
R=jeff
  • Loading branch information
sesse committed Jun 22, 2015
1 parent e7a897e commit b2ad960
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions snappy_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ static size_t MinimumRequiredOutputSpace(size_t input_size,

default:
LOG(FATAL) << "Unknown compression type number " << comp;
return 0;
}
}

Expand Down Expand Up @@ -445,7 +446,7 @@ static void Measure(const char* data,
}

compressed_size = 0;
for (int i = 0; i < compressed.size(); i++) {
for (size_t i = 0; i < compressed.size(); i++) {
compressed_size += compressed[i].size();
}
}
Expand Down Expand Up @@ -501,13 +502,13 @@ static void VerifyIOVec(const string& input) {
// ranging from 1 to 10.
char* buf = new char[input.size()];
ACMRandom rnd(input.size());
int num = rnd.Next() % 10 + 1;
size_t num = rnd.Next() % 10 + 1;
if (input.size() < num) {
num = input.size();
}
struct iovec* iov = new iovec[num];
int used_so_far = 0;
for (int i = 0; i < num; ++i) {
for (size_t i = 0; i < num; ++i) {
iov[i].iov_base = buf + used_so_far;
if (i == num - 1) {
iov[i].iov_len = input.size() - used_so_far;
Expand Down Expand Up @@ -617,7 +618,7 @@ TEST(CorruptedTest, VerifyCorrupted) {
// This is testing for a security bug - a buffer that decompresses to 100k
// but we lie in the snappy header and only reserve 0 bytes of memory :)
source.resize(100000);
for (int i = 0; i < source.length(); ++i) {
for (size_t i = 0; i < source.length(); ++i) {
source[i] = 'A';
}
snappy::Compress(source.data(), source.size(), &dest);
Expand All @@ -632,7 +633,7 @@ TEST(CorruptedTest, VerifyCorrupted) {
// where 3 GB might be an acceptable allocation size, Uncompress()
// attempts to decompress, and sometimes causes the test to run out of
// memory.
dest[0] = dest[1] = dest[2] = dest[3] = 0xff;
dest[0] = dest[1] = dest[2] = dest[3] = '\xff';
// This decodes to a really large size, i.e., about 3 GB.
dest[4] = 'k';
CHECK(!IsValidCompressedBuffer(dest));
Expand All @@ -642,7 +643,7 @@ TEST(CorruptedTest, VerifyCorrupted) {
}

// This decodes to about 2 MB; much smaller, but should still fail.
dest[0] = dest[1] = dest[2] = 0xff;
dest[0] = dest[1] = dest[2] = '\xff';
dest[3] = 0x00;
CHECK(!IsValidCompressedBuffer(dest));
CHECK(!Uncompress(dest, &uncmp));
Expand Down Expand Up @@ -759,7 +760,7 @@ TEST(Snappy, RandomData) {
}

string x;
int len = rnd.Uniform(4096);
size_t len = rnd.Uniform(4096);
if (i < 100) {
len = 65536 + rnd.Uniform(65536);
}
Expand Down Expand Up @@ -950,11 +951,11 @@ TEST(SnappyCorruption, TruncatedVarint) {
TEST(SnappyCorruption, UnterminatedVarint) {
string compressed, uncompressed;
size_t ulength;
compressed.push_back(128);
compressed.push_back(128);
compressed.push_back(128);
compressed.push_back(128);
compressed.push_back(128);
compressed.push_back('\x80');
compressed.push_back('\x80');
compressed.push_back('\x80');
compressed.push_back('\x80');
compressed.push_back('\x80');
compressed.push_back(10);
CHECK(!CheckUncompressedLength(compressed, &ulength));
CHECK(!snappy::IsValidCompressedBuffer(compressed.data(), compressed.size()));
Expand Down

0 comments on commit b2ad960

Please sign in to comment.