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
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);
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;
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;
* 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;