Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] enable -Werror and all of gcc's warning options
Here is a bunch of small patches to make fish/ build with most warnings enabled: [1/9] edit.c: avoid warning about signed/unsigned comparison [2/9] fish.c: avoid warnings [3/9] tilde.c: avoid a warning [4/9] fish.c: avoid "assignment discards qualifiers..." warning [5/9] fish.c: avoid signed/unsigned-comparison warning [6/9] fish.c: don't perform arithmetic on void* pointers [7/9] destpaths.c: avoid signed/unsigned-comparison warning [8/9] generator.ml: avoid signed/unsigned-comparison warning in fish/cmds.c [9/9] fish/: enable -Werror and all of gcc's warning options b/fish/Makefile.am | 5 ++--- b/fish/destpaths.c | 3 +-- b/fish/edit.c | 6 +++--- b/fish/fish.c | 2 +- b/fish/fish.h | 2 +- b/fish/rc.c | 3 --- b/fish/tilde.c | 9 +++------ b/src/generator.ml | 5 ++--- fish/fish.c | 9 ++++----- fish/fish.h | 7 ++++++- 10 files changed, 23 insertions(+), 28 deletions(-)
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 1/9] edit.c: avoid warning about signed/unsigned comparison
From: Jim Meyering <meyering at redhat.com>
* fish/edit.c (load_file): Change type of param from int to size_t.
(do_edit): Adjust caller.
---
fish/edit.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fish/edit.c b/fish/edit.c
index 3e6973e..1b6ce23 100644
--- a/fish/edit.c
+++ b/fish/edit.c
@@ -30,7 +30,7 @@
/* guestfish edit command, suggested by J??n Ondrej, implemented by RWMJ */
static char *
-load_file (const char *filename, int *len_r)
+load_file (const char *filename, size_t *len_r)
{
int fd, r, start;
char *content = NULL, *p;
@@ -80,7 +80,7 @@ do_edit (const char *cmd, int argc, char *argv[])
char buf[256];
const char *editor;
char *content, *content_new;
- int r, fd, size;
+ int r, fd;
if (argc != 1) {
fprintf (stderr, _("use '%s filename' to edit a file\n"),
cmd);
@@ -138,6 +138,7 @@ do_edit (const char *cmd, int argc, char *argv[])
}
/* Reload it. */
+ size_t size;
content_new = load_file (filename, &size);
if (content_new == NULL) {
unlink (filename);
--
1.6.4.378.g88f2f
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 2/9] fish.c: avoid warnings
From: Jim Meyering <meyering at redhat.com>
* fish/rc.c (UNIX_PATH_MAX): Remove unused definition.
* fish/fish.h (rc_listen): Declare with __attribute__((noreturn)).
---
fish/fish.h | 2 +-
fish/rc.c | 2 --
2 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/fish/fish.h b/fish/fish.h
index a6cc8c9..b7ed922 100644
--- a/fish/fish.h
+++ b/fish/fish.h
@@ -78,7 +78,7 @@ extern int do_glob (const char *cmd, int argc, char *argv[]);
extern int do_more (const char *cmd, int argc, char *argv[]);
/* in rc.c (remote control) */
-extern void rc_listen (void);
+extern void rc_listen (void) __attribute__((noreturn));
extern int rc_remote (int pid, const char *cmd, int argc, char *argv[],
int exit_on_error);
diff --git a/fish/rc.c b/fish/rc.c
index 57f1c36..5423c22 100644
--- a/fish/rc.c
+++ b/fish/rc.c
@@ -34,8 +34,6 @@
#include "fish.h"
#include "rc_protocol.h"
-#define UNIX_PATH_MAX 108
-
static void
create_sockpath (pid_t pid, char *sockpath, int len, struct sockaddr_un *addr)
{
--
1.6.4.378.g88f2f
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 3/9] tilde.c: avoid a warning
From: Jim Meyering <meyering at redhat.com>
* fish/tilde.c (find_home_for_username): Change param type: s/int/size_t/
(try_tilde_expansion): Adjust caller.
---
fish/tilde.c | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/fish/tilde.c b/fish/tilde.c
index f0a2259..4085417 100644
--- a/fish/tilde.c
+++ b/fish/tilde.c
@@ -30,7 +30,7 @@
#include "fish.h"
static char *expand_home (const char *);
-static const char *find_home_for_username (const char *, int);
+static const char *find_home_for_username (const char *, size_t);
/* This is called from the script loop if we find a candidate for
* ~username (tilde-expansion).
@@ -52,10 +52,8 @@ try_tilde_expansion (char *str)
* username from the password file.
*/
else {
- int len;
const char *home, *rest;
-
- len = strcspn (&str[1], "/");
+ size_t len = strcspn (&str[1], "/");
rest = &str[1+len];
home = find_home_for_username (&str[1], len);
@@ -106,7 +104,7 @@ expand_home (const char *append)
* or NULL if not found.
*/
static const char *
-find_home_for_username (const char *username, int ulen)
+find_home_for_username (const char *username, size_t ulen)
{
struct passwd *pw;
--
1.6.4.378.g88f2f
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 4/9] fish.c: avoid "assignment discards qualifiers..." warning
From: Jim Meyering <meyering at redhat.com>
* fish/fish.c (main): Cast-away-const.
* fish/fish.h (bad_cast): Define. Safer than using an actual cast.
---
fish/fish.c | 2 +-
fish/fish.h | 6 ++++++
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/fish/fish.c b/fish/fish.c
index 987df59..9de8e07 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -267,7 +267,7 @@ main (int argc, char *argv[])
*p = '\0';
mp->mountpoint = p+1;
} else
- mp->mountpoint = "/";
+ mp->mountpoint = bad_cast ("/");
mp->device = optarg;
mp->next = mps;
mps = mp;
diff --git a/fish/fish.h b/fish/fish.h
index b7ed922..642c269 100644
--- a/fish/fish.h
+++ b/fish/fish.h
@@ -106,4 +106,10 @@ extern char *try_tilde_expansion (char *path);
"reopen", \
"time"
+static inline char *
+bad_cast (char const *s)
+{
+ return (char *) s;
+}
+
#endif /* FISH_H */
--
1.6.4.378.g88f2f
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 5/9] fish.c: avoid signed/unsigned-comparison warning
From: Jim Meyering <meyering at redhat.com>
* fish/fish.c (script): Change type of index to "unsigned int".
---
fish/fish.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fish/fish.c b/fish/fish.c
index 9de8e07..fbac519 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -517,7 +517,7 @@ script (int prompt)
char *cmd;
char *p, *pend;
char *argv[64];
- int i, len;
+ int len;
int global_exit_on_error = !prompt;
int tilde_candidate;
@@ -581,7 +581,7 @@ script (int prompt)
if (len == 0) continue;
cmd = buf;
- i = 0;
+ unsigned int i = 0;
if (buf[len] == '\0') {
argv[0] = NULL;
goto got_command;
--
1.6.4.378.g88f2f
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 6/9] fish.c: don't perform arithmetic on void* pointers
From: Jim Meyering <meyering at redhat.com>
* fish/fish.c (xwrite): Use char*.
---
fish/fish.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/fish/fish.c b/fish/fish.c
index fbac519..3acd450 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -1117,9 +1117,10 @@ add_history_line (const char *line)
}
int
-xwrite (int fd, const void *buf, size_t len)
+xwrite (int fd, const void *v_buf, size_t len)
{
int r;
+ const char *buf = v_buf;
while (len > 0) {
r = write (fd, buf, len);
--
1.6.4.378.g88f2f
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 7/9] destpaths.c: avoid signed/unsigned-comparison warning
From: Jim Meyering <meyering at redhat.com>
* fish/destpaths.c (free_words): Change param type: s/int/size_t/.
---
fish/destpaths.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/fish/destpaths.c b/fish/destpaths.c
index 8b6173a..275db49 100644
--- a/fish/destpaths.c
+++ b/fish/destpaths.c
@@ -61,7 +61,7 @@ struct word {
};
static void
-free_words (struct word *words, int nr_words)
+free_words (struct word *words, size_t nr_words)
{
size_t i;
--
1.6.4.378.g88f2f
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 8/9] generator.ml: avoid signed/unsigned-comparison warning in fish/cmds.c
From: Jim Meyering <meyering at redhat.com>
* src/generator.ml (emit_print_list_function): Emit code that doesn't
evoke warnings. s/int/unsigned int/
(emit print_*_indent): Likewise, s/int/unsigned int/
---
src/generator.ml | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml
index a371ffd..46fcf2c 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6109,7 +6109,7 @@ and generate_fish_cmds () pr "static void
print_%s_list (struct guestfs_%s_list *%ss)\n"
typ typ typ;
pr "{\n";
- pr " int i;\n";
+ pr " unsigned int i;\n";
pr "\n";
pr " for (i = 0; i < %ss->len; ++i) {\n" typ;
pr " printf (\"[%%d] = {\\n\", i);\n";
@@ -6129,7 +6129,7 @@ and generate_fish_cmds () pr "static void
print_%s_indent (struct guestfs_%s *%s, const char *indent)\n" typ typ typ;
pr "{\n";
if needs_i then (
- pr " int i;\n";
+ pr " unsigned int i;\n";
pr "\n"
);
List.iter (
--
1.6.4.378.g88f2f
Jim Meyering
2009-Aug-21 13:28 UTC
[Libguestfs] [PATCH libguestfs 9/9] fish/: enable -Werror and all of gcc's warning options
From: Jim Meyering <meyering at redhat.com> * fish/Makefile.am: Use $(WARN_CFLAGS) $(WERROR_CFLAGS). --- fish/Makefile.am | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fish/Makefile.am b/fish/Makefile.am index 5bf3fbd..94bf757 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -51,8 +51,8 @@ BUILT_SOURCES = \ guestfish_CFLAGS = \ -I$(top_srcdir)/src -I$(top_builddir)/src \ -I$(top_srcdir)/fish -I$(top_builddir)/fish \ - -Wall \ - -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' + -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) guestfish_LDADD = $(top_builddir)/src/libguestfs.la $(LIBREADLINE) -- 1.6.4.378.g88f2f