Parcourir la source

[2040] Compilation warnings removed.

Tomek Mrugalski il y a 12 ans
Parent
commit
96fec63888

+ 1 - 1
tests/tools/dhcp-ubench/Makefile

@@ -1,6 +1,6 @@
 MYSQL_CFLAGS=`mysql_config --cflags`
 MYSQL_LDFLAGS=`mysql_config --libs`
-CFLAGS=-g -O0
+CFLAGS=-g -O0 -Wall -pedantic -Wextra
 LDFLAGS=-lrt
 
 SQLITE_CFLAGS=`pkg-config sqlite3 --cflags` $(LDFLAGS)

+ 13 - 12
tests/tools/dhcp-ubench/memfile_ubench.cc

@@ -156,10 +156,10 @@ void memfile_uBenchmark::createLease4Test() {
     }
 
     uint32_t addr = BASE_ADDR4; // Let's start with 1.0.0.0 address
-    char hwaddr_tmp[20];
-    uint8_t hwaddr_len = 20; // not a real field
-    char client_id_tmp[128];
-    uint8_t client_id_len = 128;
+    const uint8_t hwaddr_len = 20; // not a real field
+    char hwaddr_tmp[hwaddr_len];
+    const uint8_t client_id_len = 128;
+    char client_id_tmp[client_id_len];
     uint32_t valid_lft = 1000;  // we can use the same value for all leases
     uint32_t recycle_time = 0;  // not supported in any foresable future,
                                 // so keep this as 0
@@ -172,12 +172,14 @@ void memfile_uBenchmark::createLease4Test() {
 
     printf("CREATE:   ");
 
-    for (uint8_t i = 0; i < 20; i++) {
+    // while we could put the data directly into vector, I would like to
+    // keep the code as  similar to other benchmarks as possible
+    for (uint8_t i = 0; i < hwaddr_len; i++) {
         hwaddr_tmp[i] = 65 + i;
     }
     vector<uint8_t> hwaddr(hwaddr_tmp, hwaddr_tmp+19);
 
-    for (uint8_t i = 0; i < 128; i++) {
+    for (uint8_t i = 0; i < client_id_len; i++) {
         client_id_tmp[i] = 33 + i;
     }
     vector<uint8_t> client_id(client_id_tmp, client_id_tmp+19);
@@ -191,13 +193,13 @@ void memfile_uBenchmark::createLease4Test() {
         lease->hwaddr = hwaddr;
         lease->client_id = client_id;
         lease->valid_lft = valid_lft;
-        lease->recycle_time = 0;
+        lease->recycle_time = recycle_time;
         lease->cltt = cltt;
-        lease->pool_id = 0;
-        lease->fixed = false;
+        lease->pool_id = pool_id;
+        lease->fixed = fixed;
         lease->hostname = "foo";
-        lease->fqdn_fwd = true;
-        lease->fqdn_rev = true;
+        lease->fqdn_fwd = fqdn_fwd;
+        lease->fqdn_rev = fqdn_rev;
 
         if (!LeaseMgr_->addLease(lease)) {
             failure("addLease() failed");
@@ -272,7 +274,6 @@ void memfile_uBenchmark::deleteLease4Test() {
     }
 
     printf("DELETE:   ");
-    char * errorMsg = NULL;
 
     for (uint32_t i = 0; i < Num_; i++) {
 

+ 10 - 6
tests/tools/dhcp-ubench/mysql_ubench.cc

@@ -179,7 +179,7 @@ void MySQL_uBenchmark::searchLease4Test() {
         int num_rows = mysql_num_rows(result);
         int num_fields = mysql_num_fields(result);
 
-        if ( (num_rows != 0) && (num_rows != 1) ) {
+        if ( (num_rows > 1) ) {
             stringstream tmp;
             tmp << "Search: DB returned " << num_rows << " leases for address "
                 << hex << x << dec;
@@ -187,14 +187,22 @@ void MySQL_uBenchmark::searchLease4Test() {
         }
 
         if (num_rows) {
+            if (num_fields == 0) {
+                failure("Query returned empty set");
+            }
+
             MYSQL_ROW row = mysql_fetch_row(result);
+
             // pretend to do something with it
+            if (row[0] == NULL) {
+                failure("SELECT returned NULL data.");
+            }
+            mysql_free_result(result);
 
             if (Verbose_) {
                 printf(".");
             }
 
-            mysql_free_result(result);
         } else {
             if (Verbose_) {
                 printf("x");
@@ -220,8 +228,6 @@ void MySQL_uBenchmark::updateLease4Test() {
         sprintf(query, "UPDATE lease4 SET valid_lft=1002, cltt=now() WHERE addr=%d", x);
         mysql_real_query(Conn_, query, strlen(query));
 
-        MYSQL_RES * result = NULL;
-
         if (Verbose_)
             printf(".");
     }
@@ -244,8 +250,6 @@ void MySQL_uBenchmark::deleteLease4Test() {
         sprintf(query, "DELETE FROM lease4 WHERE addr=%d", x);
         mysql_real_query(Conn_, query, strlen(query));
 
-        MYSQL_RES * result = NULL;
-
         if (Verbose_) {
             printf(".");
         }

+ 11 - 10
tests/tools/dhcp-ubench/sqlite_ubench.cc

@@ -69,10 +69,10 @@ void SQLite_uBenchmark::createLease4Test() {
     }
 
     uint32_t addr = BASE_ADDR4; // Let's start with 1.0.0.0 address
-    char hwaddr[20];
-    uint8_t hwaddr_len = 20; // not a real field
-    char client_id[128];
-    uint8_t client_id_len = 128;
+    const uint8_t hwaddr_len = 20; // not a real field
+    char hwaddr[hwaddr_len];
+    const uint8_t client_id_len = 128;
+    char client_id[client_id_len];
     uint32_t valid_lft = 1000;  // we can use the same value for all leases
     uint32_t recycle_time = 0;  // not supported in any foresable future,
                                 // so keep this as 0
@@ -85,15 +85,16 @@ void SQLite_uBenchmark::createLease4Test() {
 
     printf("CREATE:   ");
 
-    for (uint8_t i = 0; i < 20; i++) {
+    for (uint8_t i = 0; i < hwaddr_len; i++) {
         hwaddr[i] = 65 + i;
     }
     hwaddr[19] = 0; // workaround
 
-    for (uint8_t i = 0; i < 128; i++) {
+    for (uint8_t i = 0; i < client_id_len; i++) {
         client_id[i] = 33 + i;
     }
-    client_id[6] = 'X';
+    client_id[6] = 'X'; // there's apostrophe here. It would confuse
+                        // query formatting, let's get rid of it
     client_id[127] = 0; // workaround
 
     for (uint32_t i = 0; i < Num_; i++) {
@@ -105,7 +106,7 @@ void SQLite_uBenchmark::createLease4Test() {
         char * errorMsg = NULL;
 
         // the first address is 1.0.0.0.
-        char query[2000], * end;
+        char query[2000];
         /// @todo: Encode HWADDR and CLIENT-ID properly
         sprintf(query, "INSERT INTO lease4(addr,hwaddr,client_id,"
                "valid_lft,recycle_time,cltt,pool_id,fixed,hostname,"
@@ -131,7 +132,8 @@ void SQLite_uBenchmark::createLease4Test() {
     printf("\n");
 }
 
-static int search_callback(void *counter, int argc, char **argv, char **azColName){
+static int search_callback(void *counter, int /*argc*/, char **/*argv*/, 
+                           char **/*azColName*/){
 
     int * cnt = static_cast<int*>(counter);
     (*cnt)++;
@@ -225,7 +227,6 @@ void SQLite_uBenchmark::deleteLease4Test() {
     }
 
     printf("DELETE:   ");
-    char * errorMsg = NULL;
 
     for (uint32_t i = 0; i < Num_; i++) {