[PATCH 0/4] pedantic compile warning fixes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/4] pedantic compile warning fixes

Carlo Marcelo Arenas Belon
The following patch series fixes several (mostly harmless) compilation
warnings in trunk triggered by using "pedantic" and that could result
in compilation errors for the tests (which still use -Werror).

  PATCH 1/4: confuse: ISO C90 does not support the ‘%lf’ printf format
  PATCH 2/4: tests: C++ style comments are not allowed in ISO C90
  PATCH 3/4: tests: ISO C90 forbids mixed declarations and code
  PATCH 4/4: tests: initializer element is not computable at load time

 examples/ftpconf.c          |    2 +-
 examples/reread.c           |    2 +-
 examples/simple.c           |   10 +++++-----
 examples/wincfgtest.c       |    2 +-
 src/confuse.c               |    2 +-
 tests/list_plus_syntax.c    |    9 +++++----
 tests/quote_before_print.c  |    6 ++++--
 tests/section_title_dupes.c |    2 +-
 tests/suite_dup.c           |    2 +-
 tests/suite_list.c          |    4 ++--
 tests/suite_single.c        |    6 +++---
 tests/suite_validate.c      |    7 +++----
 12 files changed, 28 insertions(+), 26 deletions(-)

Carlo


_______________________________________________
Confuse-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/confuse-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/4] confuse: ISO C90 does not support the ‘%lf’ printf format

Carlo Marcelo Arenas Belon

'%f' is valid for float and double, while '%Lf' is needed for long double
leaving this as a undefined behaviour for C90 and ignored in C99 as shown
by :

  confuse.c:1410: warning: ISO C90 does not support the ‘%lf’ printf format

Signed-off-by: Carlo Marcelo Arenas Belon <[hidden email]>
---
 examples/wincfgtest.c |    2 +-
 src/confuse.c         |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)


diff --git a/examples/wincfgtest.c b/examples/wincfgtest.c
index 24f6fa5..4a9c1ac 100644
--- a/examples/wincfgtest.c
+++ b/examples/wincfgtest.c
@@ -88,7 +88,7 @@ int main(void)
             if(cfg_parse(cfg, "wincfgtest.conf") == CFG_FILE_ERROR)
                 perror("wincfgtest.conf");
 
-           sprintf(buf, "bool:    %s\nstring:  %s\nnumber:  %ld\nfloat:   %lf\n",
+           sprintf(buf, "bool:    %s\nstring:  %s\nnumber:  %ld\nfloat:   %f\n",
              cfg_getbool(cfg, "bool") ? "true" : "false", cfg_getstr(cfg, "string"),
              cfg_getint(cfg, "number"), cfg_getfloat(cfg, "float"));
            MessageBox(NULL, buf, "libConfuse", MB_OK);
diff --git a/src/confuse.c b/src/confuse.c
index 003d0b9..6e7a0ef 100644
--- a/src/confuse.c
+++ b/src/confuse.c
@@ -1407,7 +1407,7 @@ DLLIMPORT void cfg_opt_nprint_var(cfg_opt_t *opt, unsigned int index, FILE *fp)
             fprintf(fp, "%ld", cfg_opt_getnint(opt, index));
             break;
         case CFGT_FLOAT:
-            fprintf(fp, "%lf", cfg_opt_getnfloat(opt, index));
+            fprintf(fp, "%f", cfg_opt_getnfloat(opt, index));
             break;
         case CFGT_STR:
             str = cfg_opt_getnstr(opt, index);

_______________________________________________
Confuse-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/confuse-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/4] tests: C++ style comments are not allowed in ISO C90

Carlo Marcelo Arenas Belon
In reply to this post by Carlo Marcelo Arenas Belon

remove code which was commented out using "C++" style and that is
not supported by ISO C90, resulting otherwise in an error if ANSI
is required

Signed-off-by: Carlo Marcelo Arenas Belon <[hidden email]>
---
 tests/suite_validate.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)


diff --git a/tests/suite_validate.c b/tests/suite_validate.c
index 710016c..a914bfa 100644
--- a/tests/suite_validate.c
+++ b/tests/suite_validate.c
@@ -98,7 +98,6 @@ void validate_setup(void)
     cfg_opt_t multi_opts[] =
     {
         CFG_INT_LIST("speeds", 0, CFGF_NONE),
-        //{"speeds",CFGT_INT,0,0,CFGF_LIST,0,{0,0,cfg_false,0,0},0,0,0,validate_speed,0},
         CFG_SEC("options", action_opts, CFGF_NONE),
         CFG_END()
     };

_______________________________________________
Confuse-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/confuse-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 3/4] tests: ISO C90 forbids mixed declarations and code

Carlo Marcelo Arenas Belon
In reply to this post by Carlo Marcelo Arenas Belon

move declarations to the begin of each block where they are being used

Signed-off-by: Carlo Marcelo Arenas Belon <[hidden email]>
---
 tests/list_plus_syntax.c   |    9 +++++----
 tests/quote_before_print.c |    6 ++++--
 2 files changed, 9 insertions(+), 6 deletions(-)


diff --git a/tests/list_plus_syntax.c b/tests/list_plus_syntax.c
index 76f62f7..53f48e7 100644
--- a/tests/list_plus_syntax.c
+++ b/tests/list_plus_syntax.c
@@ -8,13 +8,14 @@ int main(void)
         CFG_END()
     };
 
+    int rc;
     cfg_t *cfg = cfg_init(opts, CFGF_NONE);
     fail_unless(cfg);
 
-    int rc = cfg_parse_buf(cfg,
-            " stringproperty = {\"this\"}\n"
-            " stringproperty += {\"that\"}\n"
-            " stringproperty += {\"other\"}\n");
+    rc = cfg_parse_buf(cfg,
+        " stringproperty = {\"this\"}\n"
+        " stringproperty += {\"that\"}\n"
+        " stringproperty += {\"other\"}\n");
 
     fail_unless(rc == CFG_SUCCESS);
 
diff --git a/tests/quote_before_print.c b/tests/quote_before_print.c
index 15b02b9..e7e1df7 100644
--- a/tests/quote_before_print.c
+++ b/tests/quote_before_print.c
@@ -16,6 +16,8 @@ cfg_opt_t opts[] =
 int
 main(void)
 {
+ FILE *fp;
+ char *param;
  cfg_t *cfg = cfg_init(opts, CFGF_NONE);
  fail_unless(cfg);
 
@@ -25,7 +27,7 @@ main(void)
 
  /* print the config to a temporary file
  */
- FILE *fp = tmpfile();
+ fp = tmpfile();
  fail_unless(fp);
  cfg_print(cfg, fp);
  cfg_free(cfg);
@@ -38,7 +40,7 @@ main(void)
  fail_unless(cfg_parse_fp(cfg, fp) == CFG_SUCCESS);
  fail_unless(fclose(fp) == 0);
 
- char *param = cfg_getstr(cfg, "parameter");
+ param = cfg_getstr(cfg, "parameter");
  fail_unless(param);
 
  fail_unless(strcmp(param, "text \" with quotes and \\") == 0);

_______________________________________________
Confuse-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/confuse-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 4/4] tests: initializer element is not computable at load time

Carlo Marcelo Arenas Belon
In reply to this post by Carlo Marcelo Arenas Belon

ISO C90 (until C99) requires that all initializer be constant values
but a pointer to an automatic variable is not kwnown at load time.

make all pointers used as part of CFG_SIMPLE_* and CFG_SEC macros in
the examples and tests, point to a static variable so it can be
considered constant

Signed-off-by: Carlo Marcelo Arenas Belon <[hidden email]>
---
 examples/ftpconf.c          |    2 +-
 examples/reread.c           |    2 +-
 examples/simple.c           |   10 +++++-----
 tests/section_title_dupes.c |    2 +-
 tests/suite_dup.c           |    2 +-
 tests/suite_list.c          |    4 ++--
 tests/suite_single.c        |    6 +++---
 tests/suite_validate.c      |    6 +++---
 8 files changed, 17 insertions(+), 17 deletions(-)


diff --git a/examples/ftpconf.c b/examples/ftpconf.c
index c8497c3..a46db92 100644
--- a/examples/ftpconf.c
+++ b/examples/ftpconf.c
@@ -68,7 +68,7 @@ int conf_validate_bookmark(cfg_t *cfg, cfg_opt_t *opt)
 
 cfg_t *parse_conf(const char *filename)
 {
-    cfg_opt_t bookmark_opts[] = {
+    static cfg_opt_t bookmark_opts[] = {
         CFG_STR("host", 0, CFGF_NODEFAULT),
         CFG_INT("port", 21, CFGF_NONE),
         CFG_STR("login", "anonymous", CFGF_NONE),
diff --git a/examples/reread.c b/examples/reread.c
index fb60776..5fa1042 100644
--- a/examples/reread.c
+++ b/examples/reread.c
@@ -8,7 +8,7 @@ const char *config_filename = "./reread.conf";
 
 void read_config(void)
 {
-    cfg_opt_t arg_opts[] = {
+    static cfg_opt_t arg_opts[] = {
         CFG_STR("value", "default", CFGF_NONE),
         CFG_END()
     };
diff --git a/examples/simple.c b/examples/simple.c
index 9f47ec7..9a6ee51 100644
--- a/examples/simple.c
+++ b/examples/simple.c
@@ -4,10 +4,10 @@
 
 int main(void)
 {
-    cfg_bool_t verbose = cfg_false;
-    char *server = NULL;
-    double delay = 1.356e-32;
-    char *username = NULL;
+    static cfg_bool_t verbose = cfg_false;
+    static char *server = NULL;
+    static double delay = 1.356e-32;
+    static char *username = NULL;
 
     /* Although the macro used to specify an integer option is called
      * CFG_SIMPLE_INT(), it actually expects a long int. On a 64 bit system
@@ -18,7 +18,7 @@ int main(void)
      * cfg_getint(), this is not a problem as the data types are implicitly
      * cast.
      */
-    long int debug = 1;
+    static long int debug = 1;
 
     cfg_opt_t opts[] = {
         CFG_SIMPLE_BOOL("verbose", &verbose),
diff --git a/tests/section_title_dupes.c b/tests/section_title_dupes.c
index ba8b93f..88b0436 100644
--- a/tests/section_title_dupes.c
+++ b/tests/section_title_dupes.c
@@ -3,7 +3,7 @@
 
 int main(void)
 {
-    cfg_opt_t section_opts[] = {
+    static cfg_opt_t section_opts[] = {
         CFG_STR("prop", 0, CFGF_NONE),
         CFG_END()
     };
diff --git a/tests/suite_dup.c b/tests/suite_dup.c
index 8a125fc..189be2a 100644
--- a/tests/suite_dup.c
+++ b/tests/suite_dup.c
@@ -3,7 +3,7 @@
 
 static cfg_t *create_config(void)
 {
-    cfg_opt_t sec_opts[] =
+    static cfg_opt_t sec_opts[] =
     {
         CFG_INT("a", 1, CFGF_NONE),
         CFG_INT("b", 2, CFGF_NONE),
diff --git a/tests/suite_list.c b/tests/suite_list.c
index 862782a..e1e44cf 100644
--- a/tests/suite_list.c
+++ b/tests/suite_list.c
@@ -6,7 +6,7 @@ static int numopts = 0;
 
 static void list_setup(void)
 {
-    cfg_opt_t subsec_opts[] =
+    static cfg_opt_t subsec_opts[] =
     {
         CFG_STR_LIST("subsubstring", 0, CFGF_NONE),
         CFG_INT_LIST("subsubinteger", 0, CFGF_NONE),
@@ -15,7 +15,7 @@ static void list_setup(void)
         CFG_END()
     };
 
-    cfg_opt_t sec_opts[] =
+    static cfg_opt_t sec_opts[] =
     {
         CFG_STR_LIST("substring", "{subdefault1, subdefault2}", CFGF_NONE),
         CFG_INT_LIST("subinteger", "{17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 300}", CFGF_NONE), /* 14 values */
diff --git a/tests/suite_single.c b/tests/suite_single.c
index cb749d6..ded643f 100644
--- a/tests/suite_single.c
+++ b/tests/suite_single.c
@@ -65,7 +65,7 @@ int parse_ether_address(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *res
 
 void single_setup(void)
 {
-    cfg_opt_t subsec_opts[] =
+    static cfg_opt_t subsec_opts[] =
     {
         CFG_STR("subsubstring", "subsubdefault", CFGF_NONE),
         CFG_INT("subsubinteger", -42, CFGF_NONE),
@@ -74,7 +74,7 @@ void single_setup(void)
         CFG_END()
     };
 
-    cfg_opt_t sec_opts[] =
+    static cfg_opt_t sec_opts[] =
     {
         CFG_STR("substring", "subdefault", CFGF_NONE),
         CFG_INT("subinteger", 17, CFGF_NONE),
@@ -84,7 +84,7 @@ void single_setup(void)
         CFG_END()
     };
 
-    cfg_opt_t nodef_opts[] =
+    static cfg_opt_t nodef_opts[] =
     {
         CFG_STR("string", "defvalue", CFGF_NONE),
         CFG_INT("int", -17, CFGF_NODEFAULT),
diff --git a/tests/suite_validate.c b/tests/suite_validate.c
index a914bfa..e29f511 100644
--- a/tests/suite_validate.c
+++ b/tests/suite_validate.c
@@ -13,7 +13,7 @@ static cfg_t *cfg = 0;
 #define ACTION_CRAWL 3
 #define ACTION_JUMP 4
 
-int parse_action(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
+static int parse_action(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result)
 {
     if(strcmp(value, "run") == 0)
         *(int *)result = ACTION_RUN;
@@ -87,7 +87,7 @@ void validate_setup(void)
 {
     cfg_opt_t *opt = 0;
 
-    cfg_opt_t action_opts[] =
+    static cfg_opt_t action_opts[] =
     {
         CFG_INT("speed", 0, CFGF_NONE),
         CFG_STR("name", 0, CFGF_NONE),
@@ -95,7 +95,7 @@ void validate_setup(void)
         CFG_END()
     };
 
-    cfg_opt_t multi_opts[] =
+    static cfg_opt_t multi_opts[] =
     {
         CFG_INT_LIST("speeds", 0, CFGF_NONE),
         CFG_SEC("options", action_opts, CFGF_NONE),

_______________________________________________
Confuse-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/confuse-devel