Fixed gcc-4.7 building problem for update_engine (again).
TEST=Built using gcc-4.7 for lumpy.
BUG=None
Change-Id: Ic5dc527044d75549d7a125c64990bbee4d2dfa21
Reviewed-on: https://gerrit.chromium.org/gerrit/26138
Reviewed-by: Yunlian Jiang <yunlian@chromium.org>
Commit-Ready: Han Shen <shenhan@chromium.org>
Tested-by: Han Shen <shenhan@chromium.org>
diff --git a/SConstruct b/SConstruct
index fd3fa18..43d4392 100644
--- a/SConstruct
+++ b/SConstruct
@@ -184,6 +184,7 @@
-Wignored-qualifiers
-Wignored-qualifiers
-Wmissing-field-initializers
+ -Wno-format
-Wsign-compare
-Wtype-limits
-Wtype-limits
diff --git a/omaha_hash_calculator.h b/omaha_hash_calculator.h
index 9735ac8..784326a 100644
--- a/omaha_hash_calculator.h
+++ b/omaha_hash_calculator.h
@@ -6,6 +6,7 @@
#define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__
#include <string>
+#include <unistd.h>
#include <vector>
#include <openssl/sha.h>
diff --git a/omaha_hash_calculator_unittest.cc b/omaha_hash_calculator_unittest.cc
index b6e03a4..5147806 100644
--- a/omaha_hash_calculator_unittest.cc
+++ b/omaha_hash_calculator_unittest.cc
@@ -20,41 +20,48 @@
namespace chromeos_update_engine {
-class OmahaHashCalculatorTest : public ::testing::Test { };
-
// Generated by running this on a linux shell:
// $ echo -n hi | openssl dgst -sha256 -binary | openssl base64
static const char kExpectedHash[] =
"j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ=";
-static const char kExpectedRawHash[] = {
+static const unsigned char kRawExpectedRawHash[] = {
0x8f, 0x43, 0x43, 0x46, 0x64, 0x8f, 0x6b, 0x96,
0xdf, 0x89, 0xdd, 0xa9, 0x01, 0xc5, 0x17, 0x6b,
0x10, 0xa6, 0xd8, 0x39, 0x61, 0xdd, 0x3c, 0x1a,
0xc8, 0x8b, 0x59, 0xb2, 0xdc, 0x32, 0x7a, 0xa4
};
-TEST(OmahaHashCalculatorTest, SimpleTest) {
+class OmahaHashCalculatorTest : public ::testing::Test {
+public:
+ const char *kExpectedRawHash;
+ const char *kExpectedRawHashEnd;
+
+ OmahaHashCalculatorTest() :
+ kExpectedRawHash(reinterpret_cast<const char*>(kRawExpectedRawHash)),
+ kExpectedRawHashEnd(kExpectedRawHash + arraysize(kRawExpectedRawHash))
+ {}
+};
+
+TEST_F(OmahaHashCalculatorTest, SimpleTest) {
OmahaHashCalculator calc;
calc.Update("hi", 2);
calc.Finalize();
EXPECT_EQ(kExpectedHash, calc.hash());
- vector<char> raw_hash(kExpectedRawHash,
- kExpectedRawHash + arraysize(kExpectedRawHash));
+ vector<char> raw_hash(kExpectedRawHash, kExpectedRawHashEnd);
EXPECT_TRUE(raw_hash == calc.raw_hash());
}
-TEST(OmahaHashCalculatorTest, MultiUpdateTest) {
+TEST_F(OmahaHashCalculatorTest, MultiUpdateTest) {
OmahaHashCalculator calc;
calc.Update("h", 1);
calc.Update("i", 1);
calc.Finalize();
EXPECT_EQ(kExpectedHash, calc.hash());
- vector<char> raw_hash(kExpectedRawHash,
- kExpectedRawHash + arraysize(kExpectedRawHash));
+ vector<char> raw_hash(kExpectedRawHash, kExpectedRawHashEnd);
EXPECT_TRUE(raw_hash == calc.raw_hash());
}
-TEST(OmahaHashCalculatorTest, ContextTest) {
+TEST_F(OmahaHashCalculatorTest, ContextTest) {
OmahaHashCalculator calc;
calc.Update("h", 1);
string calc_context = calc.GetContext();
@@ -64,12 +71,11 @@
calc_next.Update("i", 1);
calc_next.Finalize();
EXPECT_EQ(kExpectedHash, calc_next.hash());
- vector<char> raw_hash(kExpectedRawHash,
- kExpectedRawHash + arraysize(kExpectedRawHash));
+ vector<char> raw_hash(kExpectedRawHash, kExpectedRawHashEnd);
EXPECT_TRUE(raw_hash == calc_next.raw_hash());
}
-TEST(OmahaHashCalculatorTest, BigTest) {
+TEST_F(OmahaHashCalculatorTest, BigTest) {
OmahaHashCalculator calc;
int digit_count = 1;
@@ -94,7 +100,7 @@
EXPECT_EQ("NZf8k6SPBkYMvhaX8YgzuMgbkLP1XZ+neM8K5wcSsf8=", calc.hash());
}
-TEST(OmahaHashCalculatorTest, UpdateFileSimpleTest) {
+TEST_F(OmahaHashCalculatorTest, UpdateFileSimpleTest) {
string data_path;
ASSERT_TRUE(
utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL));
@@ -107,8 +113,7 @@
EXPECT_EQ(2, calc.UpdateFile(data_path, kLengths[i]));
EXPECT_TRUE(calc.Finalize());
EXPECT_EQ(kExpectedHash, calc.hash());
- vector<char> raw_hash(kExpectedRawHash,
- kExpectedRawHash + arraysize(kExpectedRawHash));
+ vector<char> raw_hash(kExpectedRawHash, kExpectedRawHashEnd);
EXPECT_TRUE(raw_hash == calc.raw_hash());
}
@@ -120,7 +125,7 @@
EXPECT_EQ("qqlAJmTxpB9A67xSyZk+tmrrNmYClY/fqig7ceZNsSM=", calc.hash());
}
-TEST(OmahaHashCalculatorTest, RawHashOfFileSimpleTest) {
+TEST_F(OmahaHashCalculatorTest, RawHashOfFileSimpleTest) {
string data_path;
ASSERT_TRUE(
utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL));
@@ -129,8 +134,7 @@
static const int kLengths[] = { -1, 2, 10 };
for (size_t i = 0; i < arraysize(kLengths); i++) {
- vector<char> exp_raw_hash(kExpectedRawHash,
- kExpectedRawHash + arraysize(kExpectedRawHash));
+ vector<char> exp_raw_hash(kExpectedRawHash, kExpectedRawHashEnd);
vector<char> raw_hash;
EXPECT_EQ(2, OmahaHashCalculator::RawHashOfFile(data_path,
kLengths[i],
@@ -139,12 +143,12 @@
}
}
-TEST(OmahaHashCalculatorTest, UpdateFileNonexistentTest) {
+TEST_F(OmahaHashCalculatorTest, UpdateFileNonexistentTest) {
OmahaHashCalculator calc;
EXPECT_EQ(-1, calc.UpdateFile("/some/non-existent/file", -1));
}
-TEST(OmahaHashCalculatorTest, AbortTest) {
+TEST_F(OmahaHashCalculatorTest, AbortTest) {
// Just make sure we don't crash and valgrind doesn't detect memory leaks
{
OmahaHashCalculator calc;
diff --git a/payload_signer.cc b/payload_signer.cc
index 0feb1b6..88188a2 100644
--- a/payload_signer.cc
+++ b/payload_signer.cc
@@ -26,7 +26,7 @@
namespace {
-const char kRSA2048SHA256Padding[] = {
+const unsigned char kRSA2048SHA256Padding[] = {
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -362,8 +362,9 @@
bool PayloadSigner::PadRSA2048SHA256Hash(std::vector<char>* hash) {
TEST_AND_RETURN_FALSE(hash->size() == 32);
hash->insert(hash->begin(),
- kRSA2048SHA256Padding,
- kRSA2048SHA256Padding + sizeof(kRSA2048SHA256Padding));
+ reinterpret_cast<const char*>(kRSA2048SHA256Padding),
+ reinterpret_cast<const char*>(kRSA2048SHA256Padding +
+ sizeof(kRSA2048SHA256Padding)));
TEST_AND_RETURN_FALSE(hash->size() == 256);
return true;
}
diff --git a/payload_signer_unittest.cc b/payload_signer_unittest.cc
index 0a5a883..972bf2d 100644
--- a/payload_signer_unittest.cc
+++ b/payload_signer_unittest.cc
@@ -30,7 +30,7 @@
// Generated by:
// echo -n 'This is some data to sign.' | openssl dgst -sha256 -binary |
// hexdump -v -e '" " 8/1 "0x%02x, " "\n"'
-const char kDataHash[] = {
+const unsigned char kDataHash[] = {
0x7a, 0x07, 0xa6, 0x44, 0x08, 0x86, 0x20, 0xa6,
0xc1, 0xf8, 0xd9, 0x02, 0x05, 0x63, 0x0d, 0xb7,
0xfc, 0x2b, 0xa0, 0xa9, 0x7c, 0x9d, 0x1d, 0x8c,
@@ -42,7 +42,7 @@
// echo -n 'This is some data to sign.' | openssl dgst -sha256 -binary |
// ~/local/bin/openssl pkeyutl -sign -inkey unittest_key.pem -pkeyopt
// digest:sha256 | hexdump -v -e '" " 8/1 "0x%02x, " "\n"'
-const char kDataSignature[] = {
+const unsigned char kDataSignature[] = {
0x9f, 0x86, 0x25, 0x8b, 0xf3, 0xcc, 0xe3, 0x95,
0x5f, 0x45, 0x83, 0xb2, 0x66, 0xf0, 0x2a, 0xcf,
0xb7, 0xaa, 0x52, 0x25, 0x7a, 0xdd, 0x9d, 0x65,
@@ -115,7 +115,7 @@
const string sig_data = signature.data();
ASSERT_EQ(arraysize(kDataSignature), sig_data.size());
for (size_t i = 0; i < arraysize(kDataSignature); i++) {
- EXPECT_EQ(kDataSignature[i], sig_data[i]);
+ EXPECT_EQ(static_cast<char>(kDataSignature[i]), sig_data[i]);
}
}
@@ -127,7 +127,9 @@
EXPECT_TRUE(PayloadSigner::VerifySignature(signature_blob,
kUnittestPublicKeyPath,
&hash_data));
- vector<char> padded_hash_data(kDataHash, kDataHash + sizeof(kDataHash));
+ vector<char> padded_hash_data(reinterpret_cast<const char *>(kDataHash),
+ reinterpret_cast<const char *>(kDataHash +
+ sizeof(kDataHash)));
PayloadSigner::PadRSA2048SHA256Hash(&padded_hash_data);
ASSERT_EQ(padded_hash_data.size(), hash_data.size());
for (size_t i = 0; i < padded_hash_data.size(); i++) {
diff --git a/test_utils.cc b/test_utils.cc
index 6e5ec44..40d300c 100644
--- a/test_utils.cc
+++ b/test_utils.cc
@@ -66,7 +66,7 @@
vector<char> GenerateSampleMbr() {
// This is the actual MBR from my dev machine. Partition 1 (the first)
// is currently marked bootable
- char mbr[512] = {
+ unsigned char mbr[512] = {
0xeb, 0x48, 0x90, 0x10, 0x8e, 0xd0, 0xbc, 0x00,
0xb0, 0xb8, 0x00, 0x00, 0x8e, 0xd8, 0x8e, 0xc0,
0xfb, 0xbe, 0x00, 0x7c, 0xbf, 0x00, 0x06, 0xb9,
@@ -133,7 +133,8 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
};
vector<char> ret;
- ret.insert(ret.begin(), mbr, mbr + sizeof(mbr));
+ ret.insert(ret.begin(), reinterpret_cast<char *>(mbr),
+ reinterpret_cast<char *>(mbr + sizeof(mbr)));
return ret;
}
diff --git a/utils.h b/utils.h
index 628602f..67e8062 100644
--- a/utils.h
+++ b/utils.h
@@ -5,11 +5,11 @@
#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__
#define CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__
-#include <errno.h>
-
#include <algorithm>
+#include <errno.h>
#include <set>
#include <string>
+#include <unistd.h>
#include <vector>
#include <base/eintr_wrapper.h>