~ chicken-core (chicken-5) 1f0eefb61407259e51cb5d396561421d5eafd373


commit 1f0eefb61407259e51cb5d396561421d5eafd373
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Mon Jun 3 09:46:40 2024 +0200
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Mon Jun 3 10:40:35 2024 +0200

    Fix compiler warnings about zero-sized memsets
    
    The "gethostaddr" and "fresh-addr" foreign lambdas were both declared
    with "scheme-pointer" for the first "saddr" argument's type.  The
    callers ("bind-socket" and "tcp-connect") both always allocate the
    requisite space for the address using make-string, so this cannot
    possibly be null.  This means we can use "nonnull-scheme-pointer" as
    the argument's type, instead.
    
    By not allowing the pointer to be NULL, the emitted C code uses
    C_data_pointer as opposed to C_data_pointer_or_null before.  The
    former doesn't have the condition which may return NULL like the
    latter does, which the C compiler apparently can see, which results in
    it stating that the memory size is zero (it would've been more correct
    if it said that it *can be* zero).
    
    Signed-off-by: felix <felix@call-with-current-continuation.org>

diff --git a/tcp.scm b/tcp.scm
index 75211f08..faab6551 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -243,7 +243,7 @@ EOF
      else C_return(ntohs(se->s_port));") )     
 
 (define gethostaddr
-  (foreign-lambda* bool ((scheme-pointer saddr) (c-string host) (unsigned-short port))
+  (foreign-lambda* bool ((nonnull-scheme-pointer saddr) (c-string host) (unsigned-short port))
     "struct hostent *he = gethostbyname(host);"
     "struct sockaddr_in *addr = (struct sockaddr_in *)saddr;"
     "if(he == NULL) C_return(0);"
@@ -292,7 +292,7 @@ EOF
 		    (loop (fx+ i 1)) ) ) ) ) ) ) ) )
 
 (define fresh-addr
-  (foreign-lambda* void ((scheme-pointer saddr) (unsigned-short port))
+  (foreign-lambda* void ((nonnull-scheme-pointer saddr) (unsigned-short port))
     "struct sockaddr_in *addr = (struct sockaddr_in *)saddr;"
     "memset(addr, 0, sizeof(struct sockaddr_in));"
     "addr->sin_family = AF_INET;"
Trap