[master] 03463abf5 add back a local variable which makes flexelint grok the code
Nils Goroll
nils.goroll at uplex.de
Sat Apr 4 12:40:07 UTC 2020
commit 03463abf52bad7a538d0a8b7292892055d7a41f9
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Sat Apr 4 14:32:49 2020 +0200
add back a local variable which makes flexelint grok the code
I did not understand when I committed
119b41747f9dd3360d1fe1ea1cb181c9aefb2e81 that the local variable was
required for flexelint to unterstand that this is not an out-of-bounds
access.
This quote of phk from the top level rant sais it all:
* Do I need to tell you that static code analysis tools have a
* really hard time coping with this, and that they give a lot of
* false negatives which confuse people ?
So true. Sorry for going a smaller but almost full circle here, I
started with good intentions and now all that's left is the desire to
leave the code at least a little cleaner as I found it.
diff --git a/lib/libvarnish/vsa.c b/lib/libvarnish/vsa.c
index edad67d6d..a46e8ac08 100644
--- a/lib/libvarnish/vsa.c
+++ b/lib/libvarnish/vsa.c
@@ -305,27 +305,29 @@ VSA_Build(void *d, const void *s, unsigned sal)
{
struct suckaddr *sua;
const struct sockaddr *sa = s;
+ unsigned l; // for flexelint
AN(d);
AN(s);
- if (sal == 0 || sua_len(sa) != sal)
+ l = sua_len(sa);
+ if (l == 0 || l != sal)
return (NULL);
sua = d;
INIT_OBJ(sua, SUCKADDR_MAGIC);
- switch (sal) {
+ switch (l) {
case sizeof sua->sa4:
- memcpy(&sua->sa4, s, sal);
+ memcpy(&sua->sa4, s, l);
break;
case sizeof sua->sa6:
- memcpy(&sua->sa6, s, sal);
+ memcpy(&sua->sa6, s, l);
break;
default:
WRONG("VSA protocol vs. size");
}
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
- sua->sa.sa_len = (unsigned char)sal;
+ sua->sa.sa_len = (unsigned char)l;
#endif
return (sua);
}
More information about the varnish-commit
mailing list