r4237 - in trunk/varnish-cache: bin/varnishd lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Tue Sep 15 09:44:47 CEST 2009


Author: phk
Date: 2009-09-15 09:44:47 +0200 (Tue, 15 Sep 2009)
New Revision: 4237

Modified:
   trunk/varnish-cache/bin/varnishd/varnishd.c
   trunk/varnish-cache/lib/libvcl/vcc_acl.c
Log:
Further Flexelint polishing



Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2009-09-14 08:47:03 UTC (rev 4236)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2009-09-15 07:44:47 UTC (rev 4237)
@@ -418,15 +418,12 @@
 	VTAILQ_FOREACH(s, &symbols, list) {
 		if (s->a > pp)
 			continue;
-		if (s0 != NULL && s->a < s0->a)
-			continue;
-		s0 = s;
+		if (s0 == NULL || s->a < s0->a)
+			s0 = s;
 	}
 	if (s0 == NULL)
 		return (-1);
-	vsb_printf(vsb, "%p", ptr);
-	if (s0 != NULL)
-		vsb_printf(vsb, ": %s+%jx", s0->n, (uintmax_t)pp - s0->a);
+	vsb_printf(vsb, "%p: %s+%jx", ptr, s0->n, (uintmax_t)pp - s0->a);
 	return (0);
 }
 
@@ -438,40 +435,43 @@
 	uintptr_t a;
 	struct symbols *s;
 
-	strcpy(buf, "nm -an ");
-	strcat(buf, a0);
+	p = NULL;
+	asprintf(&p, "nm -an %s", a0);
+	if (p == NULL)
+		return;
 	fi = popen(buf, "r");
-	if (fi != NULL) {
-		while (fgets(buf, sizeof buf, fi)) {
-			if (buf[0] == ' ')
-				continue;
-			p = NULL;
-			a = strtoul(buf, &p, 16);
-			if (p == NULL)
-				continue;
-			if (a == 0)
-				continue;
-			if (*p++ != ' ')
-				continue;
-			p++;
-			if (*p++ != ' ')
-				continue;
-			if (*p <= ' ')
-				continue;
-			e = strchr(p, '\0');
-			AN(e);
-			while (e > p && isspace(e[-1]))
-				e--;
-			*e = '\0';
-			s = malloc(sizeof *s + strlen(p) + 1);
-			AN(s);
-			s->a = a;
-			s->n = (void*)(s + 1);
-			strcpy(s->n, p);
-			VTAILQ_INSERT_TAIL(&symbols, s, list);
-		}
-		(void)pclose(fi);
+	free(p);
+	if (fi == NULL) 
+		return;
+	while (fgets(buf, sizeof buf, fi)) {
+		if (buf[0] == ' ')
+			continue;
+		p = NULL;
+		a = strtoul(buf, &p, 16);
+		if (p == NULL)
+			continue;
+		if (a == 0)
+			continue;
+		if (*p++ != ' ')
+			continue;
+		p++;
+		if (*p++ != ' ')
+			continue;
+		if (*p <= ' ')
+			continue;
+		e = strchr(p, '\0');
+		AN(e);
+		while (e > p && isspace(e[-1]))
+			e--;
+		*e = '\0';
+		s = malloc(sizeof *s + strlen(p) + 1);
+		AN(s);
+		s->a = a;
+		s->n = (void*)(s + 1);
+		strcpy(s->n, p);
+		VTAILQ_INSERT_TAIL(&symbols, s, list);
 	}
+	(void)pclose(fi);
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_acl.c	2009-09-14 08:47:03 UTC (rev 4236)
+++ trunk/varnish-cache/lib/libvcl/vcc_acl.c	2009-09-15 07:44:47 UTC (rev 4237)
@@ -250,14 +250,18 @@
 {
 	unsigned char b[4];
 	int i, j, k;
+	unsigned u;
 	const char *p;
 
 	memset(b, 0, sizeof b);
 	p = ae->t_addr->dec;
 	for (i = 0; i < 4; i++) {
-		j = sscanf(p, "%hhu%n", &b[i], &k);
+		j = sscanf(p, "%u%n", &u, &k);
 		if (j != 1)
 			return (0);
+		if (u & ~0xff)
+			return (0);
+		b[i] = (unsigned char)u;
 		if (p[k] == '\0')
 			break;
 		if (p[k] != '.')



More information about the varnish-commit mailing list