ANSI and 64-bit related cleanup - integer-pointer mismatch
authorMatthew Mondor <mmondor@pulsar-zone.net>
Sat, 27 Aug 2016 15:09:03 +0000 (15:09 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Sat, 27 Aug 2016 15:09:03 +0000 (15:09 +0000)
Compiled with -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast
and fixed build-breaking cases.  Another common segfault candidate
on x86_64.

TODO
src/clientlist.c
src/ircd.c
src/m_stats.c
src/modules.c
src/res.c
src/socketengine_poll.c

diff --git a/TODO b/TODO
index 5ffbfcb..b3c494c 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
 ANSI fixes
 ----------
 
-- Compile with -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast
 - Fix any function arg mismatch (use -Werror=) (too many arg)
 - Fix format argument related warnings
 - Recheck warnings with -Wall
index 6f711ba..96402c5 100644 (file)
@@ -103,5 +103,5 @@ void remove_from_list(DLink **list, void *ptr, DLink *link)
       }
    }
 
-   sendto_realops("remove_from_list(%x, %x) failed!!", (int) list, (int) ptr);
+   sendto_realops("remove_from_list(%p, %p) failed!!", list, ptr);
 }
index 10502b0..319caca 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <sys/resource.h>
 #include <sys/socket.h>
+#include <stdint.h>
 #include <pwd.h>
 #include <signal.h>
 #include <fcntl.h>
@@ -213,8 +214,8 @@ void restart(char *mesg)
     was_here = YES;
         
 #ifdef  USE_SYSLOG
-    (void) syslog(LOG_WARNING, "Restarting Server because: %s, sbrk(0)-etext: %d",
-                  mesg, (u_int) sbrk((size_t) 0) - (u_int) sbrk0);
+    (void) syslog(LOG_WARNING, "Restarting Server because: %s, sbrk(0)-etext: %lld",
+                  mesg, (intptr_t)sbrk((size_t)0) - (intptr_t)sbrk0);
 #endif
     server_reboot();
 }
@@ -237,9 +238,9 @@ void s_restart()
 void server_reboot() 
 {
     int     i;
-    sendto_ops("Aieeeee!!!  Restarting server... sbrk(0)-etext: %d",
-               (u_int) sbrk((size_t) 0) - (u_int) sbrk0);
-        
+    sendto_ops("Aieeeee!!!  Restarting server... sbrk(0)-etext: %lld",
+               (intptr_t)sbrk((size_t)0) - (intptr_t)sbrk0);
     Debug((DEBUG_NOTICE, "Restarting server..."));
     dump_connections(me.fd);
     /*
index b31030b..8abd78e 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/stat.h>
 #include <utmp.h>
 #include <fcntl.h>
+#include <stdint.h>
 #include "h.h"
 #include "zlink.h"
 #include "userban.h"
@@ -706,9 +707,9 @@ count_memory(aClient *cptr, char *nick)
                me.name, RPL_STATSDEBUG, nick, totww, totch, totcl, totmisc,
                /*db,*/ tothash, rm, linkallocsz, fludallocsz, totuban);
 
-    sendto_one(cptr, ":%s %d %s :TOTAL: %d sbrk(0)-etext: %u",
+    sendto_one(cptr, ":%s %d %s :TOTAL: %d sbrk(0)-etext: %lld",
                me.name, RPL_STATSDEBUG, nick, tot,
-               (u_int) sbrk((size_t) 0) - (u_int) sbrk0);
+               (intptr_t)sbrk((size_t)0) - (intptr_t)sbrk0);
     return;
 }
 
index 54dbbdd..9f25247 100644 (file)
@@ -643,8 +643,8 @@ drop_all_hooks(aModule *owner)
         if(hk->owner == owner)
         {
             sendto_realops_lev(DEBUG_LEV, "Module cleanup: removing hook [%s]"
-                            " for opaque %d", get_texthooktype(hk->hooktype), 
-                            (int) owner);
+                            " for opaque %p", get_texthooktype(hk->hooktype), 
+                            owner);
 
             hooklist = get_hooklist((enum c_hooktype) hk->hooktype);
 
@@ -665,7 +665,7 @@ bircmodule_add_hook(enum c_hooktype hooktype, void *opaque, void *funcptr)
     if(!(owner = find_module_opaque(opaque)))
     {
         sendto_realops_lev(DEBUG_LEV, "Module tried to add hooktype %d with"
-                         " unknown opaque 0x%x", (int) hooktype, (int) opaque);
+                         " unknown opaque %p", (int) hooktype, opaque);
         return NULL;
     }
 
index bd53a8c..2618235 100644 (file)
--- a/src/res.c
+++ b/src/res.c
@@ -1440,7 +1440,7 @@ static unsigned int hash_id(unsigned int id)
 
 static unsigned int hash_cp(char *cp)
 {
-   return ((unsigned int) cp) % ARES_IDCACSIZE;
+   return (unsigned int)((intptr_t)cp) % ARES_IDCACSIZE;
 }
 
 /* Add a new cache item to the queue and hash table. */
index 25106ca..3a369b9 100644 (file)
 #include "socketengine.h"
 
 #include <sys/poll.h>
+#include <stdint.h>
 
 static void engine_get_pollfds(struct pollfd **pfds, int *numpfds);
 
 struct pollfd poll_fds[MAXCONNECTIONS];
-int last_pfd = -1;
+intptr_t last_pfd = -1;
 
 void engine_init(void)
 {
@@ -43,7 +44,7 @@ void engine_add_fd(int fd)
 
 void engine_del_fd(int fd)
 {
-   int arrayidx = (int) get_fd_internal(fd);
+   intptr_t arrayidx = (intptr_t)get_fd_internal(fd);
 
    /* If it's at the end of the array, just chop it off */
    if(arrayidx == last_pfd)
@@ -63,7 +64,7 @@ void engine_del_fd(int fd)
 
 void engine_change_fd_state(int fd, unsigned int stateplus)
 {
-   int arrayidx = (int) get_fd_internal(fd);
+   intptr_t arrayidx = (intptr_t)get_fd_internal(fd);
    struct pollfd *pfd = &poll_fds[arrayidx];
 
    pfd->events = 0;