From df3eeb1a9be519b5eaef18b8f7c2d7a201bf7b97 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周日, 04 10月 2015 19:53:07 +0800
Subject: [PATCH] Fix clang warnings, add clang to travis

---
 libscpi/src/parser.c           |    7 ++-
 libscpi/src/units.c            |    4 ++
 libscpi/test/test_scpi_utils.c |   64 +++++++++++++++----------------
 .travis.yml                    |    3 +
 libscpi/test/test_parser.c     |    7 +++
 5 files changed, 49 insertions(+), 36 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 19a823a..dc5d9dc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,9 +2,10 @@
   apt:
     packages:
     - libcunit1-dev
+    - clang
 
 sudo: false
 
 script:
     - make
-    - CFLAGS="-g -O0 -fsanitize=address" LDFLAGS="-g -fsanitize=address" make clean test
+    - CC=clang CFLAGS="-g -O0 -fsanitize=address" LDFLAGS="-g -fsanitize=address" make clean test
diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 9032c9c..ca711eb 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -553,8 +553,9 @@
             } else {
                 return strToULong(parameter->ptr, (uint32_t *)value, 10) > 0 ? TRUE : FALSE;
             }
+        default:
+            return FALSE;
     }
-    return FALSE;
 }
 
 
@@ -589,7 +590,7 @@
  */
 #include "stdio.h"
 scpi_bool_t SCPI_ParamToDouble(scpi_t * context, scpi_parameter_t * parameter, double * value) {
-    scpi_bool_t result = FALSE;
+    scpi_bool_t result;
     uint32_t valint;
 
     if (!value) {
@@ -608,6 +609,8 @@
         case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX:
             result = strToDouble(parameter->ptr, value) > 0 ? TRUE : FALSE;
             break;
+        default:
+            result = FALSE;
     }
     return result;
 }
diff --git a/libscpi/src/units.c b/libscpi/src/units.c
index 517bb1a..acf44fa 100644
--- a/libscpi/src/units.c
+++ b/libscpi/src/units.c
@@ -234,6 +234,8 @@
             value->special = FALSE;
             result = TRUE;
             break;
+        default:
+            break;
     }
 
     switch(param.type) {
@@ -251,6 +253,8 @@
         case SCPI_TOKEN_OCTNUM:
             value->base = 8;
             break;
+        default:
+            break;
     }
 
     switch(param.type) {
diff --git a/libscpi/test/test_parser.c b/libscpi/test/test_parser.c
index 7eb9845..cbef1af 100644
--- a/libscpi/test/test_parser.c
+++ b/libscpi/test/test_parser.c
@@ -95,6 +95,7 @@
     memcpy(output_buffer + output_buffer_pos, data, len);
     output_buffer_pos += len;
     output_buffer[output_buffer_pos] = '\0';
+    return len;
 }
 
 scpi_t scpi_context;
@@ -120,6 +121,8 @@
 }
 
 static scpi_result_t SCPI_Flush(scpi_t * context) {
+    (void) context;
+
     return SCPI_RES_OK;
 }
 
@@ -133,6 +136,8 @@
 
 scpi_reg_val_t srq_val = 0;
 static scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) {
+    (void) context;
+
     if (SCPI_CTRL_SRQ == ctrl) {
         srq_val = val;
     } else {
@@ -144,6 +149,8 @@
 scpi_bool_t RST_executed = FALSE;
 
 static scpi_result_t SCPI_Reset(scpi_t * context) {
+    (void) context;
+
     RST_executed = TRUE;
     return SCPI_RES_OK;
 }
diff --git a/libscpi/test/test_scpi_utils.c b/libscpi/test/test_scpi_utils.c
index d4472f3..08f7275 100644
--- a/libscpi/test/test_scpi_utils.c
+++ b/libscpi/test/test_scpi_utils.c
@@ -272,19 +272,17 @@
         CU_ASSERT_EQUAL(result, r);                             \
     } while(0)                                                  \
 
-    #define TEST_MATCH_COMMAND2(p, s, r, ...)                   \
+    #define NOPAREN(...) __VA_ARGS__
+
+    #define TEST_MATCH_COMMAND2(p, s, r, v)                     \
     do {                                                        \
-        int32_t evalues[] = {__VA_ARGS__};                      \
+        int32_t evalues[] = {NOPAREN v};                        \
         unsigned int cnt = (sizeof(evalues)/4);                 \
         result = matchCommand(p, s, strlen(s), values, 20);     \
         CU_ASSERT_EQUAL(result, r);                             \
-        if (cnt > 0) CU_ASSERT_EQUAL(evalues[0], values[0]);    \
-        if (cnt > 1) CU_ASSERT_EQUAL(evalues[1], values[1]);    \
-        if (cnt > 2) CU_ASSERT_EQUAL(evalues[2], values[2]);    \
-        if (cnt > 3) CU_ASSERT_EQUAL(evalues[3], values[3]);    \
-        if (cnt > 4) CU_ASSERT_EQUAL(evalues[4], values[4]);    \
-        if (cnt > 5) CU_ASSERT_EQUAL(evalues[5], values[5]);    \
-        if (cnt > 6) CU_ASSERT_EQUAL(evalues[6], values[6]);    \
+        {unsigned int i; for (i = 0; i<cnt; i++) {              \
+            CU_ASSERT_EQUAL(evalues[i], values[i]);             \
+        }}                                                      \
     } while(0)                                                  \
 
     TEST_MATCH_COMMAND("A", "a", TRUE);
@@ -403,32 +401,32 @@
     TEST_MATCH_COMMAND("OUTPut#[:MODulation#]:FM#", "outp1:fm2", TRUE); // test numeric parameter
     TEST_MATCH_COMMAND("OUTPut#[:MODulation#]:FM#", "output:fm", TRUE); // test numeric parameter
 
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "outp3:mod10:fm", TRUE, 3, 10, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "output3:mod10:fm", TRUE, 3, 10, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "outp30:modulation:fm5", TRUE, 30, 1, 5); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "output:mod:fm", TRUE, 1, 1, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:fm", TRUE, 3, 1, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:mod10:fm", TRUE, 3, 10, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:fm2", TRUE, 3, 1, 2); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "output:fm", TRUE, 1, 1, 1); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "outp3:mod10:fm", TRUE, (3, 10, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "output3:mod10:fm", TRUE, (3, 10, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "outp30:modulation:fm5", TRUE, (30, 1, 5)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "output:mod:fm", TRUE, (1, 1, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:fm", TRUE, (3, 1, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:mod10:fm", TRUE, (3, 10, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:fm2", TRUE, (3, 1, 2)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "output:fm", TRUE, (1, 1, 1)); // test numeric parameter
 
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "outp3:mod:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "output3:mod:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "outp30:modulation:fm5", TRUE, 30, 5); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "output:mod:fm", TRUE, 1, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:mod:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:fm2", TRUE, 3, 2); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "output:fm", TRUE, 1, 1); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "outp3:mod:fm", TRUE, (3, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "output3:mod:fm", TRUE, (3, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "outp30:modulation:fm5", TRUE, (30, 5)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "output:mod:fm", TRUE, (1, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:fm", TRUE, (3, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:mod:fm", TRUE, (3, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:fm2", TRUE, (3, 2)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "output:fm", TRUE, (1, 1)); // test numeric parameter
 
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "outp3:mod10:fm", TRUE, 3, 10); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "output3:mod10:fm", TRUE, 3, 10); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "outp30:modulation:fm", TRUE, 30, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "output:mod:fm", TRUE, 1, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:mod10:fm", TRUE, 3, 10); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "output:fm", TRUE, 1, 1); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "outp3:mod10:fm", TRUE, (3, 10)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "output3:mod10:fm", TRUE, (3, 10)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "outp30:modulation:fm", TRUE, (30, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "output:mod:fm", TRUE, (1, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:fm", TRUE, (3, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:mod10:fm", TRUE, (3, 10)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:fm", TRUE, (3, 1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "output:fm", TRUE, (1, 1)); // test numeric parameter
 }
 
 static void test_composeCompoundCommand(void) {

--
Gitblit v1.9.1