]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
scan-build: zero-init buffers the analyzer can't prove are written
authorAndrew Tridgell <andrew@tridgell.net>
Fri, 12 Jun 2026 00:53:01 +0000 (10:53 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Mon, 15 Jun 2026 22:55:39 +0000 (08:55 +1000)
clang's static analyzer doesn't model SIVAL/SIVAL64/SIVALu or
getpeername/getsockname as initializing their target bytes, so it
reports false "garbage value" reads. Zero-init the affected buffers;
the bytes are always overwritten at runtime, so this only quiets the
analyzer.

io.c:     write_varint/write_varlong b[]
hashtable.c: hash_search buf[]
socket.c: accepted_peer/our_local

hashtable.c
io.c
socket.c

index f4aa85f1cbbd113109854b88b351b346d1b9f4fe..4f8929d619254301f8beb787bcafd4e5702d97cb 100644 (file)
@@ -120,7 +120,7 @@ void *hashtable_find(struct hashtable *tbl, int64 key, void *data_when_new)
 
        if (!key64) {
                /* Based on Jenkins One-at-a-time hash. */
-               uchar buf[4], *keyp = buf;
+               uchar buf[4] = {0}, *keyp = buf; /* {0} only to satisfy the analyzer (SIVALu fills buf) */
                int i;
 
                SIVALu(buf, 0, key);
diff --git a/io.c b/io.c
index 0b96c27095650369cc01d9dd064b94d58d09b8ea..2dfeeaa3486aae5eeae7cc185f61d7213d684389 100644 (file)
--- a/io.c
+++ b/io.c
@@ -2163,7 +2163,7 @@ void write_int(int f, int32 x)
 
 void write_varint(int f, int32 x)
 {
-       char b[5];
+       char b[5] = {0}; /* {0} only to satisfy the analyzer: it doesn't model SIVAL initialising b[1..4] */
        uchar bit;
        int cnt;
 
@@ -2185,7 +2185,7 @@ void write_varint(int f, int32 x)
 
 void write_varlong(int f, int64 x, uchar min_bytes)
 {
-       char b[9];
+       char b[9] = {0}; /* {0} only to satisfy the analyzer: it doesn't model SIVAL64 initialising b[1..8] */
        uchar bit;
        int cnt = 8;
 
index d5aa0cb7101059ae052c506432286f58e3e19e2c..4ac79ec765998eb3e1ef78119214a358fb71c77f 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -802,7 +802,8 @@ static int socketpair_tcp(int fd[2])
         * the local address of our connecting end (fd[1]), and both must be
         * loopback.  If they differ, someone else connected first; fail closed. */
        {
-               struct sockaddr_in accepted_peer, our_local;
+               /* {0}: the analyzer doesn't model getpeername/getsockname filling these. */
+               struct sockaddr_in accepted_peer = {0}, our_local = {0};
                socklen_t plen = sizeof accepted_peer;
                socklen_t llen = sizeof our_local;