[master] 3f3d70146 http2_hpack: Apply Tforeach() macro
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Tue Sep 24 07:21:08 UTC 2024
commit 3f3d701468564d166529a4b00d09966d688432e0
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Mon Sep 23 11:03:49 2024 +0200
http2_hpack: Apply Tforeach() macro
Courtesy of Coccinelle.
diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c
index 0ef67ffe1..694e7fc83 100644
--- a/bin/varnishd/http2/cache_http2_hpack.c
+++ b/bin/varnishd/http2/cache_http2_hpack.c
@@ -74,7 +74,7 @@ h2h_checkhdr(struct vsl_log *vsl, txt nm, txt val)
l = vmin_t(int, Tlen(nm) + 2 + Tlen(val), 20);
state = FLD_NAME_FIRST;
- for (p = nm.b; p < nm.e; p++) {
+ Tforeach(p, nm) {
switch(state) {
case FLD_NAME_FIRST:
state = FLD_NAME;
@@ -101,7 +101,7 @@ h2h_checkhdr(struct vsl_log *vsl, txt nm, txt val)
}
state = FLD_VALUE_FIRST;
- for (p = val.b; p < val.e; p++) {
+ Tforeach(p, val) {
switch(state) {
case FLD_VALUE_FIRST:
if (vct_issp(*p)) {
@@ -174,7 +174,7 @@ h2h_addhdr(struct http *hp, struct h2h_decode *d)
disallow_empty = 1;
/* Check HTTP token */
- for (p = hdr.b; p < hdr.e; p++) {
+ Tforeach(p, hdr) {
if (!vct_istchar(*p))
return (H2SE_PROTOCOL_ERROR);
}
@@ -192,7 +192,7 @@ h2h_addhdr(struct http *hp, struct h2h_decode *d)
}
/* Path cannot contain LWS or CTL */
- for (p = hdr.b; p < hdr.e; p++) {
+ Tforeach(p, hdr) {
if (vct_islws(*p) || vct_isctl(*p))
return (H2SE_PROTOCOL_ERROR);
}
@@ -206,7 +206,7 @@ h2h_addhdr(struct http *hp, struct h2h_decode *d)
disallow_empty = 1;
/* Check HTTP token */
- for (p = val.b; p < val.e; p++) {
+ Tforeach(p, val) {
if (!vct_istchar(*p))
return (H2SE_PROTOCOL_ERROR);
}
diff --git a/tools/coccinelle/tforeach.cocci b/tools/coccinelle/tforeach.cocci
new file mode 100644
index 000000000..ea6e25301
--- /dev/null
+++ b/tools/coccinelle/tforeach.cocci
@@ -0,0 +1,14 @@
+/* This patch turns manual loops over a txt into foreach loops */
+
+@@
+iterator name Tforeach;
+typedef txt;
+expression c;
+txt t;
+@@
+
+- for (c = t.b; c < t.e; c++)
++ Tforeach(c, t)
+{
+ ...
+}
More information about the varnish-commit
mailing list