use mod_cgid from HEAD an example...

mod_cgid.c: In function `cgid_server':
mod_cgid.c:694: warning: cast from pointer to integer of different size
mod_cgid.c:767: warning: cast to pointer from integer of different size
mod_cgid.c: In function `close_unix_socket':
mod_cgid.c:1048: warning: cast from pointer to integer of different size
mod_cgid.c: In function `connect_to_daemon':
mod_cgid.c:1091: warning: cast to pointer from integer of different size
mod_cgid.c: In function `cgid_handler':
mod_cgid.c:1449: warning: cast to pointer from integer of different size
mod_cgid.c:1461: warning: cast to pointer from integer of different size
mod_cgid.c: In function `include_cmd':
mod_cgid.c:1686: warning: cast to pointer from integer of different size

AFAICT, all these operations are safe on systems where sizeof(int) <= sizeof(void *) and sizeof(pid_t) <= sizeof(void *) (i.e., just about everything where you'd expect to run Apache or APR). Is anybody seeing stuff like this with other compilers?

The attached clumsy patch below axes the warnings, but it sure seems like overkill. Allocating extra storage from pools to get rid of the warnings doesn't seem to be cool either.


Index: mod_cgid.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/generators/mod_cgid.c,v
retrieving revision 1.148
diff -u -r1.148 mod_cgid.c
--- mod_cgid.c  12 Feb 2003 18:27:37 -0000      1.148
+++ mod_cgid.c  27 Mar 2003 13:43:48 -0000
@@ -130,6 +130,15 @@
 static pid_t daemon_pid;
 static int daemon_should_exit = 0;
 
+typedef void *int_in_ptr_t;
+#define INT_INTO_PTR(i,p) \
+AP_DEBUG_ASSERT(sizeof(i) <= sizeof(p)); \
+if (sizeof(i) < sizeof(p)) memset(&p, 0, sizeof(p)); \
+memcpy(&p, &i, sizeof(i))
+#define INT_FROM_PTR(i,p) \
+AP_DEBUG_ASSERT(sizeof(i) <= sizeof(p)); \
+memcpy(&i, &p, sizeof(i))
+
 /* Read and discard the data in the brigade produced by a CGI script */
 static void discard_script_output(apr_bucket_brigade *bb);
 
@@ -690,8 +699,10 @@
 
         if (cgid_req.req_type == GETPID_REQ) {
             pid_t pid;
+            int_in_ptr_t pid_in_ptr;
 
-            pid = (pid_t)apr_hash_get(script_hash, &cgid_req.conn_id, 
sizeof(cgid_req.conn_id));
+            pid_in_ptr = apr_hash_get(script_hash, &cgid_req.conn_id, 
sizeof(cgid_req.conn_id));
+            INT_FROM_PTR(pid, pid_in_ptr);
             if (write(sd2, &pid, sizeof(pid)) != sizeof(pid)) {
                 ap_log_error(APLOG_MARK, APLOG_ERR, 0,
                              main_server,
@@ -763,8 +774,11 @@
                               apr_filename_of_pathname(r->filename));
             }
             else {
+                int_in_ptr_t pid_in_ptr;
+
+                INT_INTO_PTR(procnew->pid, pid_in_ptr);
                 apr_hash_set(script_hash, &cgid_req.conn_id, 
sizeof(cgid_req.conn_id), 
-                             (void *)procnew->pid);
+                             pid_in_ptr);
             }
         }
     } 
@@ -1045,8 +1059,10 @@
 
 static apr_status_t close_unix_socket(void *thefd)
 {
-    int fd = (int)thefd;
-    
+    int_in_ptr_t fd_in_ptr = thefd;
+    int fd;
+
+    INT_FROM_PTR(fd, fd_in_ptr);
     return close(fd);
 }
 
@@ -1088,7 +1104,10 @@
             }
         }
         else {
-            apr_pool_cleanup_register(r->pool, (void *)sd, close_unix_socket,
+            int_in_ptr_t sd_in_ptr;
+
+            INT_INTO_PTR(sd, sd_in_ptr);
+            apr_pool_cleanup_register(r->pool, sd_in_ptr, close_unix_socket,
                                       apr_pool_cleanup_null);
             break; /* we got connected! */
         }
@@ -1399,7 +1418,8 @@
     if (!nph) { 
         const char *location; 
         char sbuf[MAX_STRING_LEN]; 
-        int ret; 
+        int ret;
+        int_in_ptr_t sd_in_ptr;
 
         bb = apr_brigade_create(r->pool, c->bucket_alloc);
         b = apr_bucket_pipe_create(tempsock, c->bucket_alloc);
@@ -1446,19 +1466,22 @@
          * gives up the responsibility of closing the socket, so
          * get rid of the cleanup.
          */
-        apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
+        INT_INTO_PTR(sd, sd_in_ptr);
+        apr_pool_cleanup_kill(r->pool, sd_in_ptr, close_unix_socket);
 
         ap_pass_brigade(r->output_filters, bb);
     } 
 
     if (nph) {
         struct ap_filter_t *cur;
+        int_in_ptr_t sd_in_ptr;
         
         /* Passing our socket down the filter chain in a pipe bucket
          * gives up the responsibility of closing the socket, so
          * get rid of the cleanup.
          */
-        apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
+        INT_INTO_PTR(sd, sd_in_ptr);
+        apr_pool_cleanup_kill(r->pool, sd_in_ptr, close_unix_socket);
 
         /* get rid of all filters up through protocol...  since we
          * haven't parsed off the headers, there is no way they can
@@ -1683,7 +1706,10 @@
          * gives up the responsibility of closing the socket, so
          * get rid of the cleanup.
          */
-        apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
+        int_in_ptr_t sd_in_ptr;
+
+        INT_INTO_PTR(sd, sd_in_ptr);
+        apr_pool_cleanup_kill(r->pool, sd_in_ptr, close_unix_socket);
 
         bcgi = apr_brigade_create(r->pool, r->connection->bucket_alloc);
         b    = apr_bucket_pipe_create(tempsock, r->connection->bucket_alloc);

Reply via email to