[master] bc5dd0e29 vcc: Extract CSTR concatenation in its own function

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jan 31 16:08:06 UTC 2022


commit bc5dd0e2981ec3408fe29a2ee2cac902bf5d6104
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Jan 31 17:03:45 2022 +0100

    vcc: Extract CSTR concatenation in its own function
    
    This plugs a leak spotted by Coverity Scan. It might be useful in other
    places anyway, so it might as well be decoupled from constant regexp
    parsing.

diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c
index 5633f83f4..d6397636e 100644
--- a/lib/libvcc/vcc_utils.c
+++ b/lib/libvcc/vcc_utils.c
@@ -48,32 +48,39 @@
 
 /*--------------------------------------------------------------------*/
 
-void
-vcc_regexp(struct vcc *tl, struct vsb *vgc_name)
+static void
+vcc_cstrcat(struct vcc *tl, struct vsb *vsb)
 {
-	struct vsb *pattern;
-	char buf[BUFSIZ];
-	vre_t *t;
-	int error, erroroffset;
 	struct token *t1;
-	struct inifin *ifp;
-
-	pattern = VSB_new_auto();
-	AN(pattern);
 
 	assert(tl->t->tok == CSTR);
-	VSB_cat(pattern, tl->t->dec);
+	VSB_cat(vsb, tl->t->dec);
 
 	t1 = vcc_PeekToken(tl);
 	AN(t1);
+
 	while (t1->tok == '+') {
 		vcc_NextToken(tl);
 		SkipToken(tl, '+');
 		ExpectErr(tl, CSTR);
-		VSB_cat(pattern, tl->t->dec);
+		VSB_cat(vsb, tl->t->dec);
 		t1 = vcc_PeekToken(tl);
 		AN(t1);
 	}
+}
+
+void
+vcc_regexp(struct vcc *tl, struct vsb *vgc_name)
+{
+	struct vsb *pattern;
+	char buf[BUFSIZ];
+	vre_t *t;
+	int error, erroroffset;
+	struct inifin *ifp;
+
+	pattern = VSB_new_auto();
+	AN(pattern);
+	vcc_cstrcat(tl, pattern);
 	AZ(VSB_finish(pattern));
 
 	t = VRE_compile(VSB_data(pattern), 0, &error, &erroroffset, 0);


More information about the varnish-commit mailing list