summaryrefslogtreecommitdiff
path: root/osi
diff options
context:
space:
mode:
authorPavlin Radoslavov <pavlin@google.com>2016-02-13 08:47:19 -0800
committerAndre Eisenbach <eisenbach@google.com>2016-02-18 10:39:27 -0800
commit12265e39b511f28425236b0dc97c78e7d837304b (patch)
tree41f7c3bf1498bde26e98b859f556f9261b0b722f /osi
parent0bd8fa5b24103f5376afb4ddd593ecb1a6a2588c (diff)
downloadandroid-system-bt-12265e39b511f28425236b0dc97c78e7d837304b.tar.gz
android-system-bt-12265e39b511f28425236b0dc97c78e7d837304b.tar.xz
Fix C/C++ compiler generated warnings
* Remove unused functions: -Wno-unused-function * Fix logical operations that are missing parentheses: -Wno-logical-not-parentheses, -Wno-parentheses * Add missing braces in initializers: -Wno-missing-braces * Remove unused variables: -Wno-unused-variable * Fix printf()-like formatting issues: -Wno-format * Avoid using unitialized variables: -Wno-maybe-uninitialized, -Wno-uninitialized * Fix a bug inside bta_gattc_get_gatt_db_impl() when the processed GATT DB attribute type is unknown. * Fix warnings about missing field initializers: -Wno-missing-field-initializers * Re-implement macro COMPILE_ASSERT(COND) to fix a compilation warning: -Wno-non-literal-null-conversion * Fix sign mismatch comparison warnings: -Wno-sign-compare * Fix warnings related to enum conversion: -Wno-enum-conversion * Fix warnings related to incompatible pointer types: -Wno-incompatible-pointer-types * Fix warnings related to enum conversion: -Wno-enum-conversion Bug: 26879229 Change-Id: I522931fe156aeab23ae841051a9e25ceab00b1c2
Diffstat (limited to 'osi')
-rw-r--r--osi/include/osi.h2
-rw-r--r--osi/test/list_test.cpp4
-rw-r--r--osi/test/ringbuffer_test.cpp76
3 files changed, 41 insertions, 41 deletions
diff --git a/osi/include/osi.h b/osi/include/osi.h
index 78aa68c..d2cc0a3 100644
--- a/osi/include/osi.h
+++ b/osi/include/osi.h
@@ -22,7 +22,7 @@
// C++ code that includes base and osi/include/osi.h can thus easily default to
// the definition from libbase but we should check here to avoid compile errors.
#ifndef COMPILE_ASSERT
-#define COMPILE_ASSERT(x) char * DUMMY_PTR = !(x)
+#define COMPILE_ASSERT(COND) typedef int failed_compile_assert[(COND) ? 1 : -1] __attribute__ ((unused))
#endif // COMPILE_ASSERT
// Macros for safe integer to pointer conversion. In the C language, data is
diff --git a/osi/test/list_test.cpp b/osi/test/list_test.cpp
index fcb6590..b7d8ae8 100644
--- a/osi/test/list_test.cpp
+++ b/osi/test/list_test.cpp
@@ -169,7 +169,7 @@ TEST_F(ListTest, test_list_foreach_full) {
int x[] = { 1, 2, 3, 4, 5 };
for (size_t i = 0; i < ARRAY_SIZE(x); ++i)
list_append(list, &x[i]);
- EXPECT_EQ(list_length(list), 5);
+ EXPECT_EQ(list_length(list), (size_t)5);
// Test complete iteration
int sum = 0;
@@ -187,7 +187,7 @@ TEST_F(ListTest, test_list_foreach_partial) {
int x[] = { 1, 2, 3, 4, 5 };
for (size_t i = 0; i < ARRAY_SIZE(x); ++i)
list_append(list, &x[i]);
- EXPECT_EQ(list_length(list), 5);
+ EXPECT_EQ(list_length(list), (size_t)5);
// Test partial iteration
int find = 4;
diff --git a/osi/test/ringbuffer_test.cpp b/osi/test/ringbuffer_test.cpp
index 88ff64c..af007ac 100644
--- a/osi/test/ringbuffer_test.cpp
+++ b/osi/test/ringbuffer_test.cpp
@@ -8,8 +8,8 @@ extern "C" {
TEST(RingbufferTest, test_new_simple) {
ringbuffer_t *rb = ringbuffer_init(4096);
ASSERT_TRUE(rb != NULL);
- EXPECT_EQ(4096, ringbuffer_available(rb));
- EXPECT_EQ(0, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)4096, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)0, ringbuffer_size(rb));
ringbuffer_free(rb);
}
@@ -18,14 +18,14 @@ TEST(RingbufferTest, test_insert_basic) {
uint8_t buffer[10] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A};
ringbuffer_insert(rb, buffer, 10);
- EXPECT_EQ(10, ringbuffer_size(rb));
- EXPECT_EQ(6, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)10, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)6, ringbuffer_available(rb));
uint8_t peek[10] = {0};
size_t peeked = ringbuffer_peek(rb, peek, 10);
- EXPECT_EQ(10, ringbuffer_size(rb)); // Ensure size doesn't change
- EXPECT_EQ(6, ringbuffer_available(rb));
- EXPECT_EQ(10, peeked);
+ EXPECT_EQ((size_t)10, ringbuffer_size(rb)); // Ensure size doesn't change
+ EXPECT_EQ((size_t)6, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)10, peeked);
ASSERT_TRUE(0 == memcmp(buffer, peek, peeked));
ringbuffer_free(rb);
@@ -39,19 +39,19 @@ TEST(RingbufferTest, test_insert_full) {
uint8_t peek[5] = {0};
size_t added = ringbuffer_insert(rb, aa, 7);
- EXPECT_EQ(5, added);
- EXPECT_EQ(0, ringbuffer_available(rb));
- EXPECT_EQ(5, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)5, added);
+ EXPECT_EQ((size_t)0, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)5, ringbuffer_size(rb));
added = ringbuffer_insert(rb, bb, 5);
- EXPECT_EQ(0, added);
- EXPECT_EQ(0, ringbuffer_available(rb));
- EXPECT_EQ(5, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)0, added);
+ EXPECT_EQ((size_t)0, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)5, ringbuffer_size(rb));
size_t peeked = ringbuffer_peek(rb, peek, 5);
- EXPECT_EQ(5, peeked);
- EXPECT_EQ(0, ringbuffer_available(rb));
- EXPECT_EQ(5, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)5, peeked);
+ EXPECT_EQ((size_t)0, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)5, ringbuffer_size(rb));
ASSERT_TRUE(0 == memcmp(aa, peek, peeked));
@@ -60,79 +60,79 @@ TEST(RingbufferTest, test_insert_full) {
TEST(RingbufferTest, test_multi_insert_delete) {
ringbuffer_t *rb = ringbuffer_init(16);
- EXPECT_EQ(16, ringbuffer_available(rb));
- EXPECT_EQ(0, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)16, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)0, ringbuffer_size(rb));
// Insert some bytes
uint8_t aa[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
size_t added = ringbuffer_insert(rb, aa, sizeof(aa));
- EXPECT_EQ(8, added);
- EXPECT_EQ(8, ringbuffer_available(rb));
- EXPECT_EQ(8, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)8, added);
+ EXPECT_EQ((size_t)8, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)8, ringbuffer_size(rb));
uint8_t bb[] = {0xBB, 0xBB, 0xBB, 0xBB, 0xBB};
ringbuffer_insert(rb, bb, sizeof(bb));
- EXPECT_EQ(3, ringbuffer_available(rb));
- EXPECT_EQ(13, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)3, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)13, ringbuffer_size(rb));
uint8_t content[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB};
uint8_t peek[16] = {0};
size_t peeked = ringbuffer_peek(rb, peek, 16);
- EXPECT_EQ(13, peeked);
+ EXPECT_EQ((size_t)13, peeked);
ASSERT_TRUE(0 == memcmp(content, peek, peeked));
// Delete some bytes
ringbuffer_delete(rb, sizeof(aa));
- EXPECT_EQ(11, ringbuffer_available(rb));
- EXPECT_EQ(5, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)11, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)5, ringbuffer_size(rb));
// Add some more to wrap buffer
uint8_t cc[] = {0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC};
ringbuffer_insert(rb, cc, sizeof(cc));
- EXPECT_EQ(2, ringbuffer_available(rb));
- EXPECT_EQ(14, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)2, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)14, ringbuffer_size(rb));
uint8_t content2[] = {0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xCC, 0xCC};
peeked = ringbuffer_peek(rb, peek, 7);
- EXPECT_EQ(7, peeked);
+ EXPECT_EQ((size_t)7, peeked);
ASSERT_TRUE(0 == memcmp(content2, peek, peeked));
// Pop buffer
memset(peek, 0, 16);
size_t popped = ringbuffer_pop(rb, peek, 7);
- EXPECT_EQ(7, popped);
- EXPECT_EQ(9, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)7, popped);
+ EXPECT_EQ((size_t)9, ringbuffer_available(rb));
ASSERT_TRUE(0 == memcmp(content2, peek, peeked));
// Add more again to check head motion
uint8_t dd[] = { 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD };
added = ringbuffer_insert(rb, dd, sizeof(dd));
- EXPECT_EQ(8, added);
- EXPECT_EQ(1, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)8, added);
+ EXPECT_EQ((size_t)1, ringbuffer_available(rb));
// Delete everything
ringbuffer_delete(rb, 16);
- EXPECT_EQ(16, ringbuffer_available(rb));
- EXPECT_EQ(0, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)16, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)0, ringbuffer_size(rb));
// Add small token
uint8_t ae[] = { 0xAE, 0xAE, 0xAE };
added = ringbuffer_insert(rb, ae, sizeof(ae));
- EXPECT_EQ(13, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)13, ringbuffer_available(rb));
// Get everything
popped = ringbuffer_pop(rb, peek, 16);
EXPECT_EQ(added, popped);
- EXPECT_EQ(16, ringbuffer_available(rb));
- EXPECT_EQ(0, ringbuffer_size(rb));
+ EXPECT_EQ((size_t)16, ringbuffer_available(rb));
+ EXPECT_EQ((size_t)0, ringbuffer_size(rb));
ASSERT_TRUE(0 == memcmp(ae, peek, popped));
ringbuffer_free(rb);