[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH gfs2-utils] don't use "void*" in arithmetic



Building gfs2-utils, I saw these warnings:

  main.c:21: warning: pointer of type ‘void *’ used in arithmetic
  main.c:38: warning: pointer of type ‘void *’ used in arithmetic
  main.c:145: warning: pointer of type ‘void *’ used in arithmetic
  main.c:33: warning: pointer of type ‘void *’ used in arithmetic
  main.c:50: warning: pointer of type ‘void *’ used in arithmetic

Here are patches that add no casts (and yes, that's a feature ;-):

>From d107032f49e553061276f24016c4dc256292795d Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering redhat com>
Date: Mon, 22 Jun 2009 22:12:49 +0200
Subject: [PATCH gfs2-utils] don't use "void*" in arithmetic

* group/libgfscontrol/main.c (do_read): Use an intermediate
"char *" variable (better than a cast).
(do_write): Likewise, and make the BUF parameter const.
* group/gfs_control/main.c (do_write): Likewise.
* group/gfs_controld/main.c (do_read, do_write): Likewise.
* group/gfs_controld/gfs_daemon.h (do_write): Update prototype.
---
 group/gfs_control/main.c        |    6 +++---
 group/gfs_controld/gfs_daemon.h |    2 +-
 group/gfs_controld/main.c       |    9 +++++----
 group/libgfscontrol/main.c      |    9 +++++----
 4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/group/gfs_control/main.c b/group/gfs_control/main.c
index fe4359f..04aed09 100644
--- a/group/gfs_control/main.c
+++ b/group/gfs_control/main.c
@@ -137,12 +137,13 @@ static void decode_arguments(int argc, char **argv)
 	}
 }

-static int do_write(int fd, void *buf, size_t count)
+static int do_write(int fd, const void *buf, size_t count)
 {
 	int rv, off = 0;
+	const char *p = buf;

  retry:
-	rv = write(fd, buf + off, count);
+	rv = write(fd, p + off, count);
 	if (rv == -1 && errno == EINTR)
 		goto retry;
 	if (rv < 0)
@@ -462,4 +463,3 @@ int main(int argc, char **argv)
 	}
 	return 0;
 }
-
diff --git a/group/gfs_controld/gfs_daemon.h b/group/gfs_controld/gfs_daemon.h
index 7fa1837..7fbfea7 100644
--- a/group/gfs_controld/gfs_daemon.h
+++ b/group/gfs_controld/gfs_daemon.h
@@ -191,7 +191,7 @@ void free_mg(struct mountgroup *mg);

 /* main.c */
 int do_read(int fd, void *buf, size_t count);
-int do_write(int fd, void *buf, size_t count);
+int do_write(int fd, const void *buf, size_t count);
 void client_dead(int ci);
 int client_add(int fd, void (*workfn)(int ci), void (*deadfn)(int ci));
 int client_fd(int ci);
diff --git a/group/gfs_controld/main.c b/group/gfs_controld/main.c
index a0b809d..65e92dc 100644
--- a/group/gfs_controld/main.c
+++ b/group/gfs_controld/main.c
@@ -28,9 +28,10 @@ static void do_withdraw(char *name);
 int do_read(int fd, void *buf, size_t count)
 {
 	int rv, off = 0;
+	char *p = buf;

 	while (off < count) {
-		rv = read(fd, buf + off, count - off);
+		rv = read(fd, p + off, count - off);
 		if (rv == 0)
 			return -1;
 		if (rv == -1 && errno == EINTR)
@@ -42,12 +43,13 @@ int do_read(int fd, void *buf, size_t count)
 	return 0;
 }

-int do_write(int fd, void *buf, size_t count)
+int do_write(int fd, const void *buf, size_t count)
 {
 	int rv, off = 0;
+	const char *p = buf;

  retry:
-	rv = write(fd, buf + off, count);
+	rv = write(fd, p + off, count);
 	if (rv == -1 && errno == EINTR)
 		goto retry;
 	if (rv < 0) {
@@ -1359,4 +1361,3 @@ int dmsetup_wait;
 cpg_handle_t cpg_handle_daemon;
 int libcpg_flow_control_on;
 struct list_head withdrawn_mounts;
-
diff --git a/group/libgfscontrol/main.c b/group/libgfscontrol/main.c
index 831c9e4..2890733 100644
--- a/group/libgfscontrol/main.c
+++ b/group/libgfscontrol/main.c
@@ -16,9 +16,10 @@
 static int do_read(int fd, void *buf, size_t count)
 {
 	int rv, off = 0;
+	char *p = buf;

 	while (off < count) {
-		rv = read(fd, buf + off, count - off);
+		rv = read(fd, p + off, count - off);
 		if (rv == 0)
 			return -1;
 		if (rv == -1 && errno == EINTR)
@@ -30,12 +31,13 @@ static int do_read(int fd, void *buf, size_t count)
 	return 0;
 }

-static int do_write(int fd, void *buf, size_t count)
+static int do_write(int fd, const void *buf, size_t count)
 {
 	int rv, off = 0;
+	const char *p = buf;

  retry:
-	rv = write(fd, buf + off, count);
+	rv = write(fd, p + off, count);
 	if (rv == -1 && errno == EINTR)
 		goto retry;
 	if (rv < 0) {
@@ -425,4 +427,3 @@ int gfsc_fs_leave(struct gfsc_mount_args *ma, int reason)

 	return do_write(fd, msg, sizeof(msg));
 }
-
--
1.6.3.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]