don't use "void*" in arithmetic
PATCH 1/1 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 <[email protected]>
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(-)
group/gfs_control/main.c +3 -3
@@ -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 ; } -
group/gfs_controld/gfs_daemon.h +1 -1
@@ -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);
group/gfs_controld/main.c +5 -4
@@ -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; -
group/libgfscontrol/main.c +5 -4
@@ -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
PATCH 1/1 don't use "void*" in arithmetic
Quoted 9 lines · Jim Meyering
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 ;-):
We've fixed all these in the STABLE3 branch... I thought Fabio had some scheme in mind for syncing all that work to these new trees. Both to avoid doing the same work over again, and so we do the same thing in both. i.e. in STABLE3 I fixed this with write(fd, (char *)buf + off, count);
Quoted 133 lines
Quoted 2 lines
From
d107032f49e553061276f24016c4dc256292795dMon Sep 17 00:00:00 2001From: Jim Meyering <[email protected]>
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(-)group/gfs_control/main.c +3
-3@@ -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 ; } -group/gfs_controld/gfs_daemon.h +1
-1@@ -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);group/gfs_controld/main.c +5
-4@@ -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; -group/libgfscontrol/main.c +5
-5@@ -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
PATCH 1/1 don't use "void*" in arithmetic
Quoted 9 lines · David Teigland
Quoted 8 lines · Jim Meyering
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
Quoted 6 lines
Quoted 1 line
Here are patches that add no casts (and yes, that's a feature ;-):
We've fixed all these in the STABLE3 branch... I thought Fabio had some scheme in mind for syncing all that work to these new trees. Both to avoid doing the same work over again, and so we do the same thing in both. i.e. in STABLE3 I fixed this with
write(fd, (char *)buf + off, count);
Thanks for the heads-up.
Avoiding casts is nice, but not a big deal here.
The const-adding parts of the patch are worth keeping, though.
PATCH 1/1 don't use "void*" in arithmetic
In reply to David TeiglandQuoted 9 lines · David Teigland
Quoted 8 lines · Jim Meyering
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
Quoted 6 lines
Quoted 1 line
Here are patches that add no casts (and yes, that's a feature ;-):
We've fixed all these in the STABLE3 branch... I thought Fabio had some scheme in mind for syncing all that work to these new trees. Both to avoid doing the same work over again, and so we do the same thing in both. i.e. in STABLE3 I fixed this with
write(fd, (char *)buf + off, count);
Yes the idea is to sync them all, but master is lower priority at the moment vs S3 release.
master just got all the build flags required to show all of the same warnings as in S3, so it's going to be easier to spot what needs to be cherry picked.
Fabio