Mailing List Archive

[master] 36225f2ee Expend a pointer mere in struct vsb, in an attempt to make it clear for static analysis tools what goes on.
commit 36225f2ee88f6a5bb4c709e27346962a0e085822
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date: Tue Aug 4 11:32:47 2020 +0000

Expend a pointer mere in struct vsb, in an attempt to make it
clear for static analysis tools what goes on.

This commit will be reverted if that doesn't work.

diff --git a/flint.lnt b/flint.lnt
index b47a74bdb..3eb5fbd52 100644
--- a/flint.lnt
+++ b/flint.lnt
@@ -185,7 +185,6 @@
-esym(765, VSB_*) // extern could be made static
-esym(714, VSB_*) // symb not ref
-sem(VSB_new, @p == (1p ? 1p : malloc(1)))
--sem(VSB_delete, custodial(1))

// ignore retval
-esym(534, VSB_cat)
diff --git a/include/vsb.h b/include/vsb.h
index facea9394..4041f4c4f 100644
--- a/include/vsb.h
+++ b/include/vsb.h
@@ -48,9 +48,9 @@ struct vsb {
#define VSB_USRFLAGMSK 0x0000ffff /* mask of flags the user may specify */
#define VSB_DYNAMIC 0x00010000 /* s_buf must be freed */
#define VSB_FINISHED 0x00020000 /* set by VSB_finish() */
-#define VSB_DYNSTRUCT 0x00080000 /* vsb must be freed */
int s_flags; /* flags */
int s_indent; /* Ident level */
+ void *s_alloced; /* Ptr to free, if vsb is malloced */
};

#ifdef __cplusplus
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index ef9f164b0..c47977e90 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -51,8 +51,7 @@ __FBSDID("$FreeBSD: head/sys/kern/subr_vsb.c 222004 2011-05-17 06:36:32Z phk $")
/*
* Predicates
*/
-#define VSB_ISDYNAMIC(s) ((s)->s_flags & VSB_DYNAMIC)
-#define VSB_ISDYNSTRUCT(s) ((s)->s_flags & VSB_DYNSTRUCT)
+#define VSB_ISDYNAMIC(s) ((s)->s_flags & VSB_DYNAMIC)
#define VSB_HASROOM(s) ((s)->s_len < (s)->s_size - 1L)
#define VSB_FREESPACE(s) ((s)->s_size - ((s)->s_len + 1L))
#define VSB_CANEXTEND(s) ((s)->s_flags & VSB_AUTOEXTEND)
@@ -232,7 +231,7 @@ VSB_new(struct vsb *s, char *buf, int length, int flags)
SBFREE(s);
return (NULL);
}
- VSB_SETFLAG(s, VSB_DYNSTRUCT);
+ s->s_alloced = s;
return (s);
}

@@ -480,17 +479,17 @@ VSB_len(const struct vsb *s)
void
VSB_delete(struct vsb *s)
{
- int isdyn;
+ void *p;

assert_VSB_integrity(s);
/* don't care if it's finished or not */

if (VSB_ISDYNAMIC(s))
SBFREE(s->s_buf);
- isdyn = VSB_ISDYNSTRUCT(s);
+ p = s->s_alloced;
memset(s, 0, sizeof(*s));
- if (isdyn)
- SBFREE(s);
+ if (p != NULL)
+ SBFREE(p);
}

void
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit