[4.1] 082f259 Attempt to quell strange coverity report

Martin Blix Grydeland martin at varnish-software.com
Fri Sep 4 15:54:51 CEST 2015


commit 082f2596000a18f66fa2c3286c311fbc9135d049
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Jul 16 13:45:28 2015 +0200

    Attempt to quell strange coverity report
    
    Add extra variables of the right enum types in an attempt to quell a
    coverity report about enum type missmatch when reusing the same
    integer counter.

diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c
index bc108f4..3245e48 100644
--- a/lib/libvarnishapi/vsl_dispatch.c
+++ b/lib/libvarnishapi/vsl_dispatch.c
@@ -681,7 +681,9 @@ vtx_parse_link(const char *str, enum VSL_transaction_e *ptype,
 {
 	char type[16], reason[16];
 	unsigned vxid;
-	int i, j;
+	int i;
+	enum VSL_transaction_e et;
+	enum VSL_reason_e er;
 
 	AN(str);
 	AN(ptype);
@@ -691,26 +693,30 @@ vtx_parse_link(const char *str, enum VSL_transaction_e *ptype,
 	i = sscanf(str, "%15s %u %15s", type, &vxid, reason);
 	if (i < 1)
 		return (0);
-	for (j = 0; j < VSL_t__MAX; j++)
-		if (!strcmp(type, vsl_t_names[j]))
+
+	/* transaction type */
+	for (et = 0; et < VSL_t__MAX; et++)
+		if (!strcmp(type, vsl_t_names[et]))
 			break;
-	if (j < VSL_t__MAX)
-		*ptype = j;
-	else
-		*ptype = VSL_t_unknown;
+	if (et >= VSL_t__MAX)
+		et = VSL_t_unknown;
+	*ptype = et;
 	if (i == 1)
 		return (1);
+
+	/* vxid */
 	assert((vxid & ~VSL_IDENTMASK) == 0);
 	*pvxid = vxid;
 	if (i == 2)
 		return (2);
-	for (j = 0; j < VSL_r__MAX; j++)
-		if (!strcmp(reason, vsl_r_names[j]))
+
+	/* transaction reason */
+	for (er = 0; er < VSL_r__MAX; er++)
+		if (!strcmp(reason, vsl_r_names[er]))
 			break;
-	if (j < VSL_r__MAX)
-		*preason = j;
-	else
-		*preason = VSL_r_unknown;
+	if (er >= VSL_r__MAX)
+		er = VSL_r_unknown;
+	*preason = er;
 	return (3);
 }
 



More information about the varnish-commit mailing list